{"version":3,"sources":["../../../src/server/app-render/dev-validation-worker-globals.ts"],"sourcesContent":["import type { Params } from '../request/params'\nimport type { OpaqueFallbackRouteParams } from '../request/fallback-params'\nimport type { NextParsedUrlQuery } from '../request-meta'\nimport type { PrefetchingMode } from './app-render'\nimport type { NextConfigComplete, ValidationLevel } from '../config-shared'\nimport type { ImageConfigComplete } from '../../shared/lib/image-config'\nimport type { StageEndTimes } from './instant-validation/instant-validation'\n\n/**\n * Cross-module handoff for the dev validation worker (client-module warmup,\n * static-shell validation, and instant-config validation all run on it). A\n * symbol on `globalThis` decouples the dev-server entry point (which installs\n * the jest-worker pool) from the read site in `runDevValidationInBackground`\n * inside `app-render.tsx`, avoiding a direct import of dev-only pool code from\n * the render module. When the symbol is not set (e.g. because the feature flag\n * is disabled), `getDevValidationWorker()` returns undefined and the caller\n * runs validation in process instead.\n */\nconst SYMBOL: unique symbol = Symbol.for('next.dev.validationWorker')\n\n/**\n * Per-stage RSC chunks, the serializable form of `AccumulatedStreamChunks` that\n * the worker replays. No live streams cross the boundary.\n */\nexport interface SerializedAccumulatedChunks {\n  shellStaticChunks: Uint8Array[]\n  staticChunks: Uint8Array[]\n  shellRuntimeChunks: Uint8Array[]\n  runtimeChunks: Uint8Array[]\n  dynamicChunks: Uint8Array[]\n}\n\n/**\n * Serializable view of one validation input (the shape `DevValidationInputs`\n * carries), with the live streams already drained to chunks. The stage-end\n * timings are replayed into the per-depth Flight re-encodes so the worker\n * reconstructs the same partial-stage boundaries the main render observed.\n */\nexport interface SerializedValidationInputs {\n  accumulatedChunks: SerializedAccumulatedChunks\n  debugChunks: Uint8Array[] | null\n  startTime: number\n  stageEndTimes: StageEndTimes\n}\n\n/**\n * Serializable view of the request, rebuilt into a `RequestStore` on the worker\n * so `cookies()` / `headers()` / `draftMode()` behave as in the real render.\n */\nexport interface DevValidationRequestSnapshot {\n  headers: [string, string][]\n  urlPathname: string\n  urlSearch: string\n  rootParams: Params\n  isDraftMode: boolean\n  isHmrRefresh: boolean\n  hmrRefreshHash: string | undefined\n  requestStartTime: number\n}\n\n/**\n * Everything the worker needs to rebuild the render context and inputs and run\n * `runValidationInDev`. Built on the main thread from the settled render; the\n * pool augments it with install-time fields (`distDir`, `buildId`, …).\n */\nexport interface DevValidationSnapshot {\n  page: string\n  route: string\n  requestId: string\n  responseFinished: boolean\n  prefetchMode: PrefetchingMode\n  devRenderDidError: boolean\n  nonce: string | undefined\n  query: NextParsedUrlQuery\n  request: DevValidationRequestSnapshot\n  // The interpolated route params, the routing seed the worker rebuilds\n  // `getDynamicParamFromSegment` from (together with the fallback params\n  // below).\n  interpolatedParams: Params\n  // The request's fallback params, the set `ctx.getDynamicParamFromSegment`\n  // closed over. The worker rebuilds `getDynamicParamFromSegment` from these\n  // (with `interpolatedParams` and `optimisticRouting`), so the depth-loop\n  // segment keys match the seed render's Flight. It is null for a request whose\n  // params all resolve to concrete values.\n  requestFallbackRouteParams: OpaqueFallbackRouteParams | null\n  // The validation fallback params, passed to `runValidationInDev` and its\n  // prerender stores. They mark params unknown so that accessing one during the\n  // simulated prefetch is treated as dynamic. This set may include params that\n  // `requestFallbackRouteParams` does not.\n  fallbackRouteParams: OpaqueFallbackRouteParams | null\n  optimisticRouting: boolean\n  forceStatic: boolean | undefined\n  validationLevel: ValidationLevel\n  implicitTags: string[]\n  /**\n   * Pages whose client reference manifests supplied client references to the\n   * render being validated, beyond the validated route's own manifest (see\n   * `WorkStore.additionalClientReferenceManifestPages`). The worker registers\n   * these so the same references resolve in its thread. Empty for all but the\n   * rare renders that React's I/O tracking carries a reference into.\n   */\n  additionalClientReferenceManifestPages: string[]\n  isDebugChannelEnabled: boolean\n  renderOpts: {\n    images: ImageConfigComplete\n    allowEmptyStaticShell: boolean | undefined\n  }\n  instantInputs: SerializedValidationInputs | null\n  staticInputs: SerializedValidationInputs\n}\n\n/**\n * Install-time fields the dev server's worker pool augments the snapshot with\n * so the worker can reload the route (`distDir`; `page` comes from the\n * snapshot) and rebuild the work store (`buildId`, `deploymentId`, the config\n * slice).\n */\nexport interface DevValidationInstallFields {\n  distDir: string\n  buildId: string\n  deploymentId: string\n  nextConfigSerializable: {\n    httpAgentOptions: NextConfigComplete['httpAgentOptions']\n    cacheLifeProfiles: NextConfigComplete['cacheLife']\n    useCacheTimeout: number\n    staticPageGenerationTimeout: number\n  }\n}\n\n/**\n * The full message the worker receives and forwards into the in-bundle entry:\n * the main-thread snapshot plus the pool's install-time fields.\n */\nexport type DevValidationWorkerMessage = DevValidationSnapshot &\n  DevValidationInstallFields\n\n/**\n * The RSC-encoded `{ errors, errorCodes }` Flight chunks for the dev overlay,\n * or null when validation produced no errors or was aborted. The worker also\n * logs the errors to its own stderr (piped to the parent) with code frames.\n */\nexport type DevValidationWorkerResult = Uint8Array[] | null\n\n/**\n * Worker hook installed by the dev server. Given the render snapshot and the\n * validation abort signal, runs validation on a worker thread and resolves to\n * the validation error Flight chunks to deliver on the main thread. On an abort\n * the pool relays the aborted signal to the worker thread through a shared\n * flag, so the in-flight run aborts mid-run; validation always runs as a thread\n * (never a child process), which is what makes that cross-thread abort\n * possible.\n */\nexport type DevValidationWorker = (\n  snapshot: DevValidationSnapshot,\n  validationAbortSignal: AbortSignal\n) => Promise<DevValidationWorkerResult>\n\ninterface WorkerHolder {\n  [SYMBOL]?: DevValidationWorker\n}\n\nexport function setDevValidationWorker(\n  fn: DevValidationWorker | undefined\n): void {\n  ;(globalThis as WorkerHolder)[SYMBOL] = fn\n}\n\nexport function getDevValidationWorker(): DevValidationWorker | undefined {\n  return (globalThis as WorkerHolder)[SYMBOL]\n}\n"],"names":["getDevValidationWorker","setDevValidationWorker","SYMBOL","Symbol","for","fn","globalThis"],"mappings":";;;;;;;;;;;;;;;IAuKgBA,sBAAsB;eAAtBA;;IANAC,sBAAsB;eAAtBA;;;AAzJhB;;;;;;;;;CASC,GACD,MAAMC,SAAwBC,OAAOC,GAAG,CAAC;AA+IlC,SAASH,uBACdI,EAAmC;;IAEjCC,UAA2B,CAACJ,OAAO,GAAGG;AAC1C;AAEO,SAASL;IACd,OAAO,AAACM,UAA2B,CAACJ,OAAO;AAC7C","ignoreList":[0]}