Use structural React keys during server rendering (#98944)
## Summary Use structural React keys during server rendering so an HTML prerender can resume without rewriting React's postponed state when route params become known. Browser keys and router-cache identity are unchanged. For example, `/products/[slug]` previously prerendered layout boundaries with a key containing an opaque slug placeholder. Resuming `/products/shoe` produced a different key, so Next.js substituted `shoe` into the serialized React state before handing it back to React. Both server passes now use `slug|d`. The browser still uses `slug|shoe|d`, preserving template remounts and back/forward state behavior. The server only renders the active entry at each layout-router position, so it does not need parameter values to distinguish cached browser entries. React keys are not embedded in the HTML; hydration derives its concrete keys from the request's route state. - Use segment name/type for server layout keys and structural route paths for the server head key. Server keys always omit search params. The existing browser-module variant mechanism selects the concrete key implementation for browser bundles in both Webpack and Turbopack. - Remove placeholder substitution and the request-params argument from postponed-state parsing. Persist only fallback param names for render staging; React's postponed state no longer needs to be searched or rewritten. - Simplify the remaining opaque fallback map to param name → placeholder. Its dynamic-param type slot is unused after removing interpolation. Parameter wrappers still control suspension; this does not make unknown params available to application code. - Test server and browser keys directly, including catch-all/intercepted segments and search params. Update the action-only resume fixture's single assertion on the resume-metadata format so its three cases reach their behavioral checks for action execution, revalidation, and `notFound()` with names-only metadata. This refactor is independently landable against `canary` and is now the base of the parameter-matching stack: #98944 → #98891 → #98892 → #98893 → #97393. It supersedes #98890. It retains internal opaque placeholders but removes their role in matching React's postponed state. No new integration fixtures are needed. ## Verification Latest cleanup: - 126 focused unit tests and 4 snapshots pass in both default and Cache Components/Webpack configurations. - 34 production Webpack tests pass across `fallback-shells`, `partial-fallback-shell-upgrade`, `action-only-fallback-resume-data-cache`, and `resuming-head-runtime-search-param`; 4 existing tests remain skipped. The three action-only resume cases now reach and pass their behavioral assertions. Earlier commits also passed existing production and dev Webpack coverage for back/forward state, template remounts, base-path params, nested/parallel/intercepted routes, form-state hydration, and standalone/edge output. A reviewer verified this head under Turbopack using a native binary built from the same commit: a broader unit selection passed (144 tests, the focused set above plus the remaining router-reducer suites), the `packages/next` type check was clean, and 33 production e2e tests passed across `fallback-shells`, `partial-fallback-shell-upgrade`, and `action-only-fallback-resume-data-cache`. <!-- NEXT_JS_LLM -->
Showing
This diff is collapsed.
Please
register
or
sign in
to comment