Unverified Commit 9741cb57 authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub

Revert "Prerender HTTP access fallbacks with Cache Components semantics" (#94018)

Reverts vercel/next.js#93988

This broke not-found handling for internal Vercel apps.
parent 1a1d1c97
...@@ -5603,15 +5603,6 @@ async function spawnStaticShellValidationInDev( ...@@ -5603,15 +5603,6 @@ async function spawnStaticShellValidationInDev(
* While it doesn't return a stream we want it to have identical * While it doesn't return a stream we want it to have identical
* prerender semantics to prerenderToStream and should update it * prerender semantics to prerenderToStream and should update it
* in conjunction with any changes to that function. * 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( async function spawnStaticShellValidationInDevImpl(
accumulatedChunksPromise: Promise<AccumulatedStreamChunks>, accumulatedChunksPromise: Promise<AccumulatedStreamChunks>,
...@@ -7322,9 +7313,8 @@ async function prerenderToStream( ...@@ -7322,9 +7313,8 @@ async function prerenderToStream(
let prerenderStore: PrerenderStore | null = null let prerenderStore: PrerenderStore | null = null
const prerenderWithCacheComponents = async ( try {
getPayload: () => Promise<InitialRSCPayload> if (cacheComponents) {
): Promise<PrerenderToStreamResult> => {
/** /**
* cacheComponents with PPR * cacheComponents with PPR
* *
...@@ -7406,7 +7396,10 @@ async function prerenderToStream( ...@@ -7406,7 +7396,10 @@ async function prerenderToStream(
// is if it completes in a microtask and that's likely very rare for any non-trivial app // is if it completes in a microtask and that's likely very rare for any non-trivial app
const initialServerPayload = await workUnitAsyncStorage.run( const initialServerPayload = await workUnitAsyncStorage.run(
initialServerPayloadPrerenderStore, initialServerPayloadPrerenderStore,
getPayload getRSCPayload,
tree,
ctx,
{ is404: res.statusCode === 404 }
) )
const initialServerPrerenderStore: PrerenderStore = (prerenderStore = { const initialServerPrerenderStore: PrerenderStore = (prerenderStore = {
...@@ -7683,7 +7676,10 @@ async function prerenderToStream( ...@@ -7683,7 +7676,10 @@ async function prerenderToStream(
const finalAttemptRSCPayload = await workUnitAsyncStorage.run( const finalAttemptRSCPayload = await workUnitAsyncStorage.run(
finalServerPayloadPrerenderStore, finalServerPayloadPrerenderStore,
getPayload getRSCPayload,
tree,
ctx,
{ is404: res.statusCode === 404 }
) )
let staleTimeIterable: StaleTimeIterable | undefined let staleTimeIterable: StaleTimeIterable | undefined
...@@ -7836,7 +7832,8 @@ async function prerenderToStream( ...@@ -7836,7 +7832,8 @@ async function prerenderToStream(
const finalClientOnHeaders = createOnHeadersCallback(appendHeader) const finalClientOnHeaders = createOnHeadersCallback(appendHeader)
let { prelude: unprocessedPrelude, postponed } = await runInSequentialTasks( let { prelude: unprocessedPrelude, postponed } =
await runInSequentialTasks(
() => { () => {
const pendingFinalClientResult = workUnitAsyncStorage.run( const pendingFinalClientResult = workUnitAsyncStorage.run(
finalClientPrerenderStore, finalClientPrerenderStore,
...@@ -7858,8 +7855,9 @@ async function prerenderToStream( ...@@ -7858,8 +7855,9 @@ async function prerenderToStream(
isPrerenderInterruptedError(err) || isPrerenderInterruptedError(err) ||
finalClientReactController.signal.aborted finalClientReactController.signal.aborted
) { ) {
const componentStack: string | undefined = (errorInfo as any) const componentStack: string | undefined = (
.componentStack errorInfo as any
).componentStack
if (typeof componentStack === 'string') { if (typeof componentStack === 'string') {
trackAllowedDynamicAccess( trackAllowedDynamicAccess(
workStore, workStore,
...@@ -8094,13 +8092,6 @@ async function prerenderToStream( ...@@ -8094,13 +8092,6 @@ async function prerenderToStream(
), ),
} }
} }
}
try {
if (cacheComponents) {
return await prerenderWithCacheComponents(() =>
getRSCPayload(tree, ctx, { is404: res.statusCode === 404 })
)
} else if (experimental.isRoutePPREnabled) { } else if (experimental.isRoutePPREnabled) {
// We're statically generating with PPR and need to do dynamic tracking // We're statically generating with PPR and need to do dynamic tracking
let dynamicTracking = createDynamicTrackingState(isDebugDynamicAccesses) let dynamicTracking = createDynamicTrackingState(isDebugDynamicAccesses)
...@@ -8500,59 +8491,6 @@ async function prerenderToStream( ...@@ -8500,59 +8491,6 @@ async function prerenderToStream(
metadata.statusCode = res.statusCode 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( const [errorPreinitScripts, errorBootstrapScript] = getRequiredScripts(
buildManifest, buildManifest,
assetPrefix, assetPrefix,
...@@ -8582,8 +8520,37 @@ async function prerenderToStream( ...@@ -8582,8 +8520,37 @@ async function prerenderToStream(
: INFINITE_CACHE, : INFINITE_CACHE,
tags: [...(prerenderStore?.tags || implicitTags.tags)], 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
)
const errorRSCPayload = await workUnitAsyncStorage.run( if (boundaryTree) {
prerenderHTTPError = {
boundaryTree,
triggeredStatus,
}
}
}
const errorRSCPayload = prerenderHTTPError
? await workUnitAsyncStorage.run(
prerenderLegacyStore,
getRSCPayload,
tree,
ctx,
{
is404: errorType === 'not-found',
prerenderHTTPError,
}
)
: await workUnitAsyncStorage.run(
prerenderLegacyStore, prerenderLegacyStore,
getErrorRSCPayload, getErrorRSCPayload,
tree, tree,
...@@ -8592,7 +8559,7 @@ async function prerenderToStream( ...@@ -8592,7 +8559,7 @@ async function prerenderToStream(
errorType errorType
) )
const errorServerStream = workUnitAsyncStorage.run( const errorServerStreamRaw = workUnitAsyncStorage.run(
prerenderLegacyStore, prerenderLegacyStore,
renderFlightStream, renderFlightStream,
ComponentMod, ComponentMod,
...@@ -8604,6 +8571,19 @@ async function prerenderToStream( ...@@ -8604,6 +8571,19 @@ 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 { try {
const { stream: errorHtmlStream } = await workUnitAsyncStorage.run( const { stream: errorHtmlStream } = await workUnitAsyncStorage.run(
prerenderLegacyStore, prerenderLegacyStore,
...@@ -8624,10 +8604,15 @@ async function prerenderToStream( ...@@ -8624,10 +8604,15 @@ async function prerenderToStream(
{ waitForAllReady: true } { waitForAllReady: true }
) )
const resolvedFlightResult = errorFlightResultPromise
? await errorFlightResultPromise
: reactServerPrerenderResult
if (errorFlightResultPromise) {
reactServerPrerenderResult.consume()
}
if (shouldGenerateStaticFlightData(workStore)) { if (shouldGenerateStaticFlightData(workStore)) {
const flightData = await streamToBuffer( const flightData = await streamToBuffer(resolvedFlightResult.asStream())
reactServerPrerenderResult.asStream()
)
metadata.flightData = flightData metadata.flightData = flightData
await collectSegmentData( await collectSegmentData(
flightData, flightData,
...@@ -8639,12 +8624,14 @@ async function prerenderToStream( ...@@ -8639,12 +8624,14 @@ async function prerenderToStream(
) )
} }
const flightStream = resolvedFlightResult.consumeAsStream()
return { return {
digestErrorsMap: reactServerErrorsByDigest, digestErrorsMap: reactServerErrorsByDigest,
ssrErrors: allCapturedErrors, ssrErrors: allCapturedErrors,
stream: await continueFizzStream(errorHtmlStream, { stream: await continueFizzStream(errorHtmlStream, {
inlinedDataStream: createInlinedDataStream( inlinedDataStream: createInlinedDataStream(
reactServerPrerenderResult.consumeAsStream(), flightStream,
nonce, nonce,
formState formState
), ),
......
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