Unverified Commit b91297d9 authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub

Use snapshots to verify dynamic validation errors in dev mode (#80992)

Follow-up to #80946, asserting on the collapsed redbox errors in dev mode.

> [!NOTE]  
> This PR is best reviewed with hidden whitespace changes.
parent 186913a2
import { nextTestSetup } from 'e2e-utils'
import { assertNoErrorToast } from 'next-test-utils'
import { getPrerenderOutput } from './utils'
describe.each([
{ inDebugMode: true, name: 'With --prerender-debug' },
{ inDebugMode: false, name: 'Without --prerender-debug' },
])('Dynamic IO Errors - $name', ({ inDebugMode }) => {
{ inPrerenderDebugMode: true, name: 'With --prerender-debug' },
// { inPrerenderDebugMode: false, name: 'Without --prerender-debug' },
])('Dynamic IO Errors - $name', ({ inPrerenderDebugMode }) => {
// We want to skip building and starting in start mode, and in dev mode when
// prerender debug mode is enabled, which doesn't exist for `next dev`.
const skipStart =
process.env.NEXT_TEST_MODE === 'start' || inPrerenderDebugMode
describe('Sync Dynamic - With Fallback - Math.random()', () => {
const { next, isNextDev, skipped } = nextTestSetup({
files: __dirname + '/fixtures/sync-random-with-fallback',
skipStart: true,
skipStart,
skipDeployment: true,
buildOptions: inDebugMode ? ['--debug-prerender'] : undefined,
buildOptions: inPrerenderDebugMode ? ['--debug-prerender'] : undefined,
})
if (skipped) {
......@@ -18,29 +24,36 @@ describe.each([
}
if (isNextDev) {
it('does not run in dev', () => {})
return
}
it('should not error the build when calling Math.random() if all dynamic access is inside a Suspense boundary', async () => {
try {
await next.start()
} catch {
throw new Error('expected build not to fail for fully static project')
if (inPrerenderDebugMode) {
it('prerender debug mode does not exist for `next dev`', () => {})
return
}
expect(next.cliOutput).toContain('◐ / ')
const $ = await next.render$('/')
expect($('[data-fallback]').length).toBe(2)
})
it('should not show a collapsed redbox error', async () => {
const browser = await next.browser('/')
await assertNoErrorToast(browser)
})
} else {
it('should not error the build when calling Math.random() if all dynamic access is inside a Suspense boundary', async () => {
try {
await next.start()
} catch {
throw new Error('expected build not to fail for fully static project')
}
expect(next.cliOutput).toContain('◐ / ')
const $ = await next.render$('/')
expect($('[data-fallback]').length).toBe(2)
})
}
})
describe('Sync Dynamic - Without Fallback - Math.random()', () => {
const { next, isNextDev, isTurbopack, skipped } = nextTestSetup({
files: __dirname + '/fixtures/sync-random-without-fallback',
skipStart: true,
skipStart,
skipDeployment: true,
buildOptions: inDebugMode ? ['--debug-prerender'] : undefined,
buildOptions: inPrerenderDebugMode ? ['--debug-prerender'] : undefined,
})
if (skipped) {
......@@ -48,72 +61,94 @@ describe.each([
}
if (isNextDev) {
it('does not run in dev', () => {})
return
}
it('should error the build if Math.random() happens before some component outside a Suspense boundary is complete', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
if (inPrerenderDebugMode) {
it('prerender debug mode does not exist for `next dev`', () => {})
return
}
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inDebugMode,
it('should show a collapsed redbox error', async () => {
const browser = await next.browser('/')
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Route "/" used \`Math.random()\` outside of \`"use cache"\` and without explicitly calling \`await connection()\` beforehand. See more info here: https://nextjs.org/docs/messages/next-prerender-random",
"environmentLabel": "Server",
"label": "Console Error",
"source": "app/page.tsx (35:23) @ RandomReadingComponent
> 35 | const random = Math.random()
| ^",
"stack": [
"RandomReadingComponent app/page.tsx (35:23)",
"JSON.parse <anonymous> (0:0)",
"LogSafely <anonymous> (0:0)",
],
}
`)
})
} else {
it('should error the build if Math.random() happens before some component outside a Suspense boundary is complete', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
}
if (isTurbopack) {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`Math.random()\` outside of \`"use cache"\` and without explicitly calling \`await connection()\` beforehand. See more info here: https://nextjs.org/docs/messages/next-prerender-random
at RandomReadingComponent (turbopack:///[project]/app/page.tsx:35:22)
33 | use(new Promise((r) => process.nextTick(r)))
34 | }
> 35 | const random = Math.random()
| ^
36 | return (
37 | <div>
38 | <span id="rand">{random}</span>
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inPrerenderDebugMode,
})
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`Math.random()\` outside of \`"use cache"\` and without explicitly calling \`await connection()\` beforehand. See more info here: https://nextjs.org/docs/messages/next-prerender-random
at a (<next-dist-dir>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
} else {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`Math.random()\` outside of \`"use cache"\` and without explicitly calling \`await connection()\` beforehand. See more info here: https://nextjs.org/docs/messages/next-prerender-random
at RandomReadingComponent (webpack:///app/page.tsx:35:22)
33 | use(new Promise((r) => process.nextTick(r)))
34 | }
> 35 | const random = Math.random()
| ^
36 | return (
37 | <div>
38 | <span id="rand">{random}</span>
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
if (isTurbopack) {
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`Math.random()\` outside of \`"use cache"\` and without explicitly calling \`await connection()\` beforehand. See more info here: https://nextjs.org/docs/messages/next-prerender-random
at RandomReadingComponent (turbopack:///[project]/app/page.tsx:35:22)
33 | use(new Promise((r) => process.nextTick(r)))
34 | }
> 35 | const random = Math.random()
| ^
36 | return (
37 | <div>
38 | <span id="rand">{random}</span>
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`Math.random()\` outside of \`"use cache"\` and without explicitly calling \`await connection()\` beforehand. See more info here: https://nextjs.org/docs/messages/next-prerender-random
at a (<next-dist-dir>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`Math.random()\` outside of \`"use cache"\` and without explicitly calling \`await connection()\` beforehand. See more info here: https://nextjs.org/docs/messages/next-prerender-random
at a (<next-dist-dir>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`Math.random()\` outside of \`"use cache"\` and without explicitly calling \`await connection()\` beforehand. See more info here: https://nextjs.org/docs/messages/next-prerender-random
at RandomReadingComponent (webpack:///app/page.tsx:35:22)
33 | use(new Promise((r) => process.nextTick(r)))
34 | }
> 35 | const random = Math.random()
| ^
36 | return (
37 | <div>
38 | <span id="rand">{random}</span>
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`Math.random()\` outside of \`"use cache"\` and without explicitly calling \`await connection()\` beforehand. See more info here: https://nextjs.org/docs/messages/next-prerender-random
at a (<next-dist-dir>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
}
}
})
})
}
})
})
......@@ -3,17 +3,22 @@ import { assertNoErrorToast } from 'next-test-utils'
import { getPrerenderOutput } from './utils'
describe.each([
{ inDebugMode: true, name: 'With --prerender-debug' },
{ inDebugMode: false, name: 'Without --prerender-debug' },
])('Dynamic IO Errors - $name', ({ inDebugMode }) => {
{ inPrerenderDebugMode: true, name: 'With --prerender-debug' },
{ inPrerenderDebugMode: false, name: 'Without --prerender-debug' },
])('Dynamic IO Errors - $name', ({ inPrerenderDebugMode }) => {
// We want to skip building and starting in start mode, and in dev mode when
// prerender debug mode is enabled, which doesn't exist for `next dev`.
const skipStart =
process.env.NEXT_TEST_MODE === 'start' || inPrerenderDebugMode
describe('Error Attribution with Sync IO - Guarded RSC with guarded Client sync IO', () => {
const { next, isNextDev, skipped } = nextTestSetup({
files:
__dirname +
'/fixtures/sync-attribution/guarded-async-guarded-clientsync',
skipStart: true,
skipStart,
skipDeployment: true,
buildOptions: inDebugMode ? ['--debug-prerender'] : undefined,
buildOptions: inPrerenderDebugMode ? ['--debug-prerender'] : undefined,
})
if (skipped) {
......@@ -21,8 +26,12 @@ describe.each([
}
if (isNextDev) {
if (inPrerenderDebugMode) {
it('prerender debug mode does not exist for `next dev`', () => {})
return
}
it('does not show a validation error in the dev overlay', async () => {
await next.start()
const browser = await next.browser('/')
await assertNoErrorToast(browser)
})
......@@ -43,9 +52,9 @@ describe.each([
files:
__dirname +
'/fixtures/sync-attribution/guarded-async-unguarded-clientsync',
skipStart: true,
skipStart,
skipDeployment: true,
buildOptions: inDebugMode ? ['--debug-prerender'] : undefined,
buildOptions: inPrerenderDebugMode ? ['--debug-prerender'] : undefined,
})
if (skipped) {
......@@ -53,73 +62,96 @@ describe.each([
}
if (isNextDev) {
it('does not run in dev', () => {})
return
}
it('should error the build with a reason related to sync IO access', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
if (inPrerenderDebugMode) {
it('prerender debug mode does not exist for `next dev`', () => {})
return
}
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inDebugMode,
})
it('should show a collapsed redbox error', async () => {
const browser = await next.browser('/')
if (isTurbopack) {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client
at SyncIO (turbopack:///[project]/app/client.tsx:5:15)
3 | export function SyncIO() {
4 | // This is a sync IO access that should not cause an error
> 5 | const data = new Date().toISOString()
| ^
6 |
7 | return (
8 | <main>
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client
at a (<next-dist-dir>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Route "/" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client",
"environmentLabel": "Server",
"label": "Console Error",
"source": "app/client.tsx (5:16) @ SyncIO
> 5 | const data = new Date().toISOString()
| ^",
"stack": [
"SyncIO app/client.tsx (5:16)",
"JSON.parse <anonymous> (0:0)",
"JSON.parse <anonymous> (0:0)",
"LogSafely <anonymous> (0:0)",
],
}
`)
})
} else {
it('should error the build with a reason related to sync IO access', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
}
} else {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client
at SyncIO (webpack:///app/client.tsx:5:15)
3 | export function SyncIO() {
4 | // This is a sync IO access that should not cause an error
> 5 | const data = new Date().toISOString()
| ^
6 |
7 | return (
8 | <main>
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inPrerenderDebugMode,
})
if (isTurbopack) {
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client
at SyncIO (turbopack:///[project]/app/client.tsx:5:15)
3 | export function SyncIO() {
4 | // This is a sync IO access that should not cause an error
> 5 | const data = new Date().toISOString()
| ^
6 |
7 | return (
8 | <main>
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client
at a (<next-dist-dir>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client
at a (<next-dist-dir>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client
at SyncIO (webpack:///app/client.tsx:5:15)
3 | export function SyncIO() {
4 | // This is a sync IO access that should not cause an error
> 5 | const data = new Date().toISOString()
| ^
6 |
7 | return (
8 | <main>
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client
at a (<next-dist-dir>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
}
}
})
})
}
})
describe('Error Attribution with Sync IO - Unguarded RSC with guarded Client sync IO', () => {
......@@ -127,9 +159,9 @@ describe.each([
files:
__dirname +
'/fixtures/sync-attribution/unguarded-async-guarded-clientsync',
skipStart: true,
skipStart,
skipDeployment: true,
buildOptions: inDebugMode ? ['--debug-prerender'] : undefined,
buildOptions: inPrerenderDebugMode ? ['--debug-prerender'] : undefined,
})
if (skipped) {
......@@ -137,116 +169,170 @@ describe.each([
}
if (isNextDev) {
it('does not run in dev', () => {})
return
}
it('should error the build with a reason related dynamic data', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
if (inPrerenderDebugMode) {
it('prerender debug mode does not exist for `next dev`', () => {})
return
}
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inDebugMode,
})
it('should show a collapsed redbox error', async () => {
const browser = await next.browser('/')
if (isTurbopack) {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at section (<anonymous>)
at main (<anonymous>)
at RenderFromTemplateContext (<anonymous>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
if (isTurbopack) {
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense",
"environmentLabel": "Server",
"label": "Console Error",
"source": null,
"stack": [
"RequestData [Server] <anonymous> (1:29)",
"section <anonymous> (1:16)",
"main <anonymous> (1:13)",
"<FIXME-file-protocol>",
"main <anonymous> (1:13)",
"body <anonymous> (1:13)",
"html <anonymous> (1:13)",
"Root [Server] <anonymous> (1:22)",
"JSON.parse <anonymous> (0:0)",
"JSON.parse <anonymous> (0:0)",
"LogSafely <anonymous> (0:0)",
],
}
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at a (<anonymous>)
at main (<anonymous>)
at b (<next-dist-dir>)
at c (<next-dist-dir>)
at d (<next-dist-dir>)
at e (<next-dist-dir>)
at f (<next-dist-dir>)
at g (<next-dist-dir>)
at h (<next-dist-dir>)
at i (<next-dist-dir>)
at j (<next-dist-dir>)
at k (<anonymous>)
at l (<next-dist-dir>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense",
"environmentLabel": "Server",
"label": "Console Error",
"source": "app/page.tsx (27:9) @ Page
> 27 | <RequestData />
| ^",
"stack": [
"RequestData [Server] <anonymous> (1:29)",
"section <anonymous> (1:16)",
"main <anonymous> (1:13)",
"Page app/page.tsx (27:9)",
"main <anonymous> (1:13)",
"body <anonymous> (1:13)",
"html <anonymous> (1:13)",
"Root [Server] <anonymous> (1:22)",
"JSON.parse <anonymous> (0:0)",
"JSON.parse <anonymous> (0:0)",
"LogSafely <anonymous> (0:0)",
],
}
`)
}
} else {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at section (<anonymous>)
at main (<anonymous>)
at InnerLayoutRouter (webpack://<next-src>)
at RedirectErrorBoundary (webpack://<next-src>)
at RedirectBoundary (webpack://<next-src>)
at HTTPAccessFallbackErrorBoundary (webpack://<next-src>)
at HTTPAccessFallbackBoundary (webpack://<next-src>)
at LoadingBoundary (webpack://<next-src>)
at ErrorBoundary (webpack://<next-src>)
at InnerScrollAndFocusHandler (webpack://<next-src>)
at ScrollAndFocusHandler (webpack://<next-src>)
at RenderFromTemplateContext (<anonymous>)
at OuterLayoutRouter (webpack://<next-src>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
332 | */
333 | function InnerLayoutRouter({
> 334 | tree,
| ^
335 | segmentPath,
336 | cacheNode,
337 | url,
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
})
} else {
it('should error the build with a reason related dynamic data', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
}
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inPrerenderDebugMode,
})
if (isTurbopack) {
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at section (<anonymous>)
at main (<anonymous>)
at RenderFromTemplateContext (<anonymous>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at a (<anonymous>)
at main (<anonymous>)
at b (<next-dist-dir>)
at c (<next-dist-dir>)
at d (<next-dist-dir>)
at e (<next-dist-dir>)
at f (<next-dist-dir>)
at g (<next-dist-dir>)
at h (<next-dist-dir>)
at i (<next-dist-dir>)
at j (<next-dist-dir>)
at k (<anonymous>)
at l (<next-dist-dir>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at a (<anonymous>)
at main (<anonymous>)
at b (<next-dist-dir>)
at c (<next-dist-dir>)
at d (<next-dist-dir>)
at e (<next-dist-dir>)
at f (<next-dist-dir>)
at g (<next-dist-dir>)
at h (<next-dist-dir>)
at i (<next-dist-dir>)
at j (<next-dist-dir>)
at k (<anonymous>)
at l (<next-dist-dir>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at section (<anonymous>)
at main (<anonymous>)
at InnerLayoutRouter (webpack://<next-src>)
at RedirectErrorBoundary (webpack://<next-src>)
at RedirectBoundary (webpack://<next-src>)
at HTTPAccessFallbackErrorBoundary (webpack://<next-src>)
at HTTPAccessFallbackBoundary (webpack://<next-src>)
at LoadingBoundary (webpack://<next-src>)
at ErrorBoundary (webpack://<next-src>)
at InnerScrollAndFocusHandler (webpack://<next-src>)
at ScrollAndFocusHandler (webpack://<next-src>)
at RenderFromTemplateContext (<anonymous>)
at OuterLayoutRouter (webpack://<next-src>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
332 | */
333 | function InnerLayoutRouter({
> 334 | tree,
| ^
335 | segmentPath,
336 | cacheNode,
337 | url,
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at a (<anonymous>)
at main (<anonymous>)
at b (<next-dist-dir>)
at c (<next-dist-dir>)
at d (<next-dist-dir>)
at e (<next-dist-dir>)
at f (<next-dist-dir>)
at g (<next-dist-dir>)
at h (<next-dist-dir>)
at i (<next-dist-dir>)
at j (<next-dist-dir>)
at k (<anonymous>)
at l (<next-dist-dir>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
}
}
})
})
}
})
describe('Error Attribution with Sync IO - unguarded RSC with unguarded Client sync IO', () => {
......@@ -254,9 +340,9 @@ describe.each([
files:
__dirname +
'/fixtures/sync-attribution/unguarded-async-unguarded-clientsync',
skipStart: true,
skipStart,
skipDeployment: true,
buildOptions: inDebugMode ? ['--debug-prerender'] : undefined,
buildOptions: inPrerenderDebugMode ? ['--debug-prerender'] : undefined,
})
if (skipped) {
......@@ -264,72 +350,95 @@ describe.each([
}
if (isNextDev) {
it('does not run in dev', () => {})
return
}
it('should error the build with a reason related to sync IO access', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
if (inPrerenderDebugMode) {
it('prerender debug mode does not exist for `next dev`', () => {})
return
}
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inDebugMode,
})
it('should show a collapsed redbox error', async () => {
const browser = await next.browser('/')
if (isTurbopack) {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client
at SyncIO (turbopack:///[project]/app/client.tsx:5:15)
3 | export function SyncIO() {
4 | // This is a sync IO access that should not cause an error
> 5 | const data = new Date().toISOString()
| ^
6 |
7 | return (
8 | <main>
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client
at a (<next-dist-dir>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Route "/" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client",
"environmentLabel": "Server",
"label": "Console Error",
"source": "app/client.tsx (5:16) @ SyncIO
> 5 | const data = new Date().toISOString()
| ^",
"stack": [
"SyncIO app/client.tsx (5:16)",
"JSON.parse <anonymous> (0:0)",
"JSON.parse <anonymous> (0:0)",
"LogSafely <anonymous> (0:0)",
],
}
`)
})
} else {
it('should error the build with a reason related to sync IO access', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
}
} else {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client
at SyncIO (webpack:///app/client.tsx:5:15)
3 | export function SyncIO() {
4 | // This is a sync IO access that should not cause an error
> 5 | const data = new Date().toISOString()
| ^
6 |
7 | return (
8 | <main>
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inPrerenderDebugMode,
})
if (isTurbopack) {
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client
at SyncIO (turbopack:///[project]/app/client.tsx:5:15)
3 | export function SyncIO() {
4 | // This is a sync IO access that should not cause an error
> 5 | const data = new Date().toISOString()
| ^
6 |
7 | return (
8 | <main>
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client
at a (<next-dist-dir>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client
at a (<next-dist-dir>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client
at SyncIO (webpack:///app/client.tsx:5:15)
3 | export function SyncIO() {
4 | // This is a sync IO access that should not cause an error
> 5 | const data = new Date().toISOString()
| ^
6 |
7 | return (
8 | <main>
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`new Date()\` inside a Client Component without a Suspense boundary above it. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time-client
at a (<next-dist-dir>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
}
}
})
})
}
})
})
......@@ -2,15 +2,20 @@ import { nextTestSetup } from 'e2e-utils'
import { getPrerenderOutput } from './utils'
describe.each([
{ inDebugMode: true, name: 'With --prerender-debug' },
{ inDebugMode: false, name: 'Without --prerender-debug' },
])('Dynamic IO Errors - $name', ({ inDebugMode }) => {
{ inPrerenderDebugMode: true, name: 'With --prerender-debug' },
{ inPrerenderDebugMode: false, name: 'Without --prerender-debug' },
])('Dynamic IO Errors - $name', ({ inPrerenderDebugMode }) => {
// We want to skip building and starting in start mode, and in dev mode when
// prerender debug mode is enabled, which doesn't exist for `next dev`.
const skipStart =
process.env.NEXT_TEST_MODE === 'start' || inPrerenderDebugMode
describe('Sync Dynamic - With Fallback - client searchParams', () => {
const { next, isNextDev, skipped } = nextTestSetup({
files: __dirname + '/fixtures/sync-client-search-with-fallback',
skipStart: true,
skipStart,
skipDeployment: true,
buildOptions: inDebugMode ? ['--debug-prerender'] : undefined,
buildOptions: inPrerenderDebugMode ? ['--debug-prerender'] : undefined,
})
if (skipped) {
......@@ -18,29 +23,52 @@ describe.each([
}
if (isNextDev) {
it('does not run in dev', () => {})
return
}
it('should not error the build when synchronously reading search params in a client component if all dynamic access is inside a Suspense boundary', async () => {
try {
await next.start()
} catch {
throw new Error('expected build not to fail for fully static project')
if (inPrerenderDebugMode) {
it('prerender debug mode does not exist for `next dev`', () => {})
return
}
expect(next.cliOutput).toContain('◐ / ')
const $ = await next.render$('/')
expect($('[data-fallback]').length).toBe(2)
})
// We don't error the build, but we do show a dev-only error so that users
// migrate to the async usage.
it('should show a collapsed redbox error', async () => {
const browser = await next.browser('/')
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "A searchParam property was accessed directly with \`searchParams.foo\`. \`searchParams\` should be unwrapped with \`React.use()\` before accessing its properties. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis",
"environmentLabel": null,
"label": "Console Error",
"source": "app/page.tsx (44:5) @ SearchParamsReadingComponent
> 44 | ).foo
| ^",
"stack": [
"SearchParamsReadingComponent app/page.tsx (44:5)",
"Page app/page.tsx (19:11)",
],
}
`)
})
} else {
it('should not error the build when synchronously reading search params in a client component if all dynamic access is inside a Suspense boundary', async () => {
try {
await next.start()
} catch {
throw new Error('expected build not to fail for fully static project')
}
expect(next.cliOutput).toContain('◐ / ')
const $ = await next.render$('/')
expect($('[data-fallback]').length).toBe(2)
})
}
})
describe('Sync Dynamic - Without Fallback - client searchParams', () => {
const { next, isNextDev, isTurbopack, skipped } = nextTestSetup({
files: __dirname + '/fixtures/sync-client-search-without-fallback',
skipStart: true,
skipStart,
skipDeployment: true,
buildOptions: inDebugMode ? ['--debug-prerender'] : undefined,
buildOptions: inPrerenderDebugMode ? ['--debug-prerender'] : undefined,
})
if (skipped) {
......@@ -48,138 +76,181 @@ describe.each([
}
if (isNextDev) {
it('does not run in dev', () => {})
return
}
it('should error the build if dynamic IO happens in the root (outside a Suspense)', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
if (inPrerenderDebugMode) {
it('prerender debug mode does not exist for `next dev`', () => {})
return
}
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inDebugMode,
it('should show a collapsed redbox with two errors', async () => {
const browser = await next.browser('/')
await expect(browser).toDisplayCollapsedRedbox(`
[
{
"description": "Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense",
"environmentLabel": "Server",
"label": "Console Error",
"source": "app/page.tsx (52:8) @ LongRunningComponent
> 52 | use(
| ^",
"stack": [
"LongRunningComponent app/page.tsx (52:8)",
"IndirectionTwo app/indirection.tsx (7:34)",
"Page app/page.tsx (19:61)",
"main <anonymous> (1:13)",
"body <anonymous> (1:13)",
"html <anonymous> (1:13)",
"Root [Server] <anonymous> (1:22)",
"JSON.parse <anonymous> (0:0)",
"JSON.parse <anonymous> (0:0)",
"LogSafely <anonymous> (0:0)",
],
},
{
"description": "A searchParam property was accessed directly with \`searchParams.foo\`. \`searchParams\` should be unwrapped with \`React.use()\` before accessing its properties. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis",
"environmentLabel": null,
"label": "Console Error",
"source": "app/page.tsx (42:5) @ SearchParamsReadingComponent
> 42 | ).foo
| ^",
"stack": [
"SearchParamsReadingComponent app/page.tsx (42:5)",
"Page app/page.tsx (19:11)",
],
},
]
`)
})
if (isTurbopack) {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at LongRunningComponent (<anonymous>)
at IndirectionTwo (turbopack:///[project]/app/indirection.tsx:7:33)
at Page (turbopack:///[project]/app/page.tsx:19:60)
at RenderFromTemplateContext (<anonymous>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
5 | }
6 |
> 7 | export function IndirectionTwo({ children }) {
| ^
8 | return children
9 | }
10 |
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at a (<anonymous>)
at b (<next-dist-dir>)
at c (<next-dist-dir>)
at d (<next-dist-dir>)
at e (<next-dist-dir>)
at f (<next-dist-dir>)
at g (<next-dist-dir>)
at h (<next-dist-dir>)
at i (<next-dist-dir>)
at j (<next-dist-dir>)
at k (<next-dist-dir>)
at l (<next-dist-dir>)
at m (<next-dist-dir>)
at n (<anonymous>)
at o (<next-dist-dir>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
} else {
it('should error the build if dynamic IO happens in the root (outside a Suspense)', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
}
} else {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at LongRunningComponent (<anonymous>)
at IndirectionTwo (webpack:///app/indirection.tsx:7:33)
at Page (webpack:///app/page.tsx:19:60)
at ClientPageRoot (webpack://<next-src>)
at InnerLayoutRouter (webpack://<next-src>)
at RedirectErrorBoundary (webpack://<next-src>)
at RedirectBoundary (webpack://<next-src>)
at HTTPAccessFallbackErrorBoundary (webpack://<next-src>)
at HTTPAccessFallbackBoundary (webpack://<next-src>)
at LoadingBoundary (webpack://<next-src>)
at ErrorBoundary (webpack://<next-src>)
at InnerScrollAndFocusHandler (webpack://<next-src>)
at ScrollAndFocusHandler (webpack://<next-src>)
at RenderFromTemplateContext (<anonymous>)
at OuterLayoutRouter (webpack://<next-src>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
5 | }
6 |
> 7 | export function IndirectionTwo({ children }) {
| ^
8 | return children
9 | }
10 |
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inPrerenderDebugMode,
})
if (isTurbopack) {
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at LongRunningComponent (<anonymous>)
at IndirectionTwo (turbopack:///[project]/app/indirection.tsx:7:33)
at Page (turbopack:///[project]/app/page.tsx:19:60)
at RenderFromTemplateContext (<anonymous>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
5 | }
6 |
> 7 | export function IndirectionTwo({ children }) {
| ^
8 | return children
9 | }
10 |
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at a (<anonymous>)
at b (<next-dist-dir>)
at c (<next-dist-dir>)
at d (<next-dist-dir>)
at e (<next-dist-dir>)
at f (<next-dist-dir>)
at g (<next-dist-dir>)
at h (<next-dist-dir>)
at i (<next-dist-dir>)
at j (<next-dist-dir>)
at k (<next-dist-dir>)
at l (<next-dist-dir>)
at m (<next-dist-dir>)
at n (<anonymous>)
at o (<next-dist-dir>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at a (<anonymous>)
at b (<next-dist-dir>)
at c (<next-dist-dir>)
at d (<next-dist-dir>)
at e (<next-dist-dir>)
at f (<next-dist-dir>)
at g (<next-dist-dir>)
at h (<next-dist-dir>)
at i (<next-dist-dir>)
at j (<next-dist-dir>)
at k (<next-dist-dir>)
at l (<next-dist-dir>)
at m (<next-dist-dir>)
at n (<anonymous>)
at o (<next-dist-dir>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at LongRunningComponent (<anonymous>)
at IndirectionTwo (webpack:///app/indirection.tsx:7:33)
at Page (webpack:///app/page.tsx:19:60)
at ClientPageRoot (webpack://<next-src>)
at InnerLayoutRouter (webpack://<next-src>)
at RedirectErrorBoundary (webpack://<next-src>)
at RedirectBoundary (webpack://<next-src>)
at HTTPAccessFallbackErrorBoundary (webpack://<next-src>)
at HTTPAccessFallbackBoundary (webpack://<next-src>)
at LoadingBoundary (webpack://<next-src>)
at ErrorBoundary (webpack://<next-src>)
at InnerScrollAndFocusHandler (webpack://<next-src>)
at ScrollAndFocusHandler (webpack://<next-src>)
at RenderFromTemplateContext (<anonymous>)
at OuterLayoutRouter (webpack://<next-src>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
5 | }
6 |
> 7 | export function IndirectionTwo({ children }) {
| ^
8 | return children
9 | }
10 |
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at a (<anonymous>)
at b (<next-dist-dir>)
at c (<next-dist-dir>)
at d (<next-dist-dir>)
at e (<next-dist-dir>)
at f (<next-dist-dir>)
at g (<next-dist-dir>)
at h (<next-dist-dir>)
at i (<next-dist-dir>)
at j (<next-dist-dir>)
at k (<next-dist-dir>)
at l (<next-dist-dir>)
at m (<next-dist-dir>)
at n (<anonymous>)
at o (<next-dist-dir>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
}
}
})
})
}
})
describe('Sync Dynamic - With Fallback - server searchParams', () => {
const { next, isNextDev, skipped } = nextTestSetup({
files: __dirname + '/fixtures/sync-server-search-with-fallback',
skipStart: true,
skipStart,
skipDeployment: true,
buildOptions: inDebugMode ? ['--debug-prerender'] : undefined,
buildOptions: inPrerenderDebugMode ? ['--debug-prerender'] : undefined,
})
if (skipped) {
......@@ -187,29 +258,54 @@ describe.each([
}
if (isNextDev) {
it('does not run in dev', () => {})
return
}
it('should not error the build when synchronously reading search params in a client component if all dynamic access is inside a Suspense boundary', async () => {
try {
await next.start()
} catch {
throw new Error('expected build not to fail for fully static project')
if (inPrerenderDebugMode) {
it('prerender debug mode does not exist for `next dev`', () => {})
return
}
expect(next.cliOutput).toContain('◐ / ')
const $ = await next.render$('/')
expect($('[data-fallback]').length).toBe(2)
})
// We don't error the build, but we do show a dev-only error so that users
// migrate to the async usage.
it('should show a collapsed redbox error', async () => {
const browser = await next.browser('/')
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Route "/" used \`searchParams.foo\`. \`searchParams\` should be awaited before using its properties. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis",
"environmentLabel": "Prerender",
"label": "Console Error",
"source": "app/page.tsx (42:5) @ SearchParamsReadingComponent
> 42 | ).foo
| ^",
"stack": [
"SearchParamsReadingComponent app/page.tsx (42:5)",
"JSON.parse <anonymous> (0:0)",
"JSON.parse <anonymous> (0:0)",
"Page app/page.tsx (19:11)",
],
}
`)
})
} else {
it('should not error the build when synchronously reading search params in a client component if all dynamic access is inside a Suspense boundary', async () => {
try {
await next.start()
} catch {
throw new Error('expected build not to fail for fully static project')
}
expect(next.cliOutput).toContain('◐ / ')
const $ = await next.render$('/')
expect($('[data-fallback]').length).toBe(2)
})
}
})
describe('Sync Dynamic - Without Fallback - server searchParams', () => {
const { next, isNextDev, isTurbopack, skipped } = nextTestSetup({
files: __dirname + '/fixtures/sync-server-search-without-fallback',
skipStart: true,
skipStart,
skipDeployment: true,
buildOptions: inDebugMode ? ['--debug-prerender'] : undefined,
buildOptions: inPrerenderDebugMode ? ['--debug-prerender'] : undefined,
})
if (skipped) {
......@@ -217,85 +313,125 @@ describe.each([
}
if (isNextDev) {
it('does not run in dev', () => {})
return
}
it('should error the build if dynamic IO happens in the root (outside a Suspense)', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
if (inPrerenderDebugMode) {
it('prerender debug mode does not exist for `next dev`', () => {})
return
}
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inDebugMode,
// TODO: Ideally we'd only show the error once.
it('should show a collapsed redbox error', async () => {
const browser = await next.browser('/')
await expect(browser).toDisplayCollapsedRedbox(`
[
{
"description": "Route "/" used \`searchParams.foo\`. \`searchParams\` should be awaited before using its properties. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis",
"environmentLabel": "Prerender",
"label": "Console Error",
"source": "app/page.tsx (40:5) @ SearchParamsReadingComponent
> 40 | ).foo
| ^",
"stack": [
"SearchParamsReadingComponent app/page.tsx (40:5)",
"JSON.parse <anonymous> (0:0)",
"JSON.parse <anonymous> (0:0)",
"Page app/page.tsx (19:11)",
],
},
{
"description": "Route "/" used \`searchParams.foo\`. \`searchParams\` should be awaited before using its properties. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis",
"environmentLabel": "Server",
"label": "Console Error",
"source": "app/page.tsx (40:5) @ SearchParamsReadingComponent
> 40 | ).foo
| ^",
"stack": [
"SearchParamsReadingComponent app/page.tsx (40:5)",
"JSON.parse <anonymous> (0:0)",
"JSON.parse <anonymous> (0:0)",
"LogSafely <anonymous> (0:0)",
],
},
]
`)
})
if (isTurbopack) {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`searchParams.foo\`. \`searchParams\` should be awaited before using its properties. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis
at SearchParamsReadingComponent (turbopack:///[project]/app/page.tsx:40:4)
38 | const fooParams = (
39 | searchParams as unknown as UnsafeUnwrappedSearchParams<typeof searchParams>
> 40 | ).foo
| ^
41 | return (
42 | <div>
43 | this component read the accessed the \`foo\` search param: {fooParams}
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`searchParams.foo\`. \`searchParams\` should be awaited before using its properties. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis
at a (<next-dist-dir>)
at b (<next-dist-dir>)
at c (<next-dist-dir>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
} else {
it('should error the build if dynamic IO happens in the root (outside a Suspense)', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
}
} else {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`searchParams.foo\`. \`searchParams\` should be awaited before using its properties. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis
at SearchParamsReadingComponent (webpack:///app/page.tsx:40:4)
38 | const fooParams = (
39 | searchParams as unknown as UnsafeUnwrappedSearchParams<typeof searchParams>
> 40 | ).foo
| ^
41 | return (
42 | <div>
43 | this component read the accessed the \`foo\` search param: {fooParams}
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inPrerenderDebugMode,
})
if (isTurbopack) {
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`searchParams.foo\`. \`searchParams\` should be awaited before using its properties. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis
at SearchParamsReadingComponent (turbopack:///[project]/app/page.tsx:40:4)
38 | const fooParams = (
39 | searchParams as unknown as UnsafeUnwrappedSearchParams<typeof searchParams>
> 40 | ).foo
| ^
41 | return (
42 | <div>
43 | this component read the accessed the \`foo\` search param: {fooParams}
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`searchParams.foo\`. \`searchParams\` should be awaited before using its properties. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis
at a (<next-dist-dir>)
at b (<next-dist-dir>)
at c (<next-dist-dir>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`searchParams.foo\`. \`searchParams\` should be awaited before using its properties. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis
at a (<next-dist-dir>)
at b (<next-dist-dir>)
at c (<next-dist-dir>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`searchParams.foo\`. \`searchParams\` should be awaited before using its properties. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis
at SearchParamsReadingComponent (webpack:///app/page.tsx:40:4)
38 | const fooParams = (
39 | searchParams as unknown as UnsafeUnwrappedSearchParams<typeof searchParams>
> 40 | ).foo
| ^
41 | return (
42 | <div>
43 | this component read the accessed the \`foo\` search param: {fooParams}
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`searchParams.foo\`. \`searchParams\` should be awaited before using its properties. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis
at a (<next-dist-dir>)
at b (<next-dist-dir>)
at c (<next-dist-dir>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
}
}
})
})
}
})
describe('Sync Dynamic - With Fallback - cookies', () => {
const { next, isNextDev, skipped } = nextTestSetup({
files: __dirname + '/fixtures/sync-cookies-with-fallback',
skipStart: true,
skipStart,
skipDeployment: true,
buildOptions: inDebugMode ? ['--debug-prerender'] : undefined,
buildOptions: inPrerenderDebugMode ? ['--debug-prerender'] : undefined,
})
if (skipped) {
......@@ -303,29 +439,54 @@ describe.each([
}
if (isNextDev) {
it('does not run in dev', () => {})
return
}
it('should not error the build when synchronously reading search params in a client component if all dynamic access is inside a Suspense boundary', async () => {
try {
await next.start()
} catch {
throw new Error('expected build not to fail for fully static project')
if (inPrerenderDebugMode) {
it('prerender debug mode does not exist for `next dev`', () => {})
return
}
expect(next.cliOutput).toContain('◐ / ')
const $ = await next.render$('/')
expect($('[data-fallback]').length).toBe(2)
})
// We don't error the build, but we do show a dev-only error so that users
// migrate to the async usage.
it('should show a collapsed redbox error', async () => {
const browser = await next.browser('/')
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Route "/" used \`cookies().get('token')\`. \`cookies()\` should be awaited before using its value. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis",
"environmentLabel": "Server",
"label": "Console Error",
"source": "app/page.tsx (34:67) @ CookiesReadingComponent
> 34 | const _token = (cookies() as unknown as UnsafeUnwrappedCookies).get('token')
| ^",
"stack": [
"CookiesReadingComponent app/page.tsx (34:67)",
"JSON.parse <anonymous> (0:0)",
"JSON.parse <anonymous> (0:0)",
"Page app/page.tsx (17:11)",
],
}
`)
})
} else {
it('should not error the build when synchronously reading search params in a client component if all dynamic access is inside a Suspense boundary', async () => {
try {
await next.start()
} catch {
throw new Error('expected build not to fail for fully static project')
}
expect(next.cliOutput).toContain('◐ / ')
const $ = await next.render$('/')
expect($('[data-fallback]').length).toBe(2)
})
}
})
describe('Sync Dynamic - Without Fallback - cookies', () => {
const { next, isNextDev, isTurbopack, skipped } = nextTestSetup({
files: __dirname + '/fixtures/sync-cookies-without-fallback',
skipStart: true,
skipStart,
skipDeployment: true,
buildOptions: inDebugMode ? ['--debug-prerender'] : undefined,
buildOptions: inPrerenderDebugMode ? ['--debug-prerender'] : undefined,
})
if (skipped) {
......@@ -333,78 +494,118 @@ describe.each([
}
if (isNextDev) {
it('does not run in dev', () => {})
return
}
it('should error the build if dynamic IO happens in the root (outside a Suspense)', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
if (inPrerenderDebugMode) {
it('prerender debug mode does not exist for `next dev`', () => {})
return
}
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inDebugMode,
// TODO: Ideally we'd only show the error once.
it('should show a collapsed redbox error', async () => {
const browser = await next.browser('/')
await expect(browser).toDisplayCollapsedRedbox(`
[
{
"description": "Route "/" used \`cookies().get('token')\`. \`cookies()\` should be awaited before using its value. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis",
"environmentLabel": "Server",
"label": "Console Error",
"source": "app/page.tsx (32:67) @ CookiesReadingComponent
> 32 | const _token = (cookies() as unknown as UnsafeUnwrappedCookies).get('token')
| ^",
"stack": [
"CookiesReadingComponent app/page.tsx (32:67)",
"JSON.parse <anonymous> (0:0)",
"JSON.parse <anonymous> (0:0)",
"Page app/page.tsx (17:11)",
],
},
{
"description": "Route "/" used \`cookies().get('token')\`. \`cookies()\` should be awaited before using its value. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis",
"environmentLabel": "Server",
"label": "Console Error",
"source": "app/page.tsx (32:67) @ CookiesReadingComponent
> 32 | const _token = (cookies() as unknown as UnsafeUnwrappedCookies).get('token')
| ^",
"stack": [
"CookiesReadingComponent app/page.tsx (32:67)",
"JSON.parse <anonymous> (0:0)",
"JSON.parse <anonymous> (0:0)",
"LogSafely <anonymous> (0:0)",
],
},
]
`)
})
if (isTurbopack) {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`cookies().get('token')\`. \`cookies()\` should be awaited before using its value. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis
at CookiesReadingComponent (turbopack:///[project]/app/page.tsx:32:66)
30 | async function CookiesReadingComponent() {
31 | await new Promise((r) => process.nextTick(r))
> 32 | const _token = (cookies() as unknown as UnsafeUnwrappedCookies).get('token')
| ^
33 | return <div>this component read the \`token\` cookie synchronously</div>
34 | }
35 |
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`cookies().get('token')\`. \`cookies()\` should be awaited before using its value. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis
at a (<next-dist-dir>)
at b (<next-dist-dir>)
at c (<next-dist-dir>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
} else {
it('should error the build if dynamic IO happens in the root (outside a Suspense)', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
}
} else {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`cookies().get('token')\`. \`cookies()\` should be awaited before using its value. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis
at createCookiesAccessError (webpack://<next-src>)
at Promise.get (webpack://<next-src>)
at CookiesReadingComponent (webpack:///app/page.tsx:32:66)
579 | ) {
580 | const prefix = route ? \`Route "\${route}" \` : 'This route '
> 581 | return new Error(
| ^
582 | \`\${prefix}used \${expression}. \` +
583 | \`\\\`cookies()\\\` should be awaited before using its value. \` +
584 | \`Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis\`
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inPrerenderDebugMode,
})
if (isTurbopack) {
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`cookies().get('token')\`. \`cookies()\` should be awaited before using its value. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis
at CookiesReadingComponent (turbopack:///[project]/app/page.tsx:32:66)
30 | async function CookiesReadingComponent() {
31 | await new Promise((r) => process.nextTick(r))
> 32 | const _token = (cookies() as unknown as UnsafeUnwrappedCookies).get('token')
| ^
33 | return <div>this component read the \`token\` cookie synchronously</div>
34 | }
35 |
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`cookies().get('token')\`. \`cookies()\` should be awaited before using its value. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis
at a (<next-dist-dir>)
at b (<next-dist-dir>)
at c (<next-dist-dir>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`cookies().get('token')\`. \`cookies()\` should be awaited before using its value. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis
at a (<next-dist-dir>)
at b (<next-dist-dir>)
at c (<next-dist-dir>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`cookies().get('token')\`. \`cookies()\` should be awaited before using its value. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis
at createCookiesAccessError (webpack://<next-src>)
at Promise.get (webpack://<next-src>)
at CookiesReadingComponent (webpack:///app/page.tsx:32:66)
579 | ) {
580 | const prefix = route ? \`Route "\${route}" \` : 'This route '
> 581 | return new Error(
| ^
582 | \`\${prefix}used \${expression}. \` +
583 | \`\\\`cookies()\\\` should be awaited before using its value. \` +
584 | \`Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis\`
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/" used \`cookies().get('token')\`. \`cookies()\` should be awaited before using its value. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis
at a (<next-dist-dir>)
at b (<next-dist-dir>)
at c (<next-dist-dir>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
}
}
})
})
}
})
})
import { nextTestSetup } from 'e2e-utils'
import { assertNoErrorToast } from 'next-test-utils'
import { getPrerenderOutput } from './utils'
describe.each([
{ inDebugMode: true, name: 'With --prerender-debug' },
{ inDebugMode: false, name: 'Without --prerender-debug' },
])('Dynamic IO Errors - $name', ({ inDebugMode }) => {
{ inPrerenderDebugMode: true, name: 'With --prerender-debug' },
{ inPrerenderDebugMode: false, name: 'Without --prerender-debug' },
])('Dynamic IO Errors - $name', ({ inPrerenderDebugMode }) => {
// We want to skip building and starting in start mode, and in dev mode when
// prerender debug mode is enabled, which doesn't exist for `next dev`.
const skipStart =
process.env.NEXT_TEST_MODE === 'start' || inPrerenderDebugMode
describe('Dynamic Metadata - Static Route', () => {
const { next, isNextDev, isTurbopack, skipped } = nextTestSetup({
files: __dirname + '/fixtures/dynamic-metadata-static-route',
skipStart: true,
skipStart,
skipDeployment: true,
buildOptions: inDebugMode ? ['--debug-prerender'] : undefined,
buildOptions: inPrerenderDebugMode ? ['--debug-prerender'] : undefined,
})
if (skipped) {
......@@ -18,65 +24,85 @@ describe.each([
}
if (isNextDev) {
it('does not run in dev', () => {})
return
}
it('should error the build if generateMetadata is dynamic when the rest of the route is prerenderable', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
if (inPrerenderDebugMode) {
it('prerender debug mode does not exist for `next dev`', () => {})
return
}
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inDebugMode,
it('should show a collapsed redbox error', async () => {
const browser = await next.browser('/')
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Route "/" has a \`generateMetadata\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) when the rest of the route does not. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-metadata",
"environmentLabel": "Server",
"label": "Console Error",
"source": null,
"stack": [
"LogSafely <anonymous> (0:0)",
],
}
`)
})
if (isTurbopack) {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateMetadata\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) when the rest of the route does not. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-metadata
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateMetadata\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) when the rest of the route does not. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-metadata
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
} else {
it('should error the build if generateMetadata is dynamic when the rest of the route is prerenderable', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
}
} else {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateMetadata\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) when the rest of the route does not. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-metadata
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inPrerenderDebugMode,
})
if (isTurbopack) {
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateMetadata\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) when the rest of the route does not. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-metadata
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateMetadata\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) when the rest of the route does not. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-metadata
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
} else {
expect(
getPrerenderOutput(next.cliOutput, { isMinified: !inDebugMode })
).toMatchInlineSnapshot(`
"Route "/" has a \`generateMetadata\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) when the rest of the route does not. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-metadata
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateMetadata\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) when the rest of the route does not. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-metadata
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(
getPrerenderOutput(next.cliOutput, {
isMinified: !inPrerenderDebugMode,
})
).toMatchInlineSnapshot(`
"Route "/" has a \`generateMetadata\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) when the rest of the route does not. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-metadata
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
}
}
})
})
}
})
describe('Dynamic Metadata - Error Route', () => {
const { next, isNextDev, isTurbopack, skipped } = nextTestSetup({
files: __dirname + '/fixtures/dynamic-metadata-error-route',
skipStart: true,
skipStart,
skipDeployment: true,
buildOptions: inDebugMode ? ['--debug-prerender'] : undefined,
buildOptions: inPrerenderDebugMode ? ['--debug-prerender'] : undefined,
})
if (skipped) {
......@@ -84,116 +110,166 @@ describe.each([
}
if (isNextDev) {
it('does not run in dev', () => {})
return
}
// This test is just here because there was a bug when dynamic metadata was used alongside another dynamic IO violation which caused the validation to be skipped.
it('should error the build for the correct reason when there is a dynamic IO violation alongside dynamic metadata', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
if (inPrerenderDebugMode) {
it('prerender debug mode does not exist for `next dev`', () => {})
return
}
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inDebugMode,
})
if (isTurbopack) {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
it('should show a collapsed redbox error', async () => {
const browser = await next.browser('/')
if (isTurbopack) {
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense",
"environmentLabel": "Server",
"label": "Console Error",
"source": null,
"stack": [
"Dynamic [Server] <anonymous> (1:25)",
"<FIXME-file-protocol>",
"main <anonymous> (1:13)",
"body <anonymous> (1:13)",
"html <anonymous> (1:13)",
"Root [Server] <anonymous> (1:22)",
"JSON.parse <anonymous> (0:0)",
"JSON.parse <anonymous> (0:0)",
"LogSafely <anonymous> (0:0)",
],
}
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at a (<next-dist-dir>)
at b (<next-dist-dir>)
at c (<next-dist-dir>)
at d (<next-dist-dir>)
at e (<next-dist-dir>)
at f (<next-dist-dir>)
at g (<next-dist-dir>)
at h (<next-dist-dir>)
at i (<next-dist-dir>)
at j (<next-dist-dir>)
at k (<next-dist-dir>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense",
"environmentLabel": "Server",
"label": "Console Error",
"source": "app/page.tsx (15:7) @ Page
> 15 | <Dynamic />
| ^",
"stack": [
"Dynamic [Server] <anonymous> (1:25)",
"Page app/page.tsx (15:7)",
"main <anonymous> (1:13)",
"body <anonymous> (1:13)",
"html <anonymous> (1:13)",
"Root [Server] <anonymous> (1:22)",
"JSON.parse <anonymous> (0:0)",
"JSON.parse <anonymous> (0:0)",
"LogSafely <anonymous> (0:0)",
],
}
`)
}
} else {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at InnerLayoutRouter (webpack://<next-src>)
at RedirectErrorBoundary (webpack://<next-src>)
at RedirectBoundary (webpack://<next-src>)
at HTTPAccessFallbackErrorBoundary (webpack://<next-src>)
at HTTPAccessFallbackBoundary (webpack://<next-src>)
at LoadingBoundary (webpack://<next-src>)
at ErrorBoundary (webpack://<next-src>)
at InnerScrollAndFocusHandler (webpack://<next-src>)
at ScrollAndFocusHandler (webpack://<next-src>)
at RenderFromTemplateContext (webpack://<next-src>)
at OuterLayoutRouter (webpack://<next-src>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
332 | */
333 | function InnerLayoutRouter({
> 334 | tree,
| ^
335 | segmentPath,
336 | cacheNode,
337 | url,
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
})
} else {
// This test is just here because there was a bug when dynamic metadata was used alongside another dynamic IO violation which caused the validation to be skipped.
it('should error the build for the correct reason when there is a dynamic IO violation alongside dynamic metadata', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
}
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inPrerenderDebugMode,
})
if (isTurbopack) {
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at a (<next-dist-dir>)
at b (<next-dist-dir>)
at c (<next-dist-dir>)
at d (<next-dist-dir>)
at e (<next-dist-dir>)
at f (<next-dist-dir>)
at g (<next-dist-dir>)
at h (<next-dist-dir>)
at i (<next-dist-dir>)
at j (<next-dist-dir>)
at k (<next-dist-dir>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at a (<next-dist-dir>)
at b (<next-dist-dir>)
at c (<next-dist-dir>)
at d (<next-dist-dir>)
at e (<next-dist-dir>)
at f (<next-dist-dir>)
at g (<next-dist-dir>)
at h (<next-dist-dir>)
at i (<next-dist-dir>)
at j (<next-dist-dir>)
at k (<next-dist-dir>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at InnerLayoutRouter (webpack://<next-src>)
at RedirectErrorBoundary (webpack://<next-src>)
at RedirectBoundary (webpack://<next-src>)
at HTTPAccessFallbackErrorBoundary (webpack://<next-src>)
at HTTPAccessFallbackBoundary (webpack://<next-src>)
at LoadingBoundary (webpack://<next-src>)
at ErrorBoundary (webpack://<next-src>)
at InnerScrollAndFocusHandler (webpack://<next-src>)
at ScrollAndFocusHandler (webpack://<next-src>)
at RenderFromTemplateContext (webpack://<next-src>)
at OuterLayoutRouter (webpack://<next-src>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
332 | */
333 | function InnerLayoutRouter({
> 334 | tree,
| ^
335 | segmentPath,
336 | cacheNode,
337 | url,
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at a (<next-dist-dir>)
at b (<next-dist-dir>)
at c (<next-dist-dir>)
at d (<next-dist-dir>)
at e (<next-dist-dir>)
at f (<next-dist-dir>)
at g (<next-dist-dir>)
at h (<next-dist-dir>)
at i (<next-dist-dir>)
at j (<next-dist-dir>)
at k (<next-dist-dir>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
}
}
})
})
}
})
describe('Dynamic Metadata - Static Route With Suspense', () => {
const { next, isNextDev, isTurbopack, skipped } = nextTestSetup({
files: __dirname + '/fixtures/dynamic-metadata-static-with-suspense',
skipStart: true,
skipStart,
skipDeployment: true,
buildOptions: inDebugMode ? ['--debug-prerender'] : undefined,
buildOptions: inPrerenderDebugMode ? ['--debug-prerender'] : undefined,
})
if (skipped) {
......@@ -201,63 +277,81 @@ describe.each([
}
if (isNextDev) {
it('does not run in dev', () => {})
return
}
it('should error the build if generateMetadata is dynamic when the rest of the route is prerenderable', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
if (inPrerenderDebugMode) {
it('prerender debug mode does not exist for `next dev`', () => {})
return
}
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inDebugMode,
it('should show a collapsed redbox error', async () => {
const browser = await next.browser('/')
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Route "/" has a \`generateMetadata\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) when the rest of the route does not. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-metadata",
"environmentLabel": "Server",
"label": "Console Error",
"source": null,
"stack": [
"LogSafely <anonymous> (0:0)",
],
}
`)
})
if (isTurbopack) {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateMetadata\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) when the rest of the route does not. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-metadata
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateMetadata\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) when the rest of the route does not. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-metadata
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
} else {
it('should error the build if generateMetadata is dynamic when the rest of the route is prerenderable', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
}
} else {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateMetadata\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) when the rest of the route does not. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-metadata
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inPrerenderDebugMode,
})
if (isTurbopack) {
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateMetadata\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) when the rest of the route does not. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-metadata
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateMetadata\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) when the rest of the route does not. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-metadata
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
} else {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateMetadata\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) when the rest of the route does not. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-metadata
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateMetadata\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) when the rest of the route does not. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-metadata
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateMetadata\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) when the rest of the route does not. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-metadata
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
}
}
})
})
}
})
describe('Dynamic Metadata - Dynamic Route', () => {
const { next, isNextDev, skipped } = nextTestSetup({
files: __dirname + '/fixtures/dynamic-metadata-dynamic-route',
skipStart: true,
skipStart,
skipDeployment: true,
buildOptions: inDebugMode ? ['--debug-prerender'] : undefined,
buildOptions: inPrerenderDebugMode ? ['--debug-prerender'] : undefined,
})
if (skipped) {
......@@ -265,30 +359,37 @@ describe.each([
}
if (isNextDev) {
it('does not run in dev', () => {})
return
}
it('should partially prerender when all dynamic components are inside a Suspense boundary', async () => {
try {
await next.start()
} catch {
throw new Error('expected build not to fail for fully static project')
if (inPrerenderDebugMode) {
it('prerender debug mode does not exist for `next dev`', () => {})
return
}
expect(next.cliOutput).toContain('◐ / ')
const $ = await next.render$('/')
expect($('#dynamic').text()).toBe('Dynamic')
expect($('[data-fallback]').length).toBe(1)
})
it('should not show a collapsed redbox error', async () => {
const browser = await next.browser('/')
await assertNoErrorToast(browser)
})
} else {
it('should partially prerender when all dynamic components are inside a Suspense boundary', async () => {
try {
await next.start()
} catch {
throw new Error('expected build not to fail for fully static project')
}
expect(next.cliOutput).toContain('◐ / ')
const $ = await next.render$('/')
expect($('#dynamic').text()).toBe('Dynamic')
expect($('[data-fallback]').length).toBe(1)
})
}
})
describe('Dynamic Viewport - Static Route', () => {
const { next, isNextDev, isTurbopack, skipped } = nextTestSetup({
files: __dirname + '/fixtures/dynamic-viewport-static-route',
skipStart: true,
skipStart,
skipDeployment: true,
buildOptions: inDebugMode ? ['--debug-prerender'] : undefined,
buildOptions: inPrerenderDebugMode ? ['--debug-prerender'] : undefined,
})
if (skipped) {
......@@ -296,63 +397,81 @@ describe.each([
}
if (isNextDev) {
it('does not run in dev', () => {})
return
}
it('should error the build if generateViewport is dynamic', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
if (inPrerenderDebugMode) {
it('prerender debug mode does not exist for `next dev`', () => {})
return
}
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inDebugMode,
it('should show a collapsed redbox error', async () => {
const browser = await next.browser('/')
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Route "/" has a \`generateViewport\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) without explicitly allowing fully dynamic rendering. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-viewport",
"environmentLabel": "Server",
"label": "Console Error",
"source": null,
"stack": [
"LogSafely <anonymous> (0:0)",
],
}
`)
})
if (isTurbopack) {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateViewport\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) without explicitly allowing fully dynamic rendering. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-viewport
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateViewport\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) without explicitly allowing fully dynamic rendering. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-viewport
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
} else {
it('should error the build if generateViewport is dynamic', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
}
} else {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateViewport\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) without explicitly allowing fully dynamic rendering. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-viewport
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inPrerenderDebugMode,
})
if (isTurbopack) {
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateViewport\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) without explicitly allowing fully dynamic rendering. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-viewport
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateViewport\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) without explicitly allowing fully dynamic rendering. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-viewport
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
} else {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateViewport\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) without explicitly allowing fully dynamic rendering. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-viewport
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateViewport\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) without explicitly allowing fully dynamic rendering. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-viewport
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateViewport\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) without explicitly allowing fully dynamic rendering. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-viewport
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
}
}
})
})
}
})
describe('Dynamic Viewport - Dynamic Route', () => {
const { next, isNextDev, isTurbopack, skipped } = nextTestSetup({
files: __dirname + '/fixtures/dynamic-viewport-dynamic-route',
skipStart: true,
skipStart,
skipDeployment: true,
buildOptions: inDebugMode ? ['--debug-prerender'] : undefined,
buildOptions: inPrerenderDebugMode ? ['--debug-prerender'] : undefined,
})
if (skipped) {
......@@ -360,63 +479,81 @@ describe.each([
}
if (isNextDev) {
it('does not run in dev', () => {})
return
}
it('should error the build if generateViewport is dynamic even if there are other uses of dynamic on the page', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
if (inPrerenderDebugMode) {
it('prerender debug mode does not exist for `next dev`', () => {})
return
}
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inDebugMode,
it('should show a collapsed redbox error', async () => {
const browser = await next.browser('/')
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Route "/" has a \`generateViewport\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) without explicitly allowing fully dynamic rendering. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-viewport",
"environmentLabel": "Server",
"label": "Console Error",
"source": null,
"stack": [
"LogSafely <anonymous> (0:0)",
],
}
`)
})
if (isTurbopack) {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateViewport\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) without explicitly allowing fully dynamic rendering. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-viewport
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateViewport\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) without explicitly allowing fully dynamic rendering. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-viewport
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
} else {
it('should error the build if generateViewport is dynamic even if there are other uses of dynamic on the page', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
}
} else {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateViewport\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) without explicitly allowing fully dynamic rendering. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-viewport
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inPrerenderDebugMode,
})
if (isTurbopack) {
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateViewport\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) without explicitly allowing fully dynamic rendering. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-viewport
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateViewport\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) without explicitly allowing fully dynamic rendering. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-viewport
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
} else {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateViewport\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) without explicitly allowing fully dynamic rendering. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-viewport
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateViewport\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) without explicitly allowing fully dynamic rendering. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-viewport
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Route "/" has a \`generateViewport\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) without explicitly allowing fully dynamic rendering. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-viewport
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
}
}
})
})
}
})
describe('Static Route', () => {
const { next, isNextDev, skipped } = nextTestSetup({
files: __dirname + '/fixtures/static',
skipStart: true,
skipStart,
skipDeployment: true,
buildOptions: inDebugMode ? ['--debug-prerender'] : undefined,
buildOptions: inPrerenderDebugMode ? ['--debug-prerender'] : undefined,
})
if (skipped) {
......@@ -424,26 +561,33 @@ describe.each([
}
if (isNextDev) {
it('does not run in dev', () => {})
return
}
it('should not error the build when all routes are static', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
throw new Error('expected build not to fail for fully static project')
if (inPrerenderDebugMode) {
it('prerender debug mode does not exist for `next dev`', () => {})
return
}
})
it('should not show a collapsed redbox error', async () => {
const browser = await next.browser('/')
await assertNoErrorToast(browser)
})
} else {
it('should not error the build when all routes are static', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
throw new Error('expected build not to fail for fully static project')
}
})
}
})
describe('Dynamic Root', () => {
const { next, isNextDev, isTurbopack, skipped } = nextTestSetup({
files: __dirname + '/fixtures/dynamic-root',
skipStart: true,
skipStart,
skipDeployment: true,
buildOptions: inDebugMode ? ['--debug-prerender'] : undefined,
buildOptions: inPrerenderDebugMode ? ['--debug-prerender'] : undefined,
})
if (skipped) {
......@@ -451,182 +595,276 @@ describe.each([
}
if (isNextDev) {
it('does not run in dev', () => {})
return
}
it('should error the build if dynamic IO happens in the root (outside a Suspense)', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
if (inPrerenderDebugMode) {
it('prerender debug mode does not exist for `next dev`', () => {})
return
}
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inDebugMode,
})
if (isTurbopack) {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at IndirectionTwo (turbopack:///[project]/app/indirection.tsx:7:33)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
5 | }
6 |
it('should show a collapsed redbox with two errors', async () => {
const browser = await next.browser('/')
if (isTurbopack) {
await expect(browser).toDisplayCollapsedRedbox(`
[
{
"description": "Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense",
"environmentLabel": "Server",
"label": "Console Error",
"source": "app/indirection.tsx (7:34) @ IndirectionTwo
> 7 | export function IndirectionTwo({ children }) {
| ^
8 | return children
9 | }
10 |
Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
| ^",
"stack": [
"FetchingComponent [Server] <anonymous> (1:35)",
"IndirectionTwo app/indirection.tsx (7:34)",
"<FIXME-file-protocol>",
"main <anonymous> (1:13)",
"body <anonymous> (1:13)",
"html <anonymous> (1:13)",
"Root [Server] <anonymous> (1:22)",
"JSON.parse <anonymous> (0:0)",
"JSON.parse <anonymous> (0:0)",
"LogSafely <anonymous> (0:0)",
],
},
{
"description": "Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense",
"environmentLabel": "Server",
"label": "Console Error",
"source": null,
"stack": [
"FetchingComponent [Server] <anonymous> (1:35)",
"<FIXME-file-protocol>",
"main <anonymous> (1:13)",
"body <anonymous> (1:13)",
"html <anonymous> (1:13)",
"Root [Server] <anonymous> (1:22)",
"JSON.parse <anonymous> (0:0)",
"JSON.parse <anonymous> (0:0)",
"LogSafely <anonymous> (0:0)",
],
},
]
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at a (<next-dist-dir>)
at b (<next-dist-dir>)
at c (<next-dist-dir>)
at d (<next-dist-dir>)
at e (<next-dist-dir>)
at f (<next-dist-dir>)
at g (<next-dist-dir>)
at h (<next-dist-dir>)
at i (<next-dist-dir>)
at j (<next-dist-dir>)
at k (<next-dist-dir>)
at l (<next-dist-dir>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at m (<next-dist-dir>)
at n (<next-dist-dir>)
at o (<next-dist-dir>)
at p (<next-dist-dir>)
at q (<next-dist-dir>)
at r (<next-dist-dir>)
at s (<next-dist-dir>)
at t (<next-dist-dir>)
at u (<next-dist-dir>)
at v (<next-dist-dir>)
at w (<next-dist-dir>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
} else {
if (inDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at IndirectionTwo (webpack:///app/indirection.tsx:7:33)
at InnerLayoutRouter (webpack://<next-src>)
at RedirectErrorBoundary (webpack://<next-src>)
at RedirectBoundary (webpack://<next-src>)
at HTTPAccessFallbackErrorBoundary (webpack://<next-src>)
at HTTPAccessFallbackBoundary (webpack://<next-src>)
at LoadingBoundary (webpack://<next-src>)
at ErrorBoundary (webpack://<next-src>)
at InnerScrollAndFocusHandler (webpack://<next-src>)
at ScrollAndFocusHandler (webpack://<next-src>)
at RenderFromTemplateContext (webpack://<next-src>)
at OuterLayoutRouter (webpack://<next-src>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
5 | }
6 |
await expect(browser).toDisplayCollapsedRedbox(`
[
{
"description": "Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense",
"environmentLabel": "Server",
"label": "Console Error",
"source": "app/indirection.tsx (7:34) @ IndirectionTwo
> 7 | export function IndirectionTwo({ children }) {
| ^
8 | return children
9 | }
10 |
Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at InnerLayoutRouter (webpack://<next-src>)
at RedirectErrorBoundary (webpack://<next-src>)
at RedirectBoundary (webpack://<next-src>)
at HTTPAccessFallbackErrorBoundary (webpack://<next-src>)
at HTTPAccessFallbackBoundary (webpack://<next-src>)
at LoadingBoundary (webpack://<next-src>)
at ErrorBoundary (webpack://<next-src>)
at InnerScrollAndFocusHandler (webpack://<next-src>)
at ScrollAndFocusHandler (webpack://<next-src>)
at RenderFromTemplateContext (webpack://<next-src>)
at OuterLayoutRouter (webpack://<next-src>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
332 | */
333 | function InnerLayoutRouter({
> 334 | tree,
| ^
335 | segmentPath,
336 | cacheNode,
337 | url,
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
| ^",
"stack": [
"FetchingComponent [Server] <anonymous> (1:35)",
"IndirectionTwo app/indirection.tsx (7:34)",
"Page app/page.tsx (16:9)",
"main <anonymous> (1:13)",
"body <anonymous> (1:13)",
"html <anonymous> (1:13)",
"Root [Server] <anonymous> (1:22)",
"JSON.parse <anonymous> (0:0)",
"JSON.parse <anonymous> (0:0)",
"LogSafely <anonymous> (0:0)",
],
},
{
"description": "Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense",
"environmentLabel": "Server",
"label": "Console Error",
"source": "app/page.tsx (16:9) @ Page
> 16 | <FetchingComponent nonce="a" cached={true} />
| ^",
"stack": [
"FetchingComponent [Server] <anonymous> (1:35)",
"Page app/page.tsx (16:9)",
"main <anonymous> (1:13)",
"body <anonymous> (1:13)",
"html <anonymous> (1:13)",
"Root [Server] <anonymous> (1:22)",
"JSON.parse <anonymous> (0:0)",
"JSON.parse <anonymous> (0:0)",
"LogSafely <anonymous> (0:0)",
],
},
]
`)
}
})
} else {
it('should error the build if dynamic IO happens in the root (outside a Suspense)', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
}
const output = getPrerenderOutput(next.cliOutput, {
isMinified: !inPrerenderDebugMode,
})
if (isTurbopack) {
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at IndirectionTwo (turbopack:///[project]/app/indirection.tsx:7:33)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
5 | }
6 |
> 7 | export function IndirectionTwo({ children }) {
| ^
8 | return children
9 | }
10 |
Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at a (<next-dist-dir>)
at b (<next-dist-dir>)
at c (<next-dist-dir>)
at d (<next-dist-dir>)
at e (<next-dist-dir>)
at f (<next-dist-dir>)
at g (<next-dist-dir>)
at h (<next-dist-dir>)
at i (<next-dist-dir>)
at j (<next-dist-dir>)
at k (<next-dist-dir>)
at l (<next-dist-dir>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at m (<next-dist-dir>)
at n (<next-dist-dir>)
at o (<next-dist-dir>)
at p (<next-dist-dir>)
at q (<next-dist-dir>)
at r (<next-dist-dir>)
at s (<next-dist-dir>)
at t (<next-dist-dir>)
at u (<next-dist-dir>)
at v (<next-dist-dir>)
at w (<next-dist-dir>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at a (<next-dist-dir>)
at b (<next-dist-dir>)
at c (<next-dist-dir>)
at d (<next-dist-dir>)
at e (<next-dist-dir>)
at f (<next-dist-dir>)
at g (<next-dist-dir>)
at h (<next-dist-dir>)
at i (<next-dist-dir>)
at j (<next-dist-dir>)
at k (<next-dist-dir>)
at l (<next-dist-dir>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at m (<next-dist-dir>)
at n (<next-dist-dir>)
at o (<next-dist-dir>)
at p (<next-dist-dir>)
at q (<next-dist-dir>)
at r (<next-dist-dir>)
at s (<next-dist-dir>)
at t (<next-dist-dir>)
at u (<next-dist-dir>)
at v (<next-dist-dir>)
at w (<next-dist-dir>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
if (inPrerenderDebugMode) {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at IndirectionTwo (webpack:///app/indirection.tsx:7:33)
at InnerLayoutRouter (webpack://<next-src>)
at RedirectErrorBoundary (webpack://<next-src>)
at RedirectBoundary (webpack://<next-src>)
at HTTPAccessFallbackErrorBoundary (webpack://<next-src>)
at HTTPAccessFallbackBoundary (webpack://<next-src>)
at LoadingBoundary (webpack://<next-src>)
at ErrorBoundary (webpack://<next-src>)
at InnerScrollAndFocusHandler (webpack://<next-src>)
at ScrollAndFocusHandler (webpack://<next-src>)
at RenderFromTemplateContext (webpack://<next-src>)
at OuterLayoutRouter (webpack://<next-src>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
5 | }
6 |
> 7 | export function IndirectionTwo({ children }) {
| ^
8 | return children
9 | }
10 |
Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at InnerLayoutRouter (webpack://<next-src>)
at RedirectErrorBoundary (webpack://<next-src>)
at RedirectBoundary (webpack://<next-src>)
at HTTPAccessFallbackErrorBoundary (webpack://<next-src>)
at HTTPAccessFallbackBoundary (webpack://<next-src>)
at LoadingBoundary (webpack://<next-src>)
at ErrorBoundary (webpack://<next-src>)
at InnerScrollAndFocusHandler (webpack://<next-src>)
at ScrollAndFocusHandler (webpack://<next-src>)
at RenderFromTemplateContext (webpack://<next-src>)
at OuterLayoutRouter (webpack://<next-src>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
332 | */
333 | function InnerLayoutRouter({
> 334 | tree,
| ^
335 | segmentPath,
336 | cacheNode,
337 | url,
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on following paths:
/page: /"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at a (<next-dist-dir>)
at b (<next-dist-dir>)
at c (<next-dist-dir>)
at d (<next-dist-dir>)
at e (<next-dist-dir>)
at f (<next-dist-dir>)
at g (<next-dist-dir>)
at h (<next-dist-dir>)
at i (<next-dist-dir>)
at j (<next-dist-dir>)
at k (<next-dist-dir>)
at l (<next-dist-dir>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error: Route "/": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense
at m (<next-dist-dir>)
at n (<next-dist-dir>)
at o (<next-dist-dir>)
at p (<next-dist-dir>)
at q (<next-dist-dir>)
at r (<next-dist-dir>)
at s (<next-dist-dir>)
at t (<next-dist-dir>)
at u (<next-dist-dir>)
at v (<next-dist-dir>)
at w (<next-dist-dir>)
at main (<anonymous>)
at body (<anonymous>)
at html (<anonymous>)
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /page: /, exiting the build."
`)
}
}
}
})
})
}
})
describe('Dynamic Boundary', () => {
const { next, isNextDev, skipped } = nextTestSetup({
files: __dirname + '/fixtures/dynamic-boundary',
skipStart: true,
skipStart,
skipDeployment: true,
buildOptions: inDebugMode ? ['--debug-prerender'] : undefined,
buildOptions: inPrerenderDebugMode ? ['--debug-prerender'] : undefined,
})
if (skipped) {
......@@ -634,21 +872,28 @@ describe.each([
}
if (isNextDev) {
it('does not run in dev', () => {})
return
}
it('should partially prerender when all dynamic components are inside a Suspense boundary', async () => {
try {
await next.start()
} catch {
throw new Error('expected build not to fail for fully static project')
// we expect the build to fail
if (inPrerenderDebugMode) {
it('prerender debug mode does not exist for `next dev`', () => {})
return
}
expect(next.cliOutput).toContain('◐ / ')
const $ = await next.render$('/')
expect($('[data-fallback]').length).toBe(2)
})
it('should not show a collapsed redbox error', async () => {
const browser = await next.browser('/')
await assertNoErrorToast(browser)
})
} else {
it('should partially prerender when all dynamic components are inside a Suspense boundary', async () => {
try {
await next.start()
} catch {
throw new Error('expected build not to fail for fully static project')
// we expect the build to fail
}
expect(next.cliOutput).toContain('◐ / ')
const $ = await next.render$('/')
expect($('[data-fallback]').length).toBe(2)
})
}
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment