Unverified Commit 5b6747ad authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub

Prerender HTTP access fallbacks with Cache Components semantics (#93988)

The body of `if (cacheComponents)` in `prerenderToStream` is extracted
into a local helper, `prerenderWithCacheComponents(getPayload)`. The
catch-block error paths now route through that helper whenever Cache
Components is enabled, which means the legacy `prerender-legacy` store
is no longer reachable from a Cache Components prerender.

As a result, `notFound()`, `forbidden()`, and `unauthorized()` recovery
renders the matching fallback boundary under `prerender` and
`prerender-client` semantics. Dynamic API access in those boundaries —
for example `useSearchParams()` without a surrounding `<Suspense>` — now
surfaces as a blocking-route error instead of the legacy
`BailoutToCSRError`.

The dev side will be handled in a follow-up. The prerender handling
diverged a bit from the dev rendering in #92231, and we'll likely need
to re-align the dev rendering first.

> [!TIP]
> Best reviewed with hidden whitespace changes.
parent fda6986b
......@@ -5603,6 +5603,15 @@ async function spawnStaticShellValidationInDev(
* While it doesn't return a stream we want it to have identical
* prerender semantics to prerenderToStream and should update it
* in conjunction with any changes to that function.
*
* TODO: HTTP access fallback recovery (`notFound()` / `forbidden()` /
* `unauthorized()`) has been moved to use Cache Components prerender
* semantics in `prerenderToStream` via `prerenderWithCacheComponents`.
* This dev validation path still only validates the page tree, not the
* fallback boundary, so dynamic API access in `not-found.tsx` etc. is
* not yet observed by the dev redbox. Re-validate against the fallback
* boundary tree when an `HTTPAccessFallbackError` surfaces from the
* upstream RSC render to match the build-time behavior.
*/
async function spawnStaticShellValidationInDevImpl(
accumulatedChunksPromise: Promise<AccumulatedStreamChunks>,
......@@ -7313,8 +7322,9 @@ async function prerenderToStream(
let prerenderStore: PrerenderStore | null = null
try {
if (cacheComponents) {
const prerenderWithCacheComponents = async (
getPayload: () => Promise<InitialRSCPayload>
): Promise<PrerenderToStreamResult> => {
/**
* cacheComponents with PPR
*
......@@ -7396,10 +7406,7 @@ async function prerenderToStream(
// is if it completes in a microtask and that's likely very rare for any non-trivial app
const initialServerPayload = await workUnitAsyncStorage.run(
initialServerPayloadPrerenderStore,
getRSCPayload,
tree,
ctx,
{ is404: res.statusCode === 404 }
getPayload
)
const initialServerPrerenderStore: PrerenderStore = (prerenderStore = {
......@@ -7676,10 +7683,7 @@ async function prerenderToStream(
const finalAttemptRSCPayload = await workUnitAsyncStorage.run(
finalServerPayloadPrerenderStore,
getRSCPayload,
tree,
ctx,
{ is404: res.statusCode === 404 }
getPayload
)
let staleTimeIterable: StaleTimeIterable | undefined
......@@ -7832,8 +7836,7 @@ async function prerenderToStream(
const finalClientOnHeaders = createOnHeadersCallback(appendHeader)
let { prelude: unprocessedPrelude, postponed } =
await runInSequentialTasks(
let { prelude: unprocessedPrelude, postponed } = await runInSequentialTasks(
() => {
const pendingFinalClientResult = workUnitAsyncStorage.run(
finalClientPrerenderStore,
......@@ -7855,9 +7858,8 @@ async function prerenderToStream(
isPrerenderInterruptedError(err) ||
finalClientReactController.signal.aborted
) {
const componentStack: string | undefined = (
errorInfo as any
).componentStack
const componentStack: string | undefined = (errorInfo as any)
.componentStack
if (typeof componentStack === 'string') {
trackAllowedDynamicAccess(
workStore,
......@@ -8092,6 +8094,13 @@ async function prerenderToStream(
),
}
}
}
try {
if (cacheComponents) {
return await prerenderWithCacheComponents(() =>
getRSCPayload(tree, ctx, { is404: res.statusCode === 404 })
)
} else if (experimental.isRoutePPREnabled) {
// We're statically generating with PPR and need to do dynamic tracking
let dynamicTracking = createDynamicTrackingState(isDebugDynamicAccesses)
......@@ -8491,6 +8500,59 @@ async function prerenderToStream(
metadata.statusCode = res.statusCode
}
if (cacheComponents) {
// Route the recovery render through the Cache Components prerender helper
// to prerender with CC semantics. This ensures for example that dynamic
// API access in the HTTP fallback boundary (e.g. `useSearchParams()` in
// `not-found.tsx`) is observed by the helper's dynamic validation and
// surfaces as a blocking-route error rather than the legacy
// `BailoutToCSRError`. For recoveries that render the synthetic error
// shell from `getErrorRSCPayload` (generic `Error`, `RedirectError`,
// `HTTPAccessFallbackError` with no matching boundary), the helper still
// runs but no user code participates in the SSR — `global-error.tsx` is
// plumbed into the payload but its `RootErrorBoundary` is never triggered
// because the synthetic shell can't throw. We still route synthetic-shell
// recoveries through the helper for consistency so legacy prerendering is
// never used when Cache Components is on.
let prerenderHTTPError: PrerenderHTTPErrorState | undefined
if (isHTTPAccessFallbackError(err)) {
const triggeredStatus = getAccessFallbackHTTPStatus(
err
) as HTTPAccessErrorStatusCode
const boundaryTree = findPrerenderHTTPErrorBoundaryTree(
tree,
triggeredStatus,
ctx.renderOpts.experimental.authInterrupts
)
if (boundaryTree) {
prerenderHTTPError = {
boundaryTree,
triggeredStatus,
}
}
}
if (prerenderHTTPError) {
return await prerenderWithCacheComponents(() =>
getRSCPayload(tree, ctx, {
is404: errorType === 'not-found',
prerenderHTTPError,
})
)
}
return await prerenderWithCacheComponents(() =>
getErrorRSCPayload(
tree,
ctx,
reactServerErrorsByDigest.has((err as any).digest) ? undefined : err,
errorType
)
)
}
const [errorPreinitScripts, errorBootstrapScript] = getRequiredScripts(
buildManifest,
assetPrefix,
......@@ -8520,37 +8582,8 @@ async function prerenderToStream(
: INFINITE_CACHE,
tags: [...(prerenderStore?.tags || implicitTags.tags)],
})
let prerenderHTTPError: PrerenderHTTPErrorState | undefined
if (cacheComponents && isHTTPAccessFallbackError(err)) {
const triggeredStatus = getAccessFallbackHTTPStatus(
err
) as HTTPAccessErrorStatusCode
const boundaryTree = findPrerenderHTTPErrorBoundaryTree(
tree,
triggeredStatus,
ctx.renderOpts.experimental.authInterrupts
)
if (boundaryTree) {
prerenderHTTPError = {
boundaryTree,
triggeredStatus,
}
}
}
const errorRSCPayload = prerenderHTTPError
? await workUnitAsyncStorage.run(
prerenderLegacyStore,
getRSCPayload,
tree,
ctx,
{
is404: errorType === 'not-found',
prerenderHTTPError,
}
)
: await workUnitAsyncStorage.run(
const errorRSCPayload = await workUnitAsyncStorage.run(
prerenderLegacyStore,
getErrorRSCPayload,
tree,
......@@ -8559,7 +8592,7 @@ async function prerenderToStream(
errorType
)
const errorServerStreamRaw = workUnitAsyncStorage.run(
const errorServerStream = workUnitAsyncStorage.run(
prerenderLegacyStore,
renderFlightStream,
ComponentMod,
......@@ -8571,19 +8604,6 @@ async function prerenderToStream(
}
)
let errorServerStream = errorServerStreamRaw
const errorFlightResultPromise = prerenderHTTPError
? (() => {
// Fizz still needs to read the Flight stream to render ErrorApp, but
// the prerender path also needs a buffered Flight result for the HTML
// prelude and segment data collectors. Tee the stream so each consumer
// gets its own copy.
const [appStream, flightStream] = teeStream(errorServerStreamRaw)
errorServerStream = appStream
return createReactServerPrerenderResultFromRender(flightStream)
})()
: null
try {
const { stream: errorHtmlStream } = await workUnitAsyncStorage.run(
prerenderLegacyStore,
......@@ -8604,15 +8624,10 @@ async function prerenderToStream(
{ waitForAllReady: true }
)
const resolvedFlightResult = errorFlightResultPromise
? await errorFlightResultPromise
: reactServerPrerenderResult
if (errorFlightResultPromise) {
reactServerPrerenderResult.consume()
}
if (shouldGenerateStaticFlightData(workStore)) {
const flightData = await streamToBuffer(resolvedFlightResult.asStream())
const flightData = await streamToBuffer(
reactServerPrerenderResult.asStream()
)
metadata.flightData = flightData
await collectSegmentData(
flightData,
......@@ -8624,14 +8639,12 @@ async function prerenderToStream(
)
}
const flightStream = resolvedFlightResult.consumeAsStream()
return {
digestErrorsMap: reactServerErrorsByDigest,
ssrErrors: allCapturedErrors,
stream: await continueFizzStream(errorHtmlStream, {
inlinedDataStream: createInlinedDataStream(
flightStream,
reactServerPrerenderResult.consumeAsStream(),
nonce,
formState
),
......
......@@ -100,7 +100,17 @@ describe('Cache Components HTTP Access Fallback Prerender', () => {
if (isTurbopack) {
if (isDebugPrerender) {
expect(output).toMatchInlineSnapshot(`
"Error: Bail out to client-side rendering: useSearchParams()
"Error: Route "/not-found/[slug]": Next.js encountered uncached or runtime data during prerendering.
\`fetch(...)\`, \`cookies()\`, \`headers()\`, \`params\`, \`searchParams\`, or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered, blocking the page load and leading to a slower user experience.
Ways to fix this:
- Cache the data access with \`"use cache"\`
- Provide a placeholder with \`<Suspense fallback={...}>\` around the data access
- If the runtime data is \`params\` and they're known, prerender them with \`generateStaticParams\`
- Set \`export const instant = false\` to allow a blocking route
Learn more: https://nextjs.org/docs/messages/blocking-route
at NotFound (app/not-found/[slug]/not-found.tsx:6:39)
4 |
5 | export default function NotFound() {
......@@ -108,10 +118,8 @@ describe('Cache Components HTTP Access Fallback Prerender', () => {
| ^
7 |
8 | return <p>not found {searchParams.get('foo')}</p>
9 | } {
reason: 'useSearchParams()',
digest: 'BAILOUT_TO_CLIENT_SIDE_RENDERING'
}
9 | }
To debug the issue, start the app in development mode by running \`next dev\`, then open "/not-found/[slug]" in your browser to investigate the error.
Error occurred prerendering page "/not-found/not-found". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on 1 path:
......@@ -119,18 +127,30 @@ describe('Cache Components HTTP Access Fallback Prerender', () => {
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Bail out to client-side rendering: useSearchParams()
"Error: Route "/not-found/[slug]": Next.js encountered uncached or runtime data during prerendering.
\`fetch(...)\`, \`cookies()\`, \`headers()\`, \`params\`, \`searchParams\`, or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered, blocking the page load and leading to a slower user experience.
Ways to fix this:
- Cache the data access with \`"use cache"\`
- Provide a placeholder with \`<Suspense fallback={...}>\` around the data access
- If the runtime data is \`params\` and they're known, prerender them with \`generateStaticParams\`
- Set \`export const instant = false\` to allow a blocking route
Learn more: https://nextjs.org/docs/messages/blocking-route
at <unknown> (app/not-found/[slug]/not-found.tsx:6:24)
at body (<anonymous>)
at html (<anonymous>)
4 |
5 | export default function NotFound() {
> 6 | const searchParams = useSearchParams()
| ^
7 |
8 | return <p>not found {searchParams.get('foo')}</p>
9 | } {
reason: 'useSearchParams()',
digest: 'BAILOUT_TO_CLIENT_SIDE_RENDERING'
}
9 | }
To get a more detailed stack trace and pinpoint the issue, try one of the following:
- Start the app in development mode by running \`next dev\`, then open "/not-found/[slug]" in your browser to investigate the error.
- Rerun the production build with \`next build --debug-prerender\` to generate better stack traces.
Error occurred prerendering page "/not-found/not-found". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /not-found/[slug]/page: /not-found/not-found, exiting the build."
`)
......@@ -138,20 +158,26 @@ describe('Cache Components HTTP Access Fallback Prerender', () => {
} else {
if (isDebugPrerender) {
expect(output).toMatchInlineSnapshot(`
"Error: Bail out to client-side rendering: useSearchParams()
at useDynamicSearchParams (webpack:///<next-src>)
at useSearchParams (webpack:///<next-src>)
"Error: Route "/not-found/[slug]": Next.js encountered uncached or runtime data during prerendering.
\`fetch(...)\`, \`cookies()\`, \`headers()\`, \`params\`, \`searchParams\`, or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered, blocking the page load and leading to a slower user experience.
Ways to fix this:
- Cache the data access with \`"use cache"\`
- Provide a placeholder with \`<Suspense fallback={...}>\` around the data access
- If the runtime data is \`params\` and they're known, prerender them with \`generateStaticParams\`
- Set \`export const instant = false\` to allow a blocking route
Learn more: https://nextjs.org/docs/messages/blocking-route
at NotFound (webpack:///app/not-found/[slug]/not-found.tsx:6:39)
707 | return
708 | }
> 709 | throw new BailoutToCSRError(expression)
4 |
5 | export default function NotFound() {
> 6 | const searchParams = useSearchParams()
| ^
710 | }
711 | case 'prerender':
712 | case 'prerender-runtime': {
reason: 'useSearchParams()',
digest: 'BAILOUT_TO_CLIENT_SIDE_RENDERING'
}
7 |
8 | return <p>not found {searchParams.get('foo')}</p>
9 | }
To debug the issue, start the app in development mode by running \`next dev\`, then open "/not-found/[slug]" in your browser to investigate the error.
Error occurred prerendering page "/not-found/not-found". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on 1 path:
......@@ -159,13 +185,55 @@ describe('Cache Components HTTP Access Fallback Prerender', () => {
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Bail out to client-side rendering: useSearchParams()
"Error: Route "/not-found/[slug]": Next.js encountered uncached or runtime data during prerendering.
\`fetch(...)\`, \`cookies()\`, \`headers()\`, \`params\`, \`searchParams\`, or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered, blocking the page load and leading to a slower user experience.
Ways to fix this:
- Cache the data access with \`"use cache"\`
- Provide a placeholder with \`<Suspense fallback={...}>\` around the data access
- If the runtime data is \`params\` and they're known, prerender them with \`generateStaticParams\`
- Set \`export const instant = false\` to allow a blocking route
Learn more: https://nextjs.org/docs/messages/blocking-route
at a (<next-dist-dir>)
at b (<next-dist-dir>)
at c (<next-dist-dir>) {
reason: 'useSearchParams()',
digest: 'BAILOUT_TO_CLIENT_SIDE_RENDERING'
}
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 (<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 x (<next-dist-dir>)
at y (<next-dist-dir>)
at z (<next-dist-dir>)
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 body (<anonymous>)
at html (<anonymous>)
To get a more detailed stack trace and pinpoint the issue, try one of the following:
- Start the app in development mode by running \`next dev\`, then open "/not-found/[slug]" in your browser to investigate the error.
- Rerun the production build with \`next build --debug-prerender\` to generate better stack traces.
Error occurred prerendering page "/not-found/not-found". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /not-found/[slug]/page: /not-found/not-found, exiting the build."
`)
......@@ -203,7 +271,17 @@ describe('Cache Components HTTP Access Fallback Prerender', () => {
if (isTurbopack) {
if (isDebugPrerender) {
expect(output).toMatchInlineSnapshot(`
"Error: Bail out to client-side rendering: useSearchParams()
"Error: Route "/forbidden/[slug]": Next.js encountered uncached or runtime data during prerendering.
\`fetch(...)\`, \`cookies()\`, \`headers()\`, \`params\`, \`searchParams\`, or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered, blocking the page load and leading to a slower user experience.
Ways to fix this:
- Cache the data access with \`"use cache"\`
- Provide a placeholder with \`<Suspense fallback={...}>\` around the data access
- If the runtime data is \`params\` and they're known, prerender them with \`generateStaticParams\`
- Set \`export const instant = false\` to allow a blocking route
Learn more: https://nextjs.org/docs/messages/blocking-route
at Forbidden (app/forbidden/[slug]/forbidden.tsx:6:39)
4 |
5 | export default function Forbidden() {
......@@ -211,10 +289,8 @@ describe('Cache Components HTTP Access Fallback Prerender', () => {
| ^
7 |
8 | return <p>forbidden {searchParams.get('foo')}</p>
9 | } {
reason: 'useSearchParams()',
digest: 'BAILOUT_TO_CLIENT_SIDE_RENDERING'
}
9 | }
To debug the issue, start the app in development mode by running \`next dev\`, then open "/forbidden/[slug]" in your browser to investigate the error.
Error occurred prerendering page "/forbidden/forbidden". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on 1 path:
......@@ -222,18 +298,30 @@ describe('Cache Components HTTP Access Fallback Prerender', () => {
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Bail out to client-side rendering: useSearchParams()
"Error: Route "/forbidden/[slug]": Next.js encountered uncached or runtime data during prerendering.
\`fetch(...)\`, \`cookies()\`, \`headers()\`, \`params\`, \`searchParams\`, or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered, blocking the page load and leading to a slower user experience.
Ways to fix this:
- Cache the data access with \`"use cache"\`
- Provide a placeholder with \`<Suspense fallback={...}>\` around the data access
- If the runtime data is \`params\` and they're known, prerender them with \`generateStaticParams\`
- Set \`export const instant = false\` to allow a blocking route
Learn more: https://nextjs.org/docs/messages/blocking-route
at <unknown> (app/forbidden/[slug]/forbidden.tsx:6:24)
at body (<anonymous>)
at html (<anonymous>)
4 |
5 | export default function Forbidden() {
> 6 | const searchParams = useSearchParams()
| ^
7 |
8 | return <p>forbidden {searchParams.get('foo')}</p>
9 | } {
reason: 'useSearchParams()',
digest: 'BAILOUT_TO_CLIENT_SIDE_RENDERING'
}
9 | }
To get a more detailed stack trace and pinpoint the issue, try one of the following:
- Start the app in development mode by running \`next dev\`, then open "/forbidden/[slug]" in your browser to investigate the error.
- Rerun the production build with \`next build --debug-prerender\` to generate better stack traces.
Error occurred prerendering page "/forbidden/forbidden". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /forbidden/[slug]/page: /forbidden/forbidden, exiting the build."
`)
......@@ -241,20 +329,26 @@ describe('Cache Components HTTP Access Fallback Prerender', () => {
} else {
if (isDebugPrerender) {
expect(output).toMatchInlineSnapshot(`
"Error: Bail out to client-side rendering: useSearchParams()
at useDynamicSearchParams (webpack:///<next-src>)
at useSearchParams (webpack:///<next-src>)
"Error: Route "/forbidden/[slug]": Next.js encountered uncached or runtime data during prerendering.
\`fetch(...)\`, \`cookies()\`, \`headers()\`, \`params\`, \`searchParams\`, or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered, blocking the page load and leading to a slower user experience.
Ways to fix this:
- Cache the data access with \`"use cache"\`
- Provide a placeholder with \`<Suspense fallback={...}>\` around the data access
- If the runtime data is \`params\` and they're known, prerender them with \`generateStaticParams\`
- Set \`export const instant = false\` to allow a blocking route
Learn more: https://nextjs.org/docs/messages/blocking-route
at Forbidden (webpack:///app/forbidden/[slug]/forbidden.tsx:6:39)
707 | return
708 | }
> 709 | throw new BailoutToCSRError(expression)
4 |
5 | export default function Forbidden() {
> 6 | const searchParams = useSearchParams()
| ^
710 | }
711 | case 'prerender':
712 | case 'prerender-runtime': {
reason: 'useSearchParams()',
digest: 'BAILOUT_TO_CLIENT_SIDE_RENDERING'
}
7 |
8 | return <p>forbidden {searchParams.get('foo')}</p>
9 | }
To debug the issue, start the app in development mode by running \`next dev\`, then open "/forbidden/[slug]" in your browser to investigate the error.
Error occurred prerendering page "/forbidden/forbidden". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on 1 path:
......@@ -262,13 +356,55 @@ describe('Cache Components HTTP Access Fallback Prerender', () => {
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Bail out to client-side rendering: useSearchParams()
"Error: Route "/forbidden/[slug]": Next.js encountered uncached or runtime data during prerendering.
\`fetch(...)\`, \`cookies()\`, \`headers()\`, \`params\`, \`searchParams\`, or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered, blocking the page load and leading to a slower user experience.
Ways to fix this:
- Cache the data access with \`"use cache"\`
- Provide a placeholder with \`<Suspense fallback={...}>\` around the data access
- If the runtime data is \`params\` and they're known, prerender them with \`generateStaticParams\`
- Set \`export const instant = false\` to allow a blocking route
Learn more: https://nextjs.org/docs/messages/blocking-route
at a (<next-dist-dir>)
at b (<next-dist-dir>)
at c (<next-dist-dir>) {
reason: 'useSearchParams()',
digest: 'BAILOUT_TO_CLIENT_SIDE_RENDERING'
}
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 (<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 x (<next-dist-dir>)
at y (<next-dist-dir>)
at z (<next-dist-dir>)
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 body (<anonymous>)
at html (<anonymous>)
To get a more detailed stack trace and pinpoint the issue, try one of the following:
- Start the app in development mode by running \`next dev\`, then open "/forbidden/[slug]" in your browser to investigate the error.
- Rerun the production build with \`next build --debug-prerender\` to generate better stack traces.
Error occurred prerendering page "/forbidden/forbidden". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /forbidden/[slug]/page: /forbidden/forbidden, exiting the build."
`)
......@@ -306,7 +442,17 @@ describe('Cache Components HTTP Access Fallback Prerender', () => {
if (isTurbopack) {
if (isDebugPrerender) {
expect(output).toMatchInlineSnapshot(`
"Error: Bail out to client-side rendering: useSearchParams()
"Error: Route "/unauthorized/[slug]": Next.js encountered uncached or runtime data during prerendering.
\`fetch(...)\`, \`cookies()\`, \`headers()\`, \`params\`, \`searchParams\`, or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered, blocking the page load and leading to a slower user experience.
Ways to fix this:
- Cache the data access with \`"use cache"\`
- Provide a placeholder with \`<Suspense fallback={...}>\` around the data access
- If the runtime data is \`params\` and they're known, prerender them with \`generateStaticParams\`
- Set \`export const instant = false\` to allow a blocking route
Learn more: https://nextjs.org/docs/messages/blocking-route
at Unauthorized (app/unauthorized/[slug]/unauthorized.tsx:6:39)
4 |
5 | export default function Unauthorized() {
......@@ -314,10 +460,8 @@ describe('Cache Components HTTP Access Fallback Prerender', () => {
| ^
7 |
8 | return <p>unauthorized {searchParams.get('foo')}</p>
9 | } {
reason: 'useSearchParams()',
digest: 'BAILOUT_TO_CLIENT_SIDE_RENDERING'
}
9 | }
To debug the issue, start the app in development mode by running \`next dev\`, then open "/unauthorized/[slug]" in your browser to investigate the error.
Error occurred prerendering page "/unauthorized/unauthorized". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on 1 path:
......@@ -325,18 +469,30 @@ describe('Cache Components HTTP Access Fallback Prerender', () => {
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Bail out to client-side rendering: useSearchParams()
"Error: Route "/unauthorized/[slug]": Next.js encountered uncached or runtime data during prerendering.
\`fetch(...)\`, \`cookies()\`, \`headers()\`, \`params\`, \`searchParams\`, or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered, blocking the page load and leading to a slower user experience.
Ways to fix this:
- Cache the data access with \`"use cache"\`
- Provide a placeholder with \`<Suspense fallback={...}>\` around the data access
- If the runtime data is \`params\` and they're known, prerender them with \`generateStaticParams\`
- Set \`export const instant = false\` to allow a blocking route
Learn more: https://nextjs.org/docs/messages/blocking-route
at <unknown> (app/unauthorized/[slug]/unauthorized.tsx:6:24)
at body (<anonymous>)
at html (<anonymous>)
4 |
5 | export default function Unauthorized() {
> 6 | const searchParams = useSearchParams()
| ^
7 |
8 | return <p>unauthorized {searchParams.get('foo')}</p>
9 | } {
reason: 'useSearchParams()',
digest: 'BAILOUT_TO_CLIENT_SIDE_RENDERING'
}
9 | }
To get a more detailed stack trace and pinpoint the issue, try one of the following:
- Start the app in development mode by running \`next dev\`, then open "/unauthorized/[slug]" in your browser to investigate the error.
- Rerun the production build with \`next build --debug-prerender\` to generate better stack traces.
Error occurred prerendering page "/unauthorized/unauthorized". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /unauthorized/[slug]/page: /unauthorized/unauthorized, exiting the build."
`)
......@@ -344,20 +500,26 @@ describe('Cache Components HTTP Access Fallback Prerender', () => {
} else {
if (isDebugPrerender) {
expect(output).toMatchInlineSnapshot(`
"Error: Bail out to client-side rendering: useSearchParams()
at useDynamicSearchParams (webpack:///<next-src>)
at useSearchParams (webpack:///<next-src>)
"Error: Route "/unauthorized/[slug]": Next.js encountered uncached or runtime data during prerendering.
\`fetch(...)\`, \`cookies()\`, \`headers()\`, \`params\`, \`searchParams\`, or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered, blocking the page load and leading to a slower user experience.
Ways to fix this:
- Cache the data access with \`"use cache"\`
- Provide a placeholder with \`<Suspense fallback={...}>\` around the data access
- If the runtime data is \`params\` and they're known, prerender them with \`generateStaticParams\`
- Set \`export const instant = false\` to allow a blocking route
Learn more: https://nextjs.org/docs/messages/blocking-route
at Unauthorized (webpack:///app/unauthorized/[slug]/unauthorized.tsx:6:39)
707 | return
708 | }
> 709 | throw new BailoutToCSRError(expression)
4 |
5 | export default function Unauthorized() {
> 6 | const searchParams = useSearchParams()
| ^
710 | }
711 | case 'prerender':
712 | case 'prerender-runtime': {
reason: 'useSearchParams()',
digest: 'BAILOUT_TO_CLIENT_SIDE_RENDERING'
}
7 |
8 | return <p>unauthorized {searchParams.get('foo')}</p>
9 | }
To debug the issue, start the app in development mode by running \`next dev\`, then open "/unauthorized/[slug]" in your browser to investigate the error.
Error occurred prerendering page "/unauthorized/unauthorized". Read more: https://nextjs.org/docs/messages/prerender-error
> Export encountered errors on 1 path:
......@@ -365,13 +527,55 @@ describe('Cache Components HTTP Access Fallback Prerender', () => {
`)
} else {
expect(output).toMatchInlineSnapshot(`
"Error: Bail out to client-side rendering: useSearchParams()
"Error: Route "/unauthorized/[slug]": Next.js encountered uncached or runtime data during prerendering.
\`fetch(...)\`, \`cookies()\`, \`headers()\`, \`params\`, \`searchParams\`, or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered, blocking the page load and leading to a slower user experience.
Ways to fix this:
- Cache the data access with \`"use cache"\`
- Provide a placeholder with \`<Suspense fallback={...}>\` around the data access
- If the runtime data is \`params\` and they're known, prerender them with \`generateStaticParams\`
- Set \`export const instant = false\` to allow a blocking route
Learn more: https://nextjs.org/docs/messages/blocking-route
at a (<next-dist-dir>)
at b (<next-dist-dir>)
at c (<next-dist-dir>) {
reason: 'useSearchParams()',
digest: 'BAILOUT_TO_CLIENT_SIDE_RENDERING'
}
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 (<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 x (<next-dist-dir>)
at y (<next-dist-dir>)
at z (<next-dist-dir>)
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 body (<anonymous>)
at html (<anonymous>)
To get a more detailed stack trace and pinpoint the issue, try one of the following:
- Start the app in development mode by running \`next dev\`, then open "/unauthorized/[slug]" in your browser to investigate the error.
- Rerun the production build with \`next build --debug-prerender\` to generate better stack traces.
Error occurred prerendering page "/unauthorized/unauthorized". Read more: https://nextjs.org/docs/messages/prerender-error
Export encountered an error on /unauthorized/[slug]/page: /unauthorized/unauthorized, exiting the build."
`)
......
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