Unverified Commit e73504e9 authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub

Pass fallback params to the dev validation worker as maps (#96210)

The dev validation snapshot flattened both fallback param sets into
arrays of entries before handing them to the worker, and the worker
rebuilt a `Map` from each one on the other side. Neither step is needed,
because the structured clone that carries the snapshot across the
`worker_threads` boundary supports `Map` natively, so the maps can
travel as they are. Dropping the conversion on both ends also lets the
two snapshot fields be typed as `OpaqueFallbackRouteParams` directly,
and it makes them consistent with `rootParams` and `implicitTags`, which
the snapshot already passes through untouched.

The neighbouring `headers` spread stays as it is, because `Headers` is
not a structured-cloneable type and those entries genuinely do have to
be materialized before the snapshot is sent.
parent dcf242a1
...@@ -6302,20 +6302,14 @@ export async function runValidationInDevFromSnapshot( ...@@ -6302,20 +6302,14 @@ export async function runValidationInDevFromSnapshot(
installGlobalModuleLoadingHandlers(componentMod, true, false) installGlobalModuleLoadingHandlers(componentMod, true, false)
} }
// The request's fallback params reproduce `ctx.getDynamicParamFromSegment` // `requestFallbackRouteParams` reproduces `ctx.getDynamicParamFromSegment`
// exactly, so the depth-loop segment keys match the seed render's Flight. The // exactly, so the depth-loop segment keys match the seed render's Flight.
// validation set (below) is separate and only marks params unknown in the // `fallbackRouteParams` is separate and only marks params unknown in the
// prerender stores. // prerender stores.
// //
// TODO: Those two fallback params sets are very confusing in the whole code // TODO: Those two fallback params sets are very confusing in the whole code
// base. We should maybe refactor this to make their different roles clearer. // base. We should maybe refactor this to make their different roles clearer.
const requestFallbackRouteParams = message.requestFallbackRouteParams const { requestFallbackRouteParams, fallbackRouteParams } = message
? new Map(message.requestFallbackRouteParams)
: null
const fallbackRouteParams = message.fallbackRouteParams
? new Map(message.fallbackRouteParams)
: null
const getDynamicParamFromSegment = makeGetDynamicParamFromSegment( const getDynamicParamFromSegment = makeGetDynamicParamFromSegment(
message.interpolatedParams, message.interpolatedParams,
......
import type { Params } from '../request/params' import type { Params } from '../request/params'
import type { OpaqueFallbackRouteParamEntries } from '../request/fallback-params' import type { OpaqueFallbackRouteParams } from '../request/fallback-params'
import type { NextParsedUrlQuery } from '../request-meta' import type { NextParsedUrlQuery } from '../request-meta'
import type { PrefetchingMode } from './app-render' import type { PrefetchingMode } from './app-render'
import type { NextConfigComplete, ValidationLevel } from '../config-shared' import type { NextConfigComplete, ValidationLevel } from '../config-shared'
...@@ -80,14 +80,13 @@ export interface DevValidationSnapshot { ...@@ -80,14 +80,13 @@ export interface DevValidationSnapshot {
// closed over. The worker rebuilds `getDynamicParamFromSegment` from these // closed over. The worker rebuilds `getDynamicParamFromSegment` from these
// (with `interpolatedParams` and `optimisticRouting`), so the depth-loop // (with `interpolatedParams` and `optimisticRouting`), so the depth-loop
// segment keys match the seed render's Flight. It is null for a request whose // segment keys match the seed render's Flight. It is null for a request whose
// params all resolve to concrete values. Carried as map entries (like // params all resolve to concrete values.
// `fallbackRouteParams`) so both survive structured-clone transport. requestFallbackRouteParams: OpaqueFallbackRouteParams | null
requestFallbackRouteParams: OpaqueFallbackRouteParamEntries | null
// The validation fallback params, passed to `runValidationInDev` and its // The validation fallback params, passed to `runValidationInDev` and its
// prerender stores. They mark params unknown so that accessing one during the // prerender stores. They mark params unknown so that accessing one during the
// simulated prefetch is treated as dynamic. This set may include params that // simulated prefetch is treated as dynamic. This set may include params that
// `requestFallbackRouteParams` does not. // `requestFallbackRouteParams` does not.
fallbackRouteParams: OpaqueFallbackRouteParamEntries | null fallbackRouteParams: OpaqueFallbackRouteParams | null
optimisticRouting: boolean optimisticRouting: boolean
forceStatic: boolean | undefined forceStatic: boolean | undefined
validationLevel: ValidationLevel validationLevel: ValidationLevel
......
...@@ -78,12 +78,8 @@ export async function buildDevValidationSnapshot( ...@@ -78,12 +78,8 @@ export async function buildDevValidationSnapshot(
hmrRefreshHash: requestStore.hmrRefreshHash, hmrRefreshHash: requestStore.hmrRefreshHash,
}, },
interpolatedParams: ctx.interpolatedParams, interpolatedParams: ctx.interpolatedParams,
requestFallbackRouteParams: ctx.fallbackRouteParams requestFallbackRouteParams: ctx.fallbackRouteParams,
? [...ctx.fallbackRouteParams.entries()] fallbackRouteParams,
: null,
fallbackRouteParams: fallbackRouteParams
? [...fallbackRouteParams.entries()]
: null,
optimisticRouting: ctx.renderOpts.experimental.optimisticRouting, optimisticRouting: ctx.renderOpts.experimental.optimisticRouting,
forceStatic: ctx.workStore.forceStatic, forceStatic: ctx.workStore.forceStatic,
validationLevel: ctx.workStore.validationLevel, validationLevel: ctx.workStore.validationLevel,
......
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