Unverified Commit 8bb7d47f authored by Jan Kassens's avatar Jan Kassens Committed by GitHub

Capture initial HMR version in dev render context (#100407)

Replaces #100327 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 capturing the initial HMR version in `DevRenderContext` at the
handler boundary. Request rendering uses that captured value for the
existing inline bootstrap script. Prerendering never consumes the value,
so it no longer carries the field in its shared render context.

Stacked on #100323.

## Verification

- CSS startup-race suites passed in Turbopack dev (14 tests), covering
missed edits, the initial baseline, and CSP nonce reuse.
- The App startup-race suite's baseline check passed in Webpack dev and
Turbopack production, confirming the baseline remains absent there.

<!-- NEXT_JS_LLM -->
parent 78fe5180
...@@ -426,7 +426,6 @@ export type AppRenderContext = { ...@@ -426,7 +426,6 @@ export type AppRenderContext = {
assetPrefix: string assetPrefix: string
isNotFoundPath: boolean isNotFoundPath: boolean
nonce: string | undefined nonce: string | undefined
initialHmrVersion?: string
res: BaseNextResponse res: BaseNextResponse
/** /**
* For now, the implicit tags are common for the whole route. If we ever start * For now, the implicit tags are common for the whole route. If we ever start
...@@ -2746,7 +2745,6 @@ async function prepareAppPageRender( ...@@ -2746,7 +2745,6 @@ async function prepareAppPageRender(
) )
const ctx: AppRenderContext = { const ctx: AppRenderContext = {
initialHmrVersion: getRequestMeta(req, 'initialHmrVersion'),
componentMod: ComponentMod, componentMod: ComponentMod,
url, url,
renderOpts, renderOpts,
...@@ -3099,6 +3097,7 @@ async function renderAppPage( ...@@ -3099,6 +3097,7 @@ async function renderAppPage(
requestStore, requestStore,
res, res,
ctx, ctx,
dev,
notFoundLoaderTree, notFoundLoaderTree,
formState, formState,
postponedState, postponedState,
...@@ -3144,6 +3143,7 @@ async function renderAppPage( ...@@ -3144,6 +3143,7 @@ async function renderAppPage(
requestStore, requestStore,
res, res,
ctx, ctx,
dev,
loaderTree, loaderTree,
formState, formState,
postponedState, postponedState,
...@@ -3587,6 +3587,7 @@ async function renderToStream( ...@@ -3587,6 +3587,7 @@ async function renderToStream(
requestStore: RequestStore, requestStore: RequestStore,
res: BaseNextResponse, res: BaseNextResponse,
ctx: AppRenderContext, ctx: AppRenderContext,
devContext: DevRenderContext | undefined,
tree: LoaderTree, tree: LoaderTree,
formState: any, formState: any,
postponedState: PostponedState | null, postponedState: PostponedState | null,
...@@ -3677,7 +3678,7 @@ async function renderToStream( ...@@ -3677,7 +3678,7 @@ async function renderToStream(
bootstrapScriptContent = `self.__next_r=${JSON.stringify( bootstrapScriptContent = `self.__next_r=${JSON.stringify(
requestId ?? crypto.randomUUID() requestId ?? crypto.randomUUID()
)}` )}`
const initialHmrVersion = ctx.initialHmrVersion const initialHmrVersion = devContext?.initialHmrVersion
if (initialHmrVersion !== undefined) { if (initialHmrVersion !== undefined) {
// Only the dev server with Turbopack HMR supplies this captured baseline. // Only the dev server with Turbopack HMR supplies this captured baseline.
bootstrapScriptContent += `;var __nextHmrInitialVersion=${htmlEscapeJsonString( bootstrapScriptContent += `;var __nextHmrInitialVersion=${htmlEscapeJsonString(
......
...@@ -11,9 +11,11 @@ export function createDevRenderContext( ...@@ -11,9 +11,11 @@ export function createDevRenderContext(
return undefined return undefined
} }
const { serverComponentsHmrCache, hmrRefreshHash } = getRequestMeta(req) const { serverComponentsHmrCache, hmrRefreshHash, initialHmrVersion } =
getRequestMeta(req)
return { return {
serverComponentsHmrCache: serverComponentsHmrCache ?? hmrCacheFallback, serverComponentsHmrCache: serverComponentsHmrCache ?? hmrCacheFallback,
hmrRefreshHash, hmrRefreshHash,
initialHmrVersion,
} }
} }
...@@ -85,6 +85,7 @@ export type RouteMatch = { ...@@ -85,6 +85,7 @@ export type RouteMatch = {
export type DevRenderContext = { export type DevRenderContext = {
readonly serverComponentsHmrCache: ServerComponentsHmrCache | undefined readonly serverComponentsHmrCache: ServerComponentsHmrCache | undefined
readonly hmrRefreshHash: string | undefined readonly hmrRefreshHash: string | undefined
readonly initialHmrVersion: string | undefined
} }
export interface AppPageRouteHandlerContext extends RouteModuleHandleContext { export interface AppPageRouteHandlerContext extends RouteModuleHandleContext {
......
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