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