Skip to content

Commit 4afe8f3

Browse files
authored
chore: mark telemetry shim as no longer ongoing (#376)
1 parent 8486582 commit 4afe8f3

File tree

2 files changed

+48
-27
lines changed

2 files changed

+48
-27
lines changed

src/build/content/server.test.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import { expect, test, vi, describe, beforeEach } from 'vitest'
77
import { mockFileSystem } from '../../../tests/index.js'
88
import { PluginContext, RequiredServerFilesManifest } from '../plugin-context.js'
99

10-
import { copyNextServerCode, getPatchesToApply, verifyHandlerDirStructure } from './server.js'
10+
import {
11+
NextInternalModuleReplacement,
12+
copyNextServerCode,
13+
getPatchesToApply,
14+
verifyHandlerDirStructure,
15+
} from './server.js'
1116

1217
vi.mock('node:fs', async () => {
1318
// eslint-disable-next-line @typescript-eslint/no-explicit-any, unicorn/no-await-expression-member
@@ -279,16 +284,17 @@ describe(`getPatchesToApply`, () => {
279284
'14.1.4-canary.1': true, // canary version before stable with maxStableVersion - should be applied
280285
'14.1.4': true, // latest stable tested version
281286
'14.2.0': false, // untested stable version
287+
'14.2.0-canary.37': true, // maxVersion, should be applied
282288
'14.2.0-canary.38': false, // not ongoing patch so should not be applied
283289
}
284290

285291
const nextModule = 'test'
286292

287-
const patches = [
293+
const patches: NextInternalModuleReplacement[] = [
288294
{
289295
ongoing: false,
290296
minVersion: '13.5.0-canary.0',
291-
maxStableVersion: '14.1.4',
297+
maxVersion: '14.2.0-canary.37',
292298
nextModule,
293299
shimModule: 'not-used-in-test',
294300
},
@@ -318,7 +324,7 @@ describe(`getPatchesToApply`, () => {
318324

319325
const nextModule = 'test'
320326

321-
const patches = [
327+
const patches: NextInternalModuleReplacement[] = [
322328
{
323329
ongoing: true,
324330
minVersion: '13.5.0-canary.0',
@@ -353,7 +359,7 @@ describe(`getPatchesToApply`, () => {
353359

354360
const nextModule = 'test'
355361

356-
const patches = [
362+
const patches: NextInternalModuleReplacement[] = [
357363
{
358364
ongoing: true,
359365
minVersion: '13.5.0-canary.0',

src/build/content/server.ts

+37-22
Original file line numberDiff line numberDiff line change
@@ -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

186198
const 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

Comments
 (0)