Unverified Commit b087b286 authored by Jan Kassens's avatar Jan Kassens Committed by GitHub

Pass staged fallback params into App rendering (#100408)

Replaces #100329 after reordering the stack. GitHub automatically marked
the original PR as merged into its previous stack parent; it was not
merged into canary.

## Summary

Continue decoupling App Router rendering from incoming request objects
by passing `stagedFallbackParams` as an explicit input from the handler
boundary. Keep the existing placeholder map and postponed-state
precedence for staged rendering and dev validation. Edge and export
supply `null`.

This removes the last request-metadata lookup from `app-render.tsx`. A
scoped lint restriction prevents value imports from `request-meta` while
allowing its types. Existing adapter metadata writes are unchanged.

Stacked on #100327.

## Verification

- Cache Components regression suites in Turbopack dev: instant
navigation, static-shell validation (including partial prefetching), and
blocking/sync-IO validation.
- Production suites with Turbopack and Webpack: fallback shells, partial
shell upgrades, blocking root params, root-param fallback, and
static-shell validation (including partial prefetching).
- Verified the lint guard rejects aliased value imports and permits type
imports.

<!-- NEXT_JS_LLM -->
parent 8bb7d47f
......@@ -470,6 +470,23 @@ export default defineConfig([
],
},
},
{
files: ['packages/next/src/server/app-render/app-render.tsx'],
rules: {
'@typescript-eslint/no-restricted-imports': [
'error',
{
patterns: [
{
group: ['**/request-meta'],
allowTypeImports: true,
message: 'Pass request metadata through explicit render inputs.',
},
],
},
],
},
},
{
files: ['examples/**/*'],
linterOptions: {
......
......@@ -913,6 +913,8 @@ export function createAppPageEntrypoint({
},
dev,
fallbackRouteParams,
stagedFallbackParams:
getRequestMeta(req, 'stagedFallbackParams') ?? null,
renderOpts: {
App: () => null,
Document: () => null,
......
......@@ -137,6 +137,7 @@ async function requestHandler(
clientAssetToken,
},
fallbackRouteParams: null,
stagedFallbackParams: null,
renderOpts: {
App: () => null,
......
......@@ -107,7 +107,8 @@ export async function exportAppPage(
sharedContext,
routeMatch,
parsedRequestHeaders,
getServerActionRequestMetadata(nextReq)
getServerActionRequestMetadata(nextReq),
null // stagedFallbackParams
)
if ('error' in result) {
......
......@@ -296,7 +296,6 @@ import {
import { isReactLargeShellError } from './react-large-shell-error'
import type { GlobalErrorComponent } from '../../client/components/builtin/global-error'
import { normalizeConventionFilePath } from './segment-explorer-path'
import { getRequestMeta } from '../request-meta'
import { htmlEscapeJsonString } from '../../shared/lib/htmlescape'
import {
getDynamicParam,
......@@ -2938,7 +2937,8 @@ async function renderAppPage(
serverActionRequestMetadata,
}: PreparedAppPageRender,
postponedState: PostponedState | null,
dev: DevRenderContext | undefined
dev: DevRenderContext | undefined,
stagedFallbackParams: OpaqueFallbackRouteParams | null
) {
const {
res,
......@@ -2969,8 +2969,6 @@ async function renderAppPage(
const rootParams = getRootParams(loaderTree, ctx.getDynamicParamFromSegment)
// Keep the placeholder map for dev's separate prerender validation. The
// request store only needs names to defer params during a staged render.
const stagedFallbackParams =
getRequestMeta(req, 'stagedFallbackParams') ?? null
const stagedFallbackParamNames =
postponedState?.stagedFallbackParams !== undefined
? postponedState.stagedFallbackParams
......@@ -3235,7 +3233,8 @@ async function renderToHTMLOrFlightImpl(
sharedContext: AppSharedContext,
interpolatedParams: Params,
fallbackRouteParams: OpaqueFallbackRouteParams | null,
routeMatch: RouteMatch
routeMatch: RouteMatch,
stagedFallbackParams: OpaqueFallbackRouteParams | null
) {
if (renderOpts.ComponentMod.__next_app__) {
installGlobalModuleLoadingHandlers(
......@@ -3269,7 +3268,7 @@ async function renderToHTMLOrFlightImpl(
supportsPerSegmentPrefetching: renderOpts.cacheComponents,
}
)
return renderAppPage(prepared, postponedState, dev)
return renderAppPage(prepared, postponedState, dev, stagedFallbackParams)
}
async function prerenderToHTMLOrFlightImpl(
......@@ -3336,7 +3335,8 @@ export type AppPageRender = (
sharedContext: AppSharedContext,
routeMatch: RouteMatch,
parsedRequestHeaders: ParsedRequestHeaders,
serverActionRequestMetadata: ServerActionRequestMetadata
serverActionRequestMetadata: ServerActionRequestMetadata,
stagedFallbackParams: OpaqueFallbackRouteParams | null
) => Promise<RenderResult<AppPageRenderResultMetadata>>
export type AppPagePrerender = (
......@@ -3428,7 +3428,8 @@ export const renderToHTMLOrFlight: AppPageRender = (
sharedContext,
routeMatch,
parsedRequestHeaders,
serverActionRequestMetadata
serverActionRequestMetadata,
stagedFallbackParams
) => {
const { url, interpolatedParams, postponedState } = prepareAppPage(
serverActionRequestMetadata,
......@@ -3468,7 +3469,8 @@ export const renderToHTMLOrFlight: AppPageRender = (
sharedContext,
interpolatedParams,
fallbackRouteParams,
routeMatch
routeMatch,
stagedFallbackParams
)
}
......
......@@ -96,6 +96,9 @@ export interface AppPageRouteHandlerContext extends RouteModuleHandleContext {
routeMatch: RouteMatch
query: NextParsedUrlQuery
fallbackRouteParams: OpaqueFallbackRouteParams | null
// Defer access to these params while retaining their concrete request values.
// A resumed render prefers the mask recorded in its postponed state.
stagedFallbackParams: OpaqueFallbackRouteParams | null
renderOpts: RenderOpts
dev: DevRenderContext | undefined
parsedRequestHeaders: ParsedRequestHeaders
......@@ -199,7 +202,8 @@ export class AppPageRouteModule extends RouteModule<
context.sharedContext,
context.routeMatch,
context.parsedRequestHeaders,
context.serverActionRequestMetadata
context.serverActionRequestMetadata,
context.stagedFallbackParams
)
}
......@@ -220,7 +224,8 @@ export class AppPageRouteModule extends RouteModule<
context.sharedContext,
context.routeMatch,
context.parsedRequestHeaders,
context.serverActionRequestMetadata
context.serverActionRequestMetadata,
context.stagedFallbackParams
)
}
......
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