@@ -161,18 +161,11 @@ export type NextInternalModuleReplacement = {
161
161
* Minimum Next.js version that this patch should be applied to
162
162
*/
163
163
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
171
164
/**
172
165
* If the reason to patch was not addressed in Next.js we mark this as ongoing
173
166
* to continue to test latest versions to know wether we should bump `maxStableVersion`
174
167
*/
175
- ongoing ? : boolean
168
+ ongoing : boolean
176
169
/**
177
170
* Module that should be replaced
178
171
*/
@@ -181,16 +174,36 @@ export type NextInternalModuleReplacement = {
181
174
* Location of replacement module (relative to `<runtime>/dist/build/content`)
182
175
*/
183
176
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
+ )
185
197
186
198
const nextInternalModuleReplacements : NextInternalModuleReplacement [ ] = [
187
199
{
188
200
// standalone is loading expensive Telemetry module that is not actually used
189
201
// 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 ,
192
204
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' ,
194
207
nextModule : 'next/dist/telemetry/storage.js' ,
195
208
shimModule : './next-shims/telemetry-storage.cjs' ,
196
209
} ,
@@ -200,22 +213,24 @@ export function getPatchesToApply(
200
213
nextVersion : string ,
201
214
patches : NextInternalModuleReplacement [ ] = nextInternalModuleReplacements ,
202
215
) {
203
- return patches . filter ( ( { minVersion , maxStableVersion , ongoing } ) => {
216
+ return patches . filter ( ( patch ) => {
204
217
// don't apply patches for next versions below minVersion
205
- if ( semverLowerThan ( nextVersion , minVersion ) ) {
218
+ if ( semverLowerThan ( nextVersion , patch . minVersion ) ) {
206
219
return false
207
220
}
208
221
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 )
215
230
}
216
231
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 )
219
234
} )
220
235
}
221
236
0 commit comments