Unverified Commit 589aae73 authored by Jan Kassens's avatar Jan Kassens Committed by GitHub

Pass staged fallback params directly to adapter renders (#100456)

# Jan's notes

After this, there's only one place left that writes
`stagedFallbackParams` to the request params object, but that appears to
be in the adapter boundary and I'm not sure that would be a breaking
change.

# AI

## Summary

Pass staged fallback params explicitly to each `doRender` invocation,
removing the handler's request-metadata writes and rereads. Each render
now owns its staging selection, including debug shells, background shell
upgrades, and resumes.

Retain the dev metadata handoff from `base-server`, captured once at the
adapter boundary. Preserve placeholder map identity and the precedence
of masks recorded in postponed state.

## Verification

- `pnpm test-dev-turbo` and `pnpm test-start-turbo`:
instant-navigation-testing-api, instant-validation-static-shells (both
variants), fallback-shells, and ppr-root-param-fallback.
- `pnpm test-start-turbo`: partial-fallback-shell-upgrade and
partial-fallback-root-blocking.
- `pnpm test-dev-webpack` and `pnpm test-start-webpack`:
instant-navigation-testing-api.
- Postponed-state and fallback-params unit tests.
- 262 tests passed across 16 suites; 12 existing skips.

<!-- NEXT_JS_LLM -->
parent 4007b6bc
......@@ -285,6 +285,11 @@ export function createAppPageEntrypoint({
requestSpan: Span | undefined,
requestRootSpan: Span | undefined
) {
// Dev passes the selected shell's staged params from base-server. Each
// render selects its own map without changing this adapter input.
const incomingStagedFallbackParams =
getRequestMeta(req, 'stagedFallbackParams') ?? null
const prepareResult = await routeModule.prepare(req, res, {
srcPage,
multiZoneDraftMode,
......@@ -903,6 +908,7 @@ export function createAppPageEntrypoint({
span,
postponed,
fallbackRouteParams,
stagedFallbackParams,
renderOperation,
allowEmptyStaticShell,
}: {
......@@ -920,6 +926,11 @@ export function createAppPageEntrypoint({
*/
fallbackRouteParams: OpaqueFallbackRouteParams | null
/**
* Defer access to these params while retaining their request values.
*/
stagedFallbackParams: OpaqueFallbackRouteParams | null
renderOperation: AppPageRenderOperation
}): Promise<ResponseCacheEntry | PrerenderFailure> => {
// A static page may have stripped Flight headers before reaching this
......@@ -955,8 +966,7 @@ export function createAppPageEntrypoint({
},
dev,
fallbackRouteParams,
stagedFallbackParams:
getRequestMeta(req, 'stagedFallbackParams') ?? null,
stagedFallbackParams,
renderOpts: {
App: () => null,
Document: () => null,
......@@ -1362,11 +1372,6 @@ export function createAppPageEntrypoint({
}
}
// Debug rendering stages the params of the selected source shell.
if (isDebugStaticShell) {
addRequestMeta(req, 'stagedFallbackParams', fallbackRouteParams)
}
// We use the response cache here to handle the revalidation and
// management of the fallback shell.
const fallbackResponse = await routeModule.handleResponse({
......@@ -1389,6 +1394,10 @@ export function createAppPageEntrypoint({
// the background path below will complete the shell into a
// more specific cache entry for later requests.
fallbackRouteParams,
// Debug rendering stages the selected source shell.
stagedFallbackParams: isDebugStaticShell
? fallbackRouteParams
: incomingStagedFallbackParams,
renderOperation: 'prerender',
allowEmptyStaticShell: isInstantNavigationTest || undefined,
}),
......@@ -1448,6 +1457,7 @@ export function createAppPageEntrypoint({
remainingFallbackRouteParams
)
: null,
stagedFallbackParams: incomingStagedFallbackParams,
renderOperation: 'prerender',
})
},
......@@ -1690,11 +1700,11 @@ export function createAppPageEntrypoint({
// Staging defers params without replacing their values with opaque
// placeholders. A resumed render reads the selected artifact's mask
// from its postponed state.
let stagedFallbackParams = incomingStagedFallbackParams
if (
(isProduction || isDebugStaticShell) &&
nextConfig.cacheComponents
) {
let stagedFallbackParams: OpaqueFallbackRouteParams | null
if (hasPlaceholderFallbackRouteParams) {
stagedFallbackParams = createOpaqueFallbackRouteParams(
placeholderFallbackRouteParams
......@@ -1714,8 +1724,6 @@ export function createAppPageEntrypoint({
} else {
stagedFallbackParams = null
}
addRequestMeta(req, 'stagedFallbackParams', stagedFallbackParams)
}
// Forced static and debug renders are prerenders even when the
......@@ -1730,6 +1738,7 @@ export function createAppPageEntrypoint({
span,
postponed,
fallbackRouteParams,
stagedFallbackParams,
renderOperation: isRequestSpecificRender ? 'render' : 'prerender',
allowEmptyStaticShell: isInstantNavigationTest || undefined,
})
......@@ -1779,15 +1788,12 @@ export function createAppPageEntrypoint({
const transformer = new TransformStream<Uint8Array, Uint8Array>()
body.push(transformer.readable)
// This metadata supplies fallback params when the saved state does not
// record them. App-render uses the saved state's own set when present.
if (nextConfig.cacheComponents && prerenderInfo?.fallbackRouteParams) {
addRequestMeta(
req,
'stagedFallbackParams',
createOpaqueFallbackRouteParams(prerenderInfo.fallbackRouteParams)
)
}
// Supply fallback params when the saved state does not record them.
// App-render uses the saved state's own set when present.
const stagedFallbackParams =
nextConfig.cacheComponents && prerenderInfo?.fallbackRouteParams
? createOpaqueFallbackRouteParams(prerenderInfo.fallbackRouteParams)
: incomingStagedFallbackParams
// Start the resume without awaiting it. The response consumes the
// continuation stream attached above.
......@@ -1797,6 +1803,7 @@ export function createAppPageEntrypoint({
// The resume retains concrete param values; staging only defers
// access.
fallbackRouteParams: null,
stagedFallbackParams,
renderOperation: 'render',
})
.then(async (result) => {
......
......@@ -323,6 +323,10 @@ export interface RequestMeta {
minimalMode?: boolean
/**
* Dev passes the selected shell's staged params from base-server to the App
* Page handler here. The handler captures this input once and passes an
* explicit map to each render instead of updating this metadata.
*
* Staged renders defer these route params until after the static stage. They
* keep their concrete request values instead of replacing them with
* placeholders. Dev static-shell validation uses the same set for the
......@@ -333,8 +337,8 @@ export interface RequestMeta {
* - A layout's `params` containing only `top` can resolve statically.
* - A page's `params` containing `bottom` waits until after the static stage.
*
* A set recorded in postponed state overrides this metadata on a resume,
* including an explicitly empty set.
* A mask recorded in postponed state overrides the supplied map on a resume,
* including an explicitly empty set or null.
*/
stagedFallbackParams?: OpaqueFallbackRouteParams | null
......
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