@@ -161,18 +161,11 @@ export type NextInternalModuleReplacement = {
161161 * Minimum Next.js version that this patch should be applied to
162162 */
163163 minVersion : string
164- /**
165- * Maximum Next.js version that this patch should be applied to, note that for ongoing patches
166- * we will continue to apply patch for prerelease versions also as canary versions are released
167- * very frequently and trying to target canary versions is not practical. If user is using
168- * canary next versions they should be aware of the risks
169- */
170- maxStableVersion : string
171164 /**
172165 * If the reason to patch was not addressed in Next.js we mark this as ongoing
173166 * to continue to test latest versions to know wether we should bump `maxStableVersion`
174167 */
175- ongoing ? : boolean
168+ ongoing : boolean
176169 /**
177170 * Module that should be replaced
178171 */
@@ -181,16 +174,36 @@ export type NextInternalModuleReplacement = {
181174 * Location of replacement module (relative to `<runtime>/dist/build/content`)
182175 */
183176 shimModule : string
184- }
177+ } & (
178+ | {
179+ ongoing : true
180+ /**
181+ * Maximum Next.js version that this patch should be applied to, note that for ongoing patches
182+ * we will continue to apply patch for prerelease versions also as canary versions are released
183+ * very frequently and trying to target canary versions is not practical. If user is using
184+ * canary next versions they should be aware of the risks
185+ */
186+ maxStableVersion : string
187+ }
188+ | {
189+ ongoing : false
190+ /**
191+ * Maximum Next.js version that this patch should be applied to. This should be last released
192+ * version of Next.js before version making the patch not needed anymore (can be canary version).
193+ */
194+ maxVersion : string
195+ }
196+ )
185197
186198const nextInternalModuleReplacements : NextInternalModuleReplacement [ ] = [
187199 {
188200 // standalone is loading expensive Telemetry module that is not actually used
189201 // so this replace that module with lightweight no-op shim that doesn't load additional modules
190- // see https://github.com/vercel/next.js/pull/63574 that will remove need for this shim
191- ongoing : true ,
202+ // see https://github.com/vercel/next.js/pull/63574 that removed need for this shim
203+ ongoing : false ,
192204 minVersion : '13.5.0-canary.0' ,
193- maxStableVersion : '14.1.4' ,
205+ // perf released in https://github.com/vercel/next.js/releases/tag/v14.2.0-canary.43
206+ maxVersion : '14.2.0-canary.42' ,
194207 nextModule : 'next/dist/telemetry/storage.js' ,
195208 shimModule : './next-shims/telemetry-storage.cjs' ,
196209 } ,
@@ -200,22 +213,24 @@ export function getPatchesToApply(
200213 nextVersion : string ,
201214 patches : NextInternalModuleReplacement [ ] = nextInternalModuleReplacements ,
202215) {
203- return patches . filter ( ( { minVersion , maxStableVersion , ongoing } ) => {
216+ return patches . filter ( ( patch ) => {
204217 // don't apply patches for next versions below minVersion
205- if ( semverLowerThan ( nextVersion , minVersion ) ) {
218+ if ( semverLowerThan ( nextVersion , patch . minVersion ) ) {
206219 return false
207220 }
208221
209- // apply ongoing patches when used next version is prerelease or NETLIFY_NEXT_FORCE_APPLY_ONGOING_PATCHES env var is used
210- if (
211- ongoing &&
212- ( prerelease ( nextVersion ) || process . env . NETLIFY_NEXT_FORCE_APPLY_ONGOING_PATCHES )
213- ) {
214- return true
222+ if ( patch . ongoing ) {
223+ // apply ongoing patches when used next version is prerelease or NETLIFY_NEXT_FORCE_APPLY_ONGOING_PATCHES env var is used
224+ if ( prerelease ( nextVersion ) || process . env . NETLIFY_NEXT_FORCE_APPLY_ONGOING_PATCHES ) {
225+ return true
226+ }
227+
228+ // apply ongoing patches for stable next versions below or equal maxStableVersion
229+ return semverLowerThanOrEqual ( nextVersion , patch . maxStableVersion )
215230 }
216231
217- // apply patches for next versions below maxStableVersion
218- return semverLowerThanOrEqual ( nextVersion , maxStableVersion )
232+ // apply patches for next versions below or equal maxVersion
233+ return semverLowerThanOrEqual ( nextVersion , patch . maxVersion )
219234 } )
220235}
221236
0 commit comments