Skip to content

Commit a6063c9

Browse files
authored
fix: next 16 adjustments (#3155)
1 parent 4aaeb79 commit a6063c9

File tree

32 files changed

+195
-92
lines changed

32 files changed

+195
-92
lines changed

src/build/content/server.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export const copyNextServerCode = async (ctx: PluginContext): Promise<void> => {
106106
`server/*`,
107107
`server/chunks/**/*`,
108108
`server/edge-chunks/**/*`,
109-
`server/edge/chunks/**/*`,
109+
`server/edge/**/*`,
110110
`server/+(app|pages)/**/*.js`,
111111
],
112112
{
@@ -291,6 +291,8 @@ async function patchNextModules(
291291
export const copyNextDependencies = async (ctx: PluginContext): Promise<void> => {
292292
await tracer.withActiveSpan('copyNextDependencies', async () => {
293293
const entries = await readdir(ctx.standaloneDir)
294+
const filter = ctx.constants.IS_LOCAL ? undefined : nodeModulesFilter
295+
294296
const promises: Promise<void>[] = entries.map(async (entry) => {
295297
// copy all except the distDir (.next) folder as this is handled in a separate function
296298
// this will include the node_modules folder as well
@@ -299,7 +301,6 @@ export const copyNextDependencies = async (ctx: PluginContext): Promise<void> =>
299301
}
300302
const src = join(ctx.standaloneDir, entry)
301303
const dest = join(ctx.serverHandlerDir, entry)
302-
const filter = ctx.constants.IS_LOCAL ? undefined : nodeModulesFilter
303304
await cp(src, dest, {
304305
recursive: true,
305306
verbatimSymlinks: true,
@@ -321,7 +322,7 @@ export const copyNextDependencies = async (ctx: PluginContext): Promise<void> =>
321322
// see: https://github.com/vercel/next.js/issues/50072
322323
if (existsSync(rootSrcDir) && ctx.standaloneRootDir !== ctx.standaloneDir) {
323324
promises.push(
324-
cp(rootSrcDir, rootDestDir, { recursive: true, verbatimSymlinks: true }).then(() =>
325+
cp(rootSrcDir, rootDestDir, { recursive: true, verbatimSymlinks: true, filter }).then(() =>
325326
recreateNodeModuleSymlinks(resolve('node_modules'), rootDestDir),
326327
),
327328
)

tests/e2e/cli-before-regional-blobs-support.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test('should serve 404 page when requesting non existing page (no matching route
1717
const headers = response?.headers() || {}
1818
expect(response?.status()).toBe(404)
1919

20-
expect(await page.textContent('h1')).toBe('404')
20+
await expect(page.locator('h1')).toHaveText('404')
2121

2222
// https://github.com/vercel/next.js/pull/69802 made changes to returned cache-control header,
2323
// after that (14.2.10 and canary.147) 404 pages would have `private` directive, before that it

tests/e2e/middleware.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@ for (const { expectedRuntime, isNodeMiddleware, label, testWithSwitchableMiddlew
246246
const pageResponse = await page.goto(`${edgeOrNodeMiddlewarePages.url}/link`)
247247
expect(await pageResponse?.headerValue('x-runtime')).toEqual(expectedRuntime)
248248

249+
// wait for hydration to finish before doing client navigation
250+
await expect(page.getByTestId('hydration')).toHaveText('hydrated', {
251+
timeout: 10_000,
252+
})
253+
249254
await page.evaluate(() => {
250255
// set some value to window to check later if browser did reload and lost this state
251256
;(window as ExtendedWindow).didReload = false
@@ -305,6 +310,11 @@ for (const { expectedRuntime, isNodeMiddleware, label, testWithSwitchableMiddlew
305310
)
306311
expect(await pageResponse?.headerValue('x-runtime')).toEqual(expectedRuntime)
307312

313+
// wait for hydration to finish before doing client navigation
314+
await expect(page.getByTestId('hydration')).toHaveText('hydrated', {
315+
timeout: 10_000,
316+
})
317+
308318
await page.evaluate(() => {
309319
// set some value to window to check later if browser did reload and lost this state
310320
;(window as ExtendedWindow).didReload = false

tests/e2e/on-demand-app.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ test.describe('app router on-demand revalidation', () => {
9696
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
9797
)
9898

99-
const date1 = await page.textContent('[data-testid="date-now"]')
99+
const date1 = await page.getByTestId('date-now').textContent()
100100

101-
const h1 = await page.textContent('h1')
101+
const h1 = await page.locator('h1').textContent()
102102
expect(h1).toBe(expectedH1Content)
103103

104104
const response2 = await pollUntilHeadersMatch(new URL(pagePath, serverComponents.url).href, {
@@ -127,7 +127,7 @@ test.describe('app router on-demand revalidation', () => {
127127
)
128128

129129
// the page is cached
130-
const date2 = await page.textContent('[data-testid="date-now"]')
130+
const date2 = await page.getByTestId('date-now').textContent()
131131
expect(date2).toBe(date1)
132132

133133
const revalidate = await page.goto(new URL(revalidateApiPath, serverComponents.url).href)
@@ -159,7 +159,7 @@ test.describe('app router on-demand revalidation', () => {
159159
)
160160

161161
// the page has now an updated date
162-
const date3 = await page.textContent('[data-testid="date-now"]')
162+
const date3 = await page.getByTestId('date-now').textContent()
163163
expect(date3).not.toBe(date2)
164164

165165
const response4 = await pollUntilHeadersMatch(new URL(pagePath, serverComponents.url).href, {
@@ -188,7 +188,7 @@ test.describe('app router on-demand revalidation', () => {
188188
)
189189

190190
// the page is cached
191-
const date4 = await page.textContent('[data-testid="date-now"]')
191+
const date4 = await page.getByTestId('date-now').textContent()
192192
expect(date4).toBe(date3)
193193
})
194194
}

tests/e2e/page-router.test.ts

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
174174
)
175175

176176
if (fallbackWasServed) {
177-
const loading = await page.textContent('[data-testid="loading"]')
177+
const loading = await page.getByTestId('loading').textContent()
178178
expect(loading, 'Fallback should be shown').toBe('Loading...')
179179
}
180180

181-
const date1 = await page.textContent('[data-testid="date-now"]')
182-
const h1 = await page.textContent('h1')
181+
const date1 = await page.getByTestId('date-now').textContent()
182+
const h1 = await page.locator('h1').textContent()
183183
expect(h1).toBe(expectedH1Content)
184184

185185
// check json route
@@ -238,7 +238,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
238238
)
239239

240240
// the page is cached
241-
const date2 = await page.textContent('[data-testid="date-now"]')
241+
const date2 = await page.getByTestId('date-now').textContent()
242242
expect(date2).toBe(date1)
243243

244244
// check json route
@@ -299,7 +299,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
299299
expect(headers3?.['x-nextjs-cache']).toBeUndefined()
300300

301301
// the page has now an updated date
302-
const date3 = await page.textContent('[data-testid="date-now"]')
302+
const date3 = await page.getByTestId('date-now').textContent()
303303
expect(date3).not.toBe(date2)
304304

305305
// check json route
@@ -366,7 +366,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
366366
},
367367
)
368368
expect(response1?.status()).toBe(200)
369-
const date1 = (await page.textContent('[data-testid="date-now"]')) ?? ''
369+
const date1 = (await page.getByTestId('date-now').textContent()) ?? ''
370370

371371
// ensure response was produced before invocation (served from cache)
372372
expect(date1.localeCompare(beforeFetch)).toBeLessThan(0)
@@ -391,7 +391,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
391391
},
392392
)
393393
expect(response2?.status()).toBe(200)
394-
const date2 = (await page.textContent('[data-testid="date-now"]')) ?? ''
394+
const date2 = (await page.getByTestId('date-now').textContent()) ?? ''
395395

396396
// ensure response was produced after initial invocation
397397
expect(beforeFetch.localeCompare(date2)).toBeLessThan(0)
@@ -416,7 +416,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
416416
)
417417

418418
// ensure response was NOT produced before invocation
419-
const date1 = (await page.textContent('[data-testid="date-now"]')) ?? ''
419+
const date1 = (await page.getByTestId('date-now').textContent()) ?? ''
420420
expect(date1.localeCompare(beforeFirstFetch)).toBeGreaterThan(0)
421421

422422
// allow page to get stale
@@ -431,7 +431,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
431431
/s-maxage=60, stale-while-revalidate=[0-9]+, durable/,
432432
)
433433

434-
const date2 = (await page.textContent('[data-testid="date-now"]')) ?? ''
434+
const date2 = (await page.getByTestId('date-now').textContent()) ?? ''
435435
expect(date2).toBe(date1)
436436

437437
// wait a bit to ensure background work has a chance to finish
@@ -450,7 +450,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
450450
/s-maxage=60, stale-while-revalidate=[0-9]+, durable/,
451451
)
452452

453-
const date3 = (await page.textContent('[data-testid="date-now"]')) ?? ''
453+
const date3 = (await page.getByTestId('date-now').textContent()) ?? ''
454454
expect(date3.localeCompare(date2)).toBeGreaterThan(0)
455455
})
456456

@@ -469,7 +469,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
469469
const headers = response?.headers() || {}
470470
expect(response?.status()).toBe(404)
471471

472-
expect(await page.textContent('p')).toBe('Custom 404 page')
472+
await expect(page.getByTestId('custom-404')).toHaveText('Custom 404 page')
473473

474474
// https://github.com/vercel/next.js/pull/69802 made changes to returned cache-control header,
475475
// after that (14.2.10 and canary.147) 404 pages would have `private` directive, before that
@@ -493,7 +493,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
493493
const headers = response?.headers() || {}
494494
expect(response?.status()).toBe(404)
495495

496-
expect(await page.textContent('p')).toBe('Custom 404 page')
496+
await expect(page.getByTestId('custom-404')).toHaveText('Custom 404 page')
497497

498498
expect(headers['debug-netlify-cdn-cache-control']).toBe(
499499
nextVersionSatisfies('>=15.0.0-canary.187')
@@ -748,12 +748,12 @@ test.describe('Page Router with basePath and i18n', () => {
748748
)
749749

750750
if (fallbackWasServedImplicitLocale) {
751-
const loading = await page.textContent('[data-testid="loading"]')
751+
const loading = await page.getByTestId('loading').textContent()
752752
expect(loading, 'Fallback should be shown').toBe('Loading...')
753753
}
754754

755-
const date1ImplicitLocale = await page.textContent('[data-testid="date-now"]')
756-
const h1ImplicitLocale = await page.textContent('h1')
755+
const date1ImplicitLocale = await page.getByTestId('date-now').textContent()
756+
const h1ImplicitLocale = await page.locator('h1').textContent()
757757
expect(h1ImplicitLocale).toBe(expectedH1Content)
758758

759759
const response1ExplicitLocale = await pollUntilHeadersMatch(
@@ -790,12 +790,12 @@ test.describe('Page Router with basePath and i18n', () => {
790790
)
791791

792792
if (fallbackWasServedExplicitLocale) {
793-
const loading = await page.textContent('[data-testid="loading"]')
793+
const loading = await page.getByTestId('loading').textContent()
794794
expect(loading, 'Fallback should be shown').toBe('Loading...')
795795
}
796796

797-
const date1ExplicitLocale = await page.textContent('[data-testid="date-now"]')
798-
const h1ExplicitLocale = await page.textContent('h1')
797+
const date1ExplicitLocale = await page.getByTestId('date-now').textContent()
798+
const h1ExplicitLocale = await page.locator('h1').textContent()
799799
expect(h1ExplicitLocale).toBe(expectedH1Content)
800800

801801
// implicit and explicit locale paths should be the same (same cached response)
@@ -861,7 +861,7 @@ test.describe('Page Router with basePath and i18n', () => {
861861
)
862862

863863
// the page is cached
864-
const date2ImplicitLocale = await page.textContent('[data-testid="date-now"]')
864+
const date2ImplicitLocale = await page.getByTestId('date-now').textContent()
865865
expect(date2ImplicitLocale).toBe(date1ImplicitLocale)
866866

867867
const response2ExplicitLocale = await pollUntilHeadersMatch(
@@ -893,7 +893,7 @@ test.describe('Page Router with basePath and i18n', () => {
893893
)
894894

895895
// the page is cached
896-
const date2ExplicitLocale = await page.textContent('[data-testid="date-now"]')
896+
const date2ExplicitLocale = await page.getByTestId('date-now').textContent()
897897
expect(date2ExplicitLocale).toBe(date1ExplicitLocale)
898898

899899
// check json route
@@ -961,7 +961,7 @@ test.describe('Page Router with basePath and i18n', () => {
961961
expect(headers3ImplicitLocale?.['x-nextjs-cache']).toBeUndefined()
962962

963963
// the page has now an updated date
964-
const date3ImplicitLocale = await page.textContent('[data-testid="date-now"]')
964+
const date3ImplicitLocale = await page.getByTestId('date-now').textContent()
965965
expect(date3ImplicitLocale).not.toBe(date2ImplicitLocale)
966966

967967
const response3ExplicitLocale = await pollUntilHeadersMatch(
@@ -984,7 +984,7 @@ test.describe('Page Router with basePath and i18n', () => {
984984
expect(headers3ExplicitLocale?.['x-nextjs-cache']).toBeUndefined()
985985

986986
// the page has now an updated date
987-
const date3ExplicitLocale = await page.textContent('[data-testid="date-now"]')
987+
const date3ExplicitLocale = await page.getByTestId('date-now').textContent()
988988
expect(date3ExplicitLocale).not.toBe(date2ExplicitLocale)
989989

990990
// implicit and explicit locale paths should be the same (same cached response)
@@ -1057,7 +1057,7 @@ test.describe('Page Router with basePath and i18n', () => {
10571057
expect(headers4ImplicitLocale?.['x-nextjs-cache']).toBeUndefined()
10581058

10591059
// the page has now an updated date
1060-
const date4ImplicitLocale = await page.textContent('[data-testid="date-now"]')
1060+
const date4ImplicitLocale = await page.getByTestId('date-now').textContent()
10611061
expect(date4ImplicitLocale).not.toBe(date3ImplicitLocale)
10621062

10631063
const response4ExplicitLocale = await pollUntilHeadersMatch(
@@ -1080,7 +1080,7 @@ test.describe('Page Router with basePath and i18n', () => {
10801080
expect(headers4ExplicitLocale?.['x-nextjs-cache']).toBeUndefined()
10811081

10821082
// the page has now an updated date
1083-
const date4ExplicitLocale = await page.textContent('[data-testid="date-now"]')
1083+
const date4ExplicitLocale = await page.getByTestId('date-now').textContent()
10841084
expect(date4ExplicitLocale).not.toBe(date3ExplicitLocale)
10851085

10861086
// implicit and explicit locale paths should be the same (same cached response)
@@ -1173,12 +1173,12 @@ test.describe('Page Router with basePath and i18n', () => {
11731173
)
11741174

11751175
if (fallbackWasServed) {
1176-
const loading = await page.textContent('[data-testid="loading"]')
1176+
const loading = await page.getByTestId('loading').textContent()
11771177
expect(loading, 'Fallback should be shown').toBe('Loading...')
11781178
}
11791179

1180-
const date1 = await page.textContent('[data-testid="date-now"]')
1181-
const h1 = await page.textContent('h1')
1180+
const date1 = await page.getByTestId('date-now').textContent()
1181+
const h1 = await page.locator('h1').textContent()
11821182
expect(h1).toBe(expectedH1Content)
11831183

11841184
// check json route
@@ -1241,7 +1241,7 @@ test.describe('Page Router with basePath and i18n', () => {
12411241
)
12421242

12431243
// the page is cached
1244-
const date2 = await page.textContent('[data-testid="date-now"]')
1244+
const date2 = await page.getByTestId('date-now').textContent()
12451245
expect(date2).toBe(date1)
12461246

12471247
// check json route
@@ -1309,7 +1309,7 @@ test.describe('Page Router with basePath and i18n', () => {
13091309
expect(headers3?.['x-nextjs-cache']).toBeUndefined()
13101310

13111311
// the page has now an updated date
1312-
const date3 = await page.textContent('[data-testid="date-now"]')
1312+
const date3 = await page.getByTestId('date-now').textContent()
13131313
expect(date3).not.toBe(date2)
13141314

13151315
// check json route
@@ -1360,7 +1360,7 @@ test.describe('Page Router with basePath and i18n', () => {
13601360
const headers = response?.headers() || {}
13611361
expect(response?.status()).toBe(404)
13621362

1363-
expect(await page.textContent('p')).toBe('Custom 404 page for locale: en')
1363+
await expect(page.getByTestId('custom-404')).toHaveText('Custom 404 page for locale: en')
13641364

13651365
expect(headers['debug-netlify-cdn-cache-control']).toMatch(
13661366
/no-cache, no-store, max-age=0, must-revalidate, durable/m,
@@ -1378,7 +1378,7 @@ test.describe('Page Router with basePath and i18n', () => {
13781378
const headers = response?.headers() || {}
13791379
expect(response?.status()).toBe(404)
13801380

1381-
expect(await page.textContent('p')).toBe('Custom 404 page for locale: en')
1381+
await expect(page.getByTestId('custom-404')).toHaveText('Custom 404 page for locale: en')
13821382

13831383
// Prior to v14.2.4 notFound pages are not cacheable
13841384
// https://github.com/vercel/next.js/pull/66674

tests/e2e/simple-app.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, type Locator, type Response } from '@playwright/test'
2-
import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs'
2+
import { hasDefaultTurbopackBuilds, nextVersionSatisfies } from '../utils/next-version-helpers.mjs'
33
import { test } from '../utils/playwright-helpers.js'
44

55
const expectImageWasLoaded = async (locator: Locator) => {
@@ -227,7 +227,7 @@ test('requesting a non existing page route that needs to be fetched from the blo
227227
const headers = response?.headers() || {}
228228
expect(response?.status()).toBe(404)
229229

230-
expect(await page.textContent('h1')).toBe('404 Not Found')
230+
await expect(page.locator('h1')).toHaveText('404 Not Found')
231231

232232
// https://github.com/vercel/next.js/pull/66674 made changes to returned cache-control header,
233233
// before that 404 page would have `private` directive, after that (14.2.4 and canary.24) it
@@ -254,7 +254,7 @@ test('requesting a non existing page route that needs to be fetched from the blo
254254
const headers = response?.headers() || {}
255255
expect(response?.status()).toBe(404)
256256

257-
expect(await page.textContent('h1')).toBe('404 Not Found')
257+
await expect(page.locator('h1')).toHaveText('404 Not Found')
258258

259259
expect(headers['debug-netlify-cdn-cache-control']).toBe(
260260
nextVersionSatisfies('>=15.0.0-canary.187')
@@ -273,6 +273,8 @@ test('Compressed rewrites are readable', async ({ simple }) => {
273273
})
274274

275275
test('can require CJS module that is not bundled', async ({ simple }) => {
276+
// setup for this test only works with webpack builds due to usage of ` __non_webpack_require__` to avoid bundling a file
277+
test.skip(hasDefaultTurbopackBuilds(), 'Setup for this test only works with webpack builds')
276278
const resp = await fetch(`${simple.url}/api/cjs-file-with-js-extension`)
277279

278280
expect(resp.status).toBe(200)

0 commit comments

Comments
 (0)