{"version":3,"sources":["../../../src/server/app-render/collect-segment-data.tsx"],"sourcesContent":["/* eslint-disable @next/internal/no-ambiguous-jsx -- Bundled in entry-base so it gets the right JSX runtime. */\nimport type {\n  CacheNodeSeedData,\n  FlightRouterState,\n  InitialRSCPayload,\n  DynamicParamTypesShort,\n  HeadData,\n  PrefetchHints,\n} from '../../shared/lib/app-router-types'\nimport { PrefetchHint } from '../../shared/lib/app-router-types'\nimport { readVaryParams } from '../../shared/lib/segment-cache/vary-params-decoding'\nimport { PAGE_SEGMENT_KEY } from '../../shared/lib/segment'\nimport type { ManifestNode } from '../../build/webpack/plugins/flight-manifest-plugin'\n\n// eslint-disable-next-line import/no-extraneous-dependencies\nimport { createFromReadableStream } from 'react-server-dom-webpack/client'\n// eslint-disable-next-line import/no-extraneous-dependencies\nimport { prerender } from 'react-server-dom-webpack/static'\n\nimport {\n  streamFromBuffer,\n  streamToBuffer,\n} from '../stream-utils/node-web-streams-helper'\nimport { waitAtLeastOneReactRenderTask } from '../../lib/scheduler'\nimport {\n  type SegmentRequestKey,\n  createSegmentRequestKeyPart,\n  appendSegmentRequestKeyPart,\n  ROOT_SEGMENT_REQUEST_KEY,\n  HEAD_REQUEST_KEY,\n} from '../../shared/lib/segment-cache/segment-value-encoding'\nimport { getDigestForWellKnownError } from './create-error-handler'\nimport {\n  Phase,\n  printDebugThrownValueForProspectiveRender,\n} from './prospective-render-utils'\nimport { workAsyncStorage } from './work-async-storage.external'\n\n// Contains metadata about the route tree. The client must fetch this before\n// it can fetch any actual segment data.\nexport type RootTreePrefetch = {\n  buildId?: string\n  tree: TreePrefetch\n  staleTime: number\n}\n\nexport type TreePrefetchParam = {\n  type: DynamicParamTypesShort\n  // When cacheComponents is enabled, this field is always null.\n  // Instead we parse the param on the client, allowing us to omit it from\n  // the prefetch response and increase its cacheability.\n  key: string | null\n  // Static sibling segments at the same URL level. Used by the client\n  // router to determine if a prefetch can be reused when navigating to\n  // a static sibling of a dynamic route. For example, if the route is\n  // /products/[id] and there's also /products/sale, then siblings\n  // would be ['sale']. null means the siblings are unknown (e.g. in\n  // webpack dev mode).\n  siblings: readonly string[] | null\n}\n\nexport type TreePrefetch = {\n  name: string\n  // Only present for parameterized (dynamic) segments.\n  param: TreePrefetchParam | null\n\n  // Child segments.\n  slots: null | {\n    [parallelRouteKey: string]: TreePrefetch\n  }\n\n  /** Bitmask of PrefetchHint flags for this segment and its subtree */\n  prefetchHints: number\n}\n\nexport type SegmentPrefetch = {\n  buildId?: string\n  rsc: React.ReactNode | null\n  isPartial: boolean\n  staleTime: number\n  /**\n   * The set of params that this segment's output depends on. Used by the client\n   * cache to determine which entries can be reused across different param\n   * values.\n   * - `null` means vary params were not tracked (conservative: assume all\n   *   params matter)\n   * - Empty set means no params were accessed (segment is reusable for any\n   *   param values)\n   */\n  varyParams: Set<string> | null\n}\n\n/**\n * A node in the inlined prefetch tree. Wraps a SegmentPrefetch with child\n * slots so all segments for a route can be bundled into a single response.\n *\n * This is a separate type from SegmentPrefetch because the inlined flow is\n * still gated behind a feature flag. Eventually inlining will always be\n * enabled, and the per-segment and inlined paths will merge.\n */\nexport type InlinedSegmentPrefetch = {\n  segment: SegmentPrefetch\n  slots: null | {\n    [parallelRouteKey: string]: InlinedSegmentPrefetch\n  }\n}\n\n/**\n * The response shape for the /_inlined prefetch endpoint. Contains all segment\n * data for a route bundled into a single tree structure, plus the head segment.\n */\nexport type InlinedPrefetchResponse = {\n  tree: InlinedSegmentPrefetch\n  head: SegmentPrefetch\n}\n\nconst filterStackFrame =\n  process.env.NODE_ENV !== 'production'\n    ? (require('../lib/source-maps') as typeof import('../lib/source-maps'))\n        .filterStackFrameDEV\n    : undefined\nconst findSourceMapURL =\n  process.env.NODE_ENV !== 'production'\n    ? (require('../lib/source-maps') as typeof import('../lib/source-maps'))\n        .findSourceMapURLDEV\n    : undefined\n\nfunction onSegmentPrerenderError(error: unknown) {\n  const digest = getDigestForWellKnownError(error)\n  if (digest) {\n    return digest\n  }\n  // We don't need to log the errors because we would have already done that\n  // when generating the original Flight stream for the whole page.\n  if (process.env.NEXT_DEBUG_BUILD || process.env.__NEXT_VERBOSE_LOGGING) {\n    const workStore = workAsyncStorage.getStore()\n    printDebugThrownValueForProspectiveRender(\n      error,\n      workStore?.route ?? 'unknown route',\n      Phase.SegmentCollection\n    )\n  }\n}\n\n/**\n * Extract the FlightRouterState, seed data, and head from a prerendered\n * InitialRSCPayload. Returns null if the payload doesn't match the expected\n * shape (single path with 3 elements).\n */\nfunction extractFlightData(initialRSCPayload: InitialRSCPayload): {\n  buildId: string | undefined\n  flightRouterState: FlightRouterState\n  seedData: CacheNodeSeedData\n  head: HeadData\n} | null {\n  const flightDataPaths = initialRSCPayload.f\n  // FlightDataPath is an unsound type, hence the additional checks.\n  if (flightDataPaths.length !== 1 && flightDataPaths[0].length !== 3) {\n    console.error(\n      'Internal Next.js error: InitialRSCPayload does not match the expected ' +\n        'shape for a prerendered page during segment prefetch generation.'\n    )\n    return null\n  }\n  return {\n    buildId: initialRSCPayload.b,\n    flightRouterState: flightDataPaths[0][0],\n    seedData: flightDataPaths[0][1],\n    head: flightDataPaths[0][2],\n  }\n}\n\nexport async function collectSegmentData(\n  isCacheComponentsEnabled: boolean,\n  fullPageDataBuffer: Buffer,\n  staleTime: number,\n  clientModules: ManifestNode,\n  serverConsumerManifest: any,\n  prefetchInlining: boolean,\n  hints: PrefetchHints | null\n): Promise<Map<SegmentRequestKey, Buffer>> {\n  // Traverse the router tree and generate a prefetch response for each segment.\n\n  // A mutable map to collect the results as we traverse the route tree.\n  const resultMap = new Map<SegmentRequestKey, Buffer>()\n\n  // Before we start, warm up the module cache by decoding the page data once.\n  // Then we can assume that any remaining async tasks that occur the next time\n  // are due to hanging promises caused by dynamic data access. Note we only\n  // have to do this once per page, not per individual segment.\n  //\n  try {\n    await createFromReadableStream(streamFromBuffer(fullPageDataBuffer), {\n      findSourceMapURL,\n      serverConsumerManifest,\n    })\n    await waitAtLeastOneReactRenderTask()\n  } catch {}\n\n  // Create an abort controller that we'll use to stop the stream.\n  const abortController = new AbortController()\n  const onCompletedProcessingRouteTree = async () => {\n    // Since all we're doing is decoding and re-encoding a cached prerender, if\n    // serializing the stream takes longer than a microtask, it must because of\n    // hanging promises caused by dynamic data.\n    await waitAtLeastOneReactRenderTask()\n    abortController.abort()\n  }\n\n  // Generate a stream for the route tree prefetch. While we're walking the\n  // tree, we'll also spawn additional tasks to generate the segment prefetches.\n  // The promises for these tasks are pushed to a mutable array that we will\n  // await once the route tree is fully rendered.\n  const segmentTasks: Array<Promise<[SegmentRequestKey, Buffer]>> = []\n  const { prelude: treeStream } = await prerender(\n    // RootTreePrefetch is not a valid return type for a React component, but\n    // we need to use a component so that when we decode the original stream\n    // inside of it, the side effects are transferred to the new stream.\n    // @ts-expect-error\n    <PrefetchTreeData\n      isClientParamParsingEnabled={isCacheComponentsEnabled}\n      fullPageDataBuffer={fullPageDataBuffer}\n      serverConsumerManifest={serverConsumerManifest}\n      clientModules={clientModules}\n      staleTime={staleTime}\n      segmentTasks={segmentTasks}\n      onCompletedProcessingRouteTree={onCompletedProcessingRouteTree}\n      prefetchInlining={prefetchInlining}\n      hints={hints}\n    />,\n    clientModules,\n    {\n      filterStackFrame,\n      signal: abortController.signal,\n      onError: onSegmentPrerenderError,\n    }\n  )\n\n  // Write the route tree to a special `/_tree` segment.\n  const treeBuffer = await streamToBuffer(treeStream)\n  resultMap.set('/_tree' as SegmentRequestKey, treeBuffer)\n\n  // Also output the entire full page data response\n  resultMap.set('/_full' as SegmentRequestKey, fullPageDataBuffer)\n\n  // Now that we've finished rendering the route tree, all the segment tasks\n  // should have been spawned. Await them in parallel and write the segment\n  // prefetches to the result map.\n  for (const [segmentPath, buffer] of await Promise.all(segmentTasks)) {\n    resultMap.set(segmentPath, buffer)\n  }\n\n  return resultMap\n}\n\n/**\n * Compute prefetch hints for a route by measuring segment sizes and deciding\n * which segments should be inlined. Only runs at build time. The results are\n * written to prefetch-hints.json and loaded at server startup.\n *\n * This is a separate pass from collectSegmentData so that the inlining\n * decisions can be fed back into collectSegmentData to control which segments\n * are output as separate entries vs. inlined into their parent.\n */\nexport async function collectPrefetchHints(\n  fullPageDataBuffer: Buffer,\n  staleTime: number,\n  clientModules: ManifestNode,\n  serverConsumerManifest: any,\n  maxSize: number,\n  maxBundleSize: number\n): Promise<PrefetchHints> {\n  // Warm up the module cache, same as collectSegmentData.\n  try {\n    await createFromReadableStream(streamFromBuffer(fullPageDataBuffer), {\n      findSourceMapURL,\n      serverConsumerManifest,\n    })\n    await waitAtLeastOneReactRenderTask()\n  } catch {}\n\n  // Decode the Flight data to walk the route tree.\n  const initialRSCPayload: InitialRSCPayload = await createFromReadableStream(\n    createUnclosingPrefetchStream(streamFromBuffer(fullPageDataBuffer)),\n    {\n      findSourceMapURL,\n      serverConsumerManifest,\n    }\n  )\n\n  const flightData = extractFlightData(initialRSCPayload)\n  if (flightData === null) {\n    return { hints: 0, slots: null }\n  }\n  const { buildId, flightRouterState, seedData, head } = flightData\n\n  // Measure the head (metadata/viewport) gzip size so the main traversal\n  // can decide whether to inline it into a page's bundle.\n  const headVaryParamsThenable = initialRSCPayload.h\n  const headVaryParams =\n    headVaryParamsThenable !== null\n      ? readVaryParams(headVaryParamsThenable)\n      : null\n\n  const [, headBuffer] = await renderSegmentPrefetch(\n    buildId,\n    staleTime,\n    head,\n    HEAD_REQUEST_KEY,\n    headVaryParams,\n    clientModules\n  )\n  const headGzipSize = await getGzipSize(headBuffer)\n\n  // Mutable accumulator: the first page leaf that can fit the head sets\n  // this to true. Once set, subsequent leaves skip the check.\n  const headInlineState = { inlined: false }\n\n  // Walk the tree with the parent-first, child-decides algorithm.\n  const { node } = await collectPrefetchHintsImpl(\n    flightRouterState,\n    buildId,\n    staleTime,\n    seedData,\n    clientModules,\n    ROOT_SEGMENT_REQUEST_KEY,\n    null, // root has no parent to inline\n    maxSize,\n    maxBundleSize,\n    headGzipSize,\n    headInlineState\n  )\n\n  if (!headInlineState.inlined) {\n    // No page could accept the head. Set HeadOutlined on the root so the\n    // client knows to fetch the head separately.\n    node.hints |= PrefetchHint.HeadOutlined\n  }\n\n  return node\n}\n\n// Measure a segment's gzip size and decide whether it should be inlined.\n//\n// These hints are computed once during build and never change for the\n// lifetime of that deployment. The client can assume that hints delivered as\n// part of one request will be the same during a subsequent request, given\n// the same build ID. There's no skew to worry about as long as the build\n// itself is consistent.\n//\n// In the Segment Cache, we split page prefetches into multiple requests so\n// that each one can be cached and deduped independently. However, some\n// segments are small enough that the potential caching benefits are not worth\n// the additional network overhead. For these, we inline a parent's data into\n// one of its children's responses, avoiding a separate request. The parent\n// is inlined into the child (not the other way around) because the parent's\n// response is more likely to be shared across multiple pages. The child's\n// response is already page-specific, so adding the parent's data there\n// doesn't meaningfully reduce deduplication. It's similar to how JS bundlers\n// decide whether to inline a module into a chunk.\n//\n// The algorithm is parent-first, child-decides: the parent measures itself\n// and passes its gzip size down. Each child decides whether to accept. A\n// child rejects if the parent exceeds maxSize or if accepting would push\n// the cumulative inlined bytes past maxBundleSize. This produces\n// both ParentInlinedIntoSelf (on the child) and InlinedIntoChild (on the\n// parent) in a single pass.\nasync function collectPrefetchHintsImpl(\n  route: FlightRouterState,\n  buildId: string | undefined,\n  staleTime: number,\n  seedData: CacheNodeSeedData | null,\n  clientModules: ManifestNode,\n  // TODO: Consider persisting the computed requestKey into the hints output\n  // so it doesn't need to be recomputed during the build. This might also\n  // suggest renaming prefetch-hints.json to something like\n  // segment-manifest.json, since it would contain more than just hints.\n  requestKey: SegmentRequestKey,\n  parentGzipSize: number | null,\n  maxSize: number,\n  maxBundleSize: number,\n  headGzipSize: number,\n  headInlineState: { inlined: boolean }\n): Promise<{\n  node: PrefetchHints\n  // Total inlined bytes accumulated along the deepest accepting path in this\n  // subtree. Used by ancestors for budget checks.\n  inlinedBytes: number\n}> {\n  // Render current segment and measure its gzip size.\n  let currentGzipSize: number | null = null\n  if (seedData !== null) {\n    const varyParamsThenable = seedData[4]\n    const varyParams =\n      varyParamsThenable !== null ? readVaryParams(varyParamsThenable) : null\n\n    const [, buffer] = await renderSegmentPrefetch(\n      buildId,\n      staleTime,\n      seedData[0],\n      requestKey,\n      varyParams,\n      clientModules\n    )\n    currentGzipSize = await getGzipSize(buffer)\n  }\n\n  // Only offer this segment to its children for inlining if its gzip size\n  // is below maxSize. Segments above this get their own response.\n  const sizeToInline =\n    currentGzipSize !== null && currentGzipSize < maxSize\n      ? currentGzipSize\n      : null\n\n  // Process children serially (not in parallel) to ensure deterministic\n  // results. Since this only runs at build time and the rendering is just\n  // re-encoding cached prerenders, this won't impact build times. Each child\n  // receives our gzip size and decides whether to inline us. Once a child\n  // accepts, we stop offering to remaining siblings — the parent is only\n  // inlined into one child. In parallel routes, this avoids duplicating the\n  // parent's data across multiple sibling responses.\n  const children = route[1]\n  const seedDataChildren = seedData !== null ? seedData[1] : null\n\n  let slots: Record<string, PrefetchHints> | null = null\n  let didInlineIntoChild = false\n  let acceptingChildInlinedBytes = 0\n  // Track the smallest inlinedBytes across all children so we know how much\n  // budget remains along the best path. When our own parent asks whether we\n  // can accept its data, the parent's bytes would flow through to the child\n  // with the most remaining headroom.\n  let smallestChildInlinedBytes = Infinity\n  let hasChildren = false\n\n  for (const parallelRouteKey in children) {\n    hasChildren = true\n    const childRoute = children[parallelRouteKey]\n    const childSegment = childRoute[0]\n    const childSeedData =\n      seedDataChildren !== null ? seedDataChildren[parallelRouteKey] : null\n\n    const childRequestKey = appendSegmentRequestKeyPart(\n      requestKey,\n      parallelRouteKey,\n      createSegmentRequestKeyPart(childSegment)\n    )\n\n    const childResult = await collectPrefetchHintsImpl(\n      childRoute,\n      buildId,\n      staleTime,\n      childSeedData,\n      clientModules,\n      childRequestKey,\n      // Once a child has accepted us, stop offering to remaining siblings.\n      didInlineIntoChild ? null : sizeToInline,\n      maxSize,\n      maxBundleSize,\n      headGzipSize,\n      headInlineState\n    )\n\n    if (slots === null) {\n      slots = {}\n    }\n    slots[parallelRouteKey] = childResult.node\n\n    if (childResult.node.hints & PrefetchHint.ParentInlinedIntoSelf) {\n      // This child accepted our data — it will include our segment's\n      // response in its own. No need to track headroom anymore since\n      // we already know which child we're inlined into.\n      didInlineIntoChild = true\n      acceptingChildInlinedBytes = childResult.inlinedBytes\n    } else if (!didInlineIntoChild) {\n      // Track the child with the most remaining headroom. Used below\n      // when deciding whether to accept our own parent's data.\n      if (childResult.inlinedBytes < smallestChildInlinedBytes) {\n        smallestChildInlinedBytes = childResult.inlinedBytes\n      }\n    }\n  }\n\n  // Leaf segment: no children have consumed any budget yet.\n  if (!hasChildren) {\n    smallestChildInlinedBytes = 0\n  }\n\n  // Mark this segment as InlinedIntoChild if one of its children accepted.\n  // This means this segment doesn't need its own prefetch response — its\n  // data is included in the accepting child's response instead.\n  let hints = 0\n  if (didInlineIntoChild) {\n    hints |= PrefetchHint.InlinedIntoChild\n  }\n\n  // inlinedBytes represents the total gzipped bytes of parent data inlined\n  // into the deepest \"inlining target\" along this branch. It starts at 0 at\n  // the leaves and grows as parents are inlined going back up the tree. If a\n  // child accepted us, our size is already counted in that child's value.\n  let inlinedBytes = didInlineIntoChild\n    ? acceptingChildInlinedBytes\n    : smallestChildInlinedBytes\n\n  // At leaf nodes (pages), try to inline the head (metadata/viewport) into\n  // this page's response. The head is treated like an additional inlined\n  // entry — it counts against the same total budget. Only the first page\n  // that has room gets the head; subsequent pages skip via the shared\n  // headInlineState accumulator.\n  if (!hasChildren && !headInlineState.inlined) {\n    if (inlinedBytes + headGzipSize < maxBundleSize) {\n      hints |= PrefetchHint.HeadInlinedIntoSelf\n      inlinedBytes += headGzipSize\n      headInlineState.inlined = true\n    }\n  }\n\n  // Decide whether to accept our own parent's data. Two conditions:\n  //\n  // 1. The parent offered us a size (parentGzipSize is not null). It's null\n  //    when the parent is too large to inline or when this is the root.\n  //\n  // 2. The total inlined bytes along this branch wouldn't exceed the budget.\n  //    Even if each segment is individually small, at some point it no\n  //    longer makes sense to keep adding bytes because the combined response\n  //    is unique per URL and can't be deduped.\n  //\n  // A node can be both InlinedIntoChild and ParentInlinedIntoSelf. This\n  // happens in multi-level chains: GP → P → C where all are small. C\n  // accepts P (P is InlinedIntoChild), then P also accepts GP (P is\n  // ParentInlinedIntoSelf). The result: C's response includes both P's\n  // and GP's data. The parent's data flows through to the deepest\n  // accepting descendant.\n  if (parentGzipSize !== null) {\n    if (inlinedBytes + parentGzipSize < maxBundleSize) {\n      hints |= PrefetchHint.ParentInlinedIntoSelf\n      inlinedBytes += parentGzipSize\n    }\n  }\n\n  return {\n    node: { hints, slots },\n    inlinedBytes,\n  }\n}\n\n// We use gzip size rather than raw size because it better reflects the actual\n// transfer cost. The inlining trade-off is about whether the overhead of an\n// additional HTTP request (connection setup, headers, round trip) is worth\n// the deduplication benefit of keeping a segment separate. Below some\n// compressed size, the request overhead dominates and inlining is better.\n// Above it, the deduplication benefit of a cacheable standalone response\n// wins out.\nasync function getGzipSize(buffer: Buffer): Promise<number> {\n  const stream = new Blob([new Uint8Array(buffer)])\n    .stream()\n    .pipeThrough(new CompressionStream('gzip'))\n  const compressedBlob = await new Response(stream).blob()\n  return compressedBlob.size\n}\n\nasync function PrefetchTreeData({\n  isClientParamParsingEnabled,\n  fullPageDataBuffer,\n  serverConsumerManifest,\n  clientModules,\n  staleTime,\n  segmentTasks,\n  onCompletedProcessingRouteTree,\n  prefetchInlining,\n  hints,\n}: {\n  isClientParamParsingEnabled: boolean\n  fullPageDataBuffer: Buffer\n  serverConsumerManifest: any\n  clientModules: ManifestNode\n  staleTime: number\n  segmentTasks: Array<Promise<[SegmentRequestKey, Buffer]>>\n  onCompletedProcessingRouteTree: () => void\n  prefetchInlining: boolean\n  hints: PrefetchHints | null\n}): Promise<RootTreePrefetch | null> {\n  // We're currently rendering a Flight response for the route tree prefetch.\n  // Inside this component, decode the Flight stream for the whole page. This is\n  // a hack to transfer the side effects from the original Flight stream (e.g.\n  // Float preloads) onto the Flight stream for the tree prefetch.\n  // TODO: React needs a better way to do this. Needed for Server Actions, too.\n  const initialRSCPayload: InitialRSCPayload = await createFromReadableStream(\n    createUnclosingPrefetchStream(streamFromBuffer(fullPageDataBuffer)),\n    {\n      findSourceMapURL,\n      serverConsumerManifest,\n    }\n  )\n\n  const flightData = extractFlightData(initialRSCPayload)\n  if (flightData === null) {\n    return null\n  }\n  const { buildId, flightRouterState, seedData, head } = flightData\n\n  // Extract the head vary params from the decoded response.\n  // The head vary params thenable should be fulfilled by now; if not, treat\n  // as unknown (null).\n  const headVaryParamsThenable = initialRSCPayload.h\n  const headVaryParams =\n    headVaryParamsThenable !== null\n      ? readVaryParams(headVaryParamsThenable)\n      : null\n\n  // Compute the route metadata tree by traversing the FlightRouterState. As we\n  // walk the tree, we will also spawn a task to produce a prefetch response for\n  // each segment (unless prefetch inlining is enabled, in which case all\n  // segments are bundled into a single /_inlined response).\n  const tree = collectSegmentDataImpl(\n    isClientParamParsingEnabled,\n    flightRouterState,\n    buildId,\n    staleTime,\n    seedData,\n    clientModules,\n    ROOT_SEGMENT_REQUEST_KEY,\n    segmentTasks,\n    prefetchInlining,\n    hints\n  )\n\n  if (prefetchInlining) {\n    // When prefetch inlining is enabled, bundle all segment data into a single\n    // /_inlined response instead of individual per-segment responses. The head\n    // is also included in the inlined response.\n    segmentTasks.push(\n      waitAtLeastOneReactRenderTask().then(() =>\n        renderInlinedPrefetchResponse(\n          flightRouterState,\n          buildId,\n          staleTime,\n          seedData,\n          head,\n          headVaryParams,\n          clientModules\n        )\n      )\n    )\n  } else {\n    // Also spawn a task to produce a prefetch response for the \"head\" segment.\n    // The head contains metadata, like the title; it's not really a route\n    // segment, but it contains RSC data, so it's treated like a segment by\n    // the client cache.\n    segmentTasks.push(\n      waitAtLeastOneReactRenderTask().then(() =>\n        renderSegmentPrefetch(\n          buildId,\n          staleTime,\n          head,\n          HEAD_REQUEST_KEY,\n          headVaryParams,\n          clientModules\n        )\n      )\n    )\n  }\n\n  // Notify the abort controller that we're done processing the route tree.\n  // Anything async that happens after this point must be due to hanging\n  // promises in the original stream.\n  onCompletedProcessingRouteTree()\n\n  // Render the route tree to a special `/_tree` segment.\n  const treePrefetch: RootTreePrefetch = {\n    tree,\n    staleTime,\n  }\n  if (buildId) {\n    treePrefetch.buildId = buildId\n  }\n  return treePrefetch\n}\n\nfunction collectSegmentDataImpl(\n  isClientParamParsingEnabled: boolean,\n  route: FlightRouterState,\n  buildId: string | undefined,\n  staleTime: number,\n  seedData: CacheNodeSeedData | null,\n  clientModules: ManifestNode,\n  requestKey: SegmentRequestKey,\n  segmentTasks: Array<Promise<[string, Buffer]>>,\n  prefetchInlining: boolean,\n  hintTree: PrefetchHints | null\n): TreePrefetch {\n  // Metadata about the segment. Sent as part of the tree prefetch. Null if\n  // there are no children.\n  let slotMetadata: { [parallelRouteKey: string]: TreePrefetch } | null = null\n\n  const children = route[1]\n  const seedDataChildren = seedData !== null ? seedData[1] : null\n  for (const parallelRouteKey in children) {\n    const childRoute = children[parallelRouteKey]\n    const childSegment = childRoute[0]\n    const childSeedData =\n      seedDataChildren !== null ? seedDataChildren[parallelRouteKey] : null\n\n    const childRequestKey = appendSegmentRequestKeyPart(\n      requestKey,\n      parallelRouteKey,\n      createSegmentRequestKeyPart(childSegment)\n    )\n    const childHintTree =\n      hintTree !== null && hintTree.slots !== null\n        ? (hintTree.slots[parallelRouteKey] ?? null)\n        : null\n    const childTree = collectSegmentDataImpl(\n      isClientParamParsingEnabled,\n      childRoute,\n      buildId,\n      staleTime,\n      childSeedData,\n      clientModules,\n      childRequestKey,\n      segmentTasks,\n      prefetchInlining,\n      childHintTree\n    )\n    if (slotMetadata === null) {\n      slotMetadata = {}\n    }\n    slotMetadata[parallelRouteKey] = childTree\n  }\n\n  // Union the hints already embedded in the FlightRouterState with the\n  // separately-computed build-time hints. During the initial build, the\n  // FlightRouterState was produced before collectPrefetchHints ran, so\n  // inlining hints (ParentInlinedIntoSelf, InlinedIntoChild) won't be in\n  // route[4] yet. On subsequent renders the hints are already in the\n  // FlightRouterState, so the union is idempotent.\n  const prefetchHints =\n    (route[4] ?? 0) | (hintTree !== null ? hintTree.hints : 0)\n\n  // Determine which params this segment varies on.\n  // Read the vary params thenable directly from the seed data. By the time\n  // collectSegmentData runs, the thenable should be fulfilled. If it's not\n  // fulfilled or null, treat as unknown (null means we can't share cache\n  // entries across param values).\n  const varyParamsThenable = seedData !== null ? seedData[4] : null\n  const varyParams =\n    varyParamsThenable !== null ? readVaryParams(varyParamsThenable) : null\n\n  if (!prefetchInlining) {\n    // When prefetch inlining is disabled, spawn individual segment tasks.\n    // When enabled, segment data is bundled into the /_inlined response\n    // instead, so we skip per-segment tasks here.\n    if (seedData !== null) {\n      // Spawn a task to write the segment data to a new Flight stream.\n      segmentTasks.push(\n        // Since we're already in the middle of a render, wait until after the\n        // current task to escape the current rendering context.\n        waitAtLeastOneReactRenderTask().then(() =>\n          renderSegmentPrefetch(\n            buildId,\n            staleTime,\n            seedData[0],\n            requestKey,\n            varyParams,\n            clientModules\n          )\n        )\n      )\n    } else {\n      // This segment does not have any seed data. Skip generating a prefetch\n      // response for it. We'll still include it in the route tree, though.\n      // TODO: We should encode in the route tree whether a segment is missing\n      // so we don't attempt to fetch it for no reason. As of now this shouldn't\n      // ever happen in practice, though.\n    }\n  }\n\n  const segment = route[0]\n  let name: string\n  let param: TreePrefetchParam | null\n  if (typeof segment === 'string') {\n    name = segment\n    param = null\n  } else {\n    name = segment[0]\n    param = {\n      type: segment[2],\n      // This value is omitted from the prefetch response when cacheComponents\n      // is enabled.\n      key: isClientParamParsingEnabled ? null : segment[1],\n      siblings: segment[3],\n    }\n  }\n\n  // Metadata about the segment. Sent to the client as part of the\n  // tree prefetch.\n  return {\n    name,\n    param,\n    prefetchHints,\n    slots: slotMetadata,\n  }\n}\n\nasync function renderSegmentPrefetch(\n  buildId: string | undefined,\n  staleTime: number,\n  rsc: React.ReactNode,\n  requestKey: SegmentRequestKey,\n  varyParams: Set<string> | null,\n  clientModules: ManifestNode\n): Promise<[SegmentRequestKey, Buffer]> {\n  // Render the segment data to a stream.\n  const segmentPrefetch: SegmentPrefetch = {\n    rsc,\n    isPartial: await isPartialRSCData(rsc, clientModules),\n    staleTime,\n    varyParams,\n  }\n  if (buildId) {\n    segmentPrefetch.buildId = buildId\n  }\n  // Since all we're doing is decoding and re-encoding a cached prerender, if\n  // it takes longer than a microtask, it must because of hanging promises\n  // caused by dynamic data. Abort the stream at the end of the current task.\n  const abortController = new AbortController()\n  waitAtLeastOneReactRenderTask().then(() => abortController.abort())\n  const { prelude: segmentStream } = await prerender(\n    segmentPrefetch,\n    clientModules,\n    {\n      filterStackFrame,\n      signal: abortController.signal,\n      onError: onSegmentPrerenderError,\n    }\n  )\n  const segmentBuffer = await streamToBuffer(segmentStream)\n  if (requestKey === ROOT_SEGMENT_REQUEST_KEY) {\n    return ['/_index' as SegmentRequestKey, segmentBuffer]\n  } else {\n    return [requestKey, segmentBuffer]\n  }\n}\n\nasync function renderInlinedPrefetchResponse(\n  route: FlightRouterState,\n  buildId: string | undefined,\n  staleTime: number,\n  seedData: CacheNodeSeedData | null,\n  head: HeadData,\n  headVaryParams: Set<string> | null,\n  clientModules: ManifestNode\n): Promise<[SegmentRequestKey, Buffer]> {\n  // Build the inlined tree by walking the route and collecting all segments.\n  const inlinedTree = await buildInlinedSegmentPrefetch(\n    route,\n    buildId,\n    staleTime,\n    seedData,\n    clientModules\n  )\n\n  // Build the head segment.\n  const headPrefetch: SegmentPrefetch = {\n    rsc: head,\n    isPartial: await isPartialRSCData(head, clientModules),\n    staleTime,\n    varyParams: headVaryParams,\n  }\n  if (buildId) {\n    headPrefetch.buildId = buildId\n  }\n\n  const response: InlinedPrefetchResponse = {\n    tree: inlinedTree,\n    head: headPrefetch,\n  }\n\n  // Render as a single Flight response.\n  const abortController = new AbortController()\n  waitAtLeastOneReactRenderTask().then(() => abortController.abort())\n  const { prelude } = await prerender(response, clientModules, {\n    filterStackFrame,\n    signal: abortController.signal,\n    onError: onSegmentPrerenderError,\n  })\n  const buffer = await streamToBuffer(prelude)\n  return [('/' + PAGE_SEGMENT_KEY) as SegmentRequestKey, buffer]\n}\n\nasync function buildInlinedSegmentPrefetch(\n  route: FlightRouterState,\n  buildId: string | undefined,\n  staleTime: number,\n  seedData: CacheNodeSeedData | null,\n  clientModules: ManifestNode\n): Promise<InlinedSegmentPrefetch> {\n  let slots: {\n    [parallelRouteKey: string]: InlinedSegmentPrefetch\n  } | null = null\n\n  const children = route[1]\n  const seedDataChildren = seedData !== null ? seedData[1] : null\n  for (const parallelRouteKey in children) {\n    const childRoute = children[parallelRouteKey]\n    const childSeedData =\n      seedDataChildren !== null ? seedDataChildren[parallelRouteKey] : null\n    const childPrefetch = await buildInlinedSegmentPrefetch(\n      childRoute,\n      buildId,\n      staleTime,\n      childSeedData,\n      clientModules\n    )\n    if (slots === null) {\n      slots = {}\n    }\n    slots[parallelRouteKey] = childPrefetch\n  }\n\n  const rsc = seedData !== null ? seedData[0] : null\n  const varyParamsThenable = seedData !== null ? seedData[4] : null\n  const varyParams =\n    varyParamsThenable !== null ? readVaryParams(varyParamsThenable) : null\n\n  const segment: SegmentPrefetch = {\n    rsc,\n    isPartial: rsc !== null ? await isPartialRSCData(rsc, clientModules) : true,\n    staleTime,\n    varyParams,\n  }\n  if (buildId) {\n    segment.buildId = buildId\n  }\n  return { segment, slots }\n}\n\nasync function isPartialRSCData(\n  rsc: React.ReactNode,\n  clientModules: ManifestNode\n): Promise<boolean> {\n  // We can determine if a segment contains only partial data if it takes longer\n  // than a task to encode, because dynamic data is encoded as an infinite\n  // promise. We must do this in a separate Flight prerender from the one that\n  // actually generates the prefetch stream because we need to include\n  // `isPartial` in the stream itself.\n  let isPartial = false\n  const abortController = new AbortController()\n  waitAtLeastOneReactRenderTask().then(() => {\n    // If we haven't yet finished the outer task, then it must be because we\n    // accessed dynamic data.\n    isPartial = true\n    abortController.abort()\n  })\n  await prerender(rsc, clientModules, {\n    filterStackFrame,\n    signal: abortController.signal,\n    onError() {},\n  })\n  return isPartial\n}\n\nfunction createUnclosingPrefetchStream(\n  originalFlightStream: ReadableStream<Uint8Array>\n): ReadableStream<Uint8Array> {\n  // When PPR is enabled, prefetch streams may contain references that never\n  // resolve, because that's how we encode dynamic data access. In the decoded\n  // object returned by the Flight client, these are reified into hanging\n  // promises that suspend during render, which is effectively what we want.\n  // The UI resolves when it switches to the dynamic data stream\n  // (via useDeferredValue(dynamic, static)).\n  //\n  // However, the Flight implementation currently errors if the server closes\n  // the response before all the references are resolved. As a cheat to work\n  // around this, we wrap the original stream in a new stream that never closes,\n  // and therefore doesn't error.\n  const reader = originalFlightStream.getReader()\n  return new ReadableStream({\n    async pull(controller) {\n      while (true) {\n        const { done, value } = await reader.read()\n        if (!done) {\n          // Pass to the target stream and keep consuming the Flight response\n          // from the server.\n          controller.enqueue(value)\n          continue\n        }\n        // The server stream has closed. Exit, but intentionally do not close\n        // the target stream.\n        return\n      }\n    },\n  })\n}\n"],"names":["collectPrefetchHints","collectSegmentData","filterStackFrame","process","env","NODE_ENV","require","filterStackFrameDEV","undefined","findSourceMapURL","findSourceMapURLDEV","onSegmentPrerenderError","error","digest","getDigestForWellKnownError","NEXT_DEBUG_BUILD","__NEXT_VERBOSE_LOGGING","workStore","workAsyncStorage","getStore","printDebugThrownValueForProspectiveRender","route","Phase","SegmentCollection","extractFlightData","initialRSCPayload","flightDataPaths","f","length","console","buildId","b","flightRouterState","seedData","head","isCacheComponentsEnabled","fullPageDataBuffer","staleTime","clientModules","serverConsumerManifest","prefetchInlining","hints","resultMap","Map","createFromReadableStream","streamFromBuffer","waitAtLeastOneReactRenderTask","abortController","AbortController","onCompletedProcessingRouteTree","abort","segmentTasks","prelude","treeStream","prerender","PrefetchTreeData","isClientParamParsingEnabled","signal","onError","treeBuffer","streamToBuffer","set","segmentPath","buffer","Promise","all","maxSize","maxBundleSize","createUnclosingPrefetchStream","flightData","slots","headVaryParamsThenable","h","headVaryParams","readVaryParams","headBuffer","renderSegmentPrefetch","HEAD_REQUEST_KEY","headGzipSize","getGzipSize","headInlineState","inlined","node","collectPrefetchHintsImpl","ROOT_SEGMENT_REQUEST_KEY","PrefetchHint","HeadOutlined","requestKey","parentGzipSize","currentGzipSize","varyParamsThenable","varyParams","sizeToInline","children","seedDataChildren","didInlineIntoChild","acceptingChildInlinedBytes","smallestChildInlinedBytes","Infinity","hasChildren","parallelRouteKey","childRoute","childSegment","childSeedData","childRequestKey","appendSegmentRequestKeyPart","createSegmentRequestKeyPart","childResult","ParentInlinedIntoSelf","inlinedBytes","InlinedIntoChild","HeadInlinedIntoSelf","stream","Blob","Uint8Array","pipeThrough","CompressionStream","compressedBlob","Response","blob","size","tree","collectSegmentDataImpl","push","then","renderInlinedPrefetchResponse","treePrefetch","hintTree","slotMetadata","childHintTree","childTree","prefetchHints","segment","name","param","type","key","siblings","rsc","segmentPrefetch","isPartial","isPartialRSCData","segmentStream","segmentBuffer","inlinedTree","buildInlinedSegmentPrefetch","headPrefetch","response","PAGE_SEGMENT_KEY","childPrefetch","originalFlightStream","reader","getReader","ReadableStream","pull","controller","done","value","read","enqueue"],"mappings":"AAAA,6GAA6G;;;;;;;;;;;;;;;IAwQvFA,oBAAoB;eAApBA;;IA5FAC,kBAAkB;eAAlBA;;;;gCAnKO;oCACE;yBACE;wBAIQ;wBAEf;sCAKnB;2BACuC;sCAOvC;oCACoC;wCAIpC;0CAC0B;AAgFjC,MAAMC,mBACJC,QAAQC,GAAG,CAACC,QAAQ,KAAK,eACrB,AAACC,QAAQ,sBACNC,mBAAmB,GACtBC;AACN,MAAMC,mBACJN,QAAQC,GAAG,CAACC,QAAQ,KAAK,eACrB,AAACC,QAAQ,sBACNI,mBAAmB,GACtBF;AAEN,SAASG,wBAAwBC,KAAc;IAC7C,MAAMC,SAASC,IAAAA,8CAA0B,EAACF;IAC1C,IAAIC,QAAQ;QACV,OAAOA;IACT;IACA,0EAA0E;IAC1E,iEAAiE;IACjE,IAAIV,QAAQC,GAAG,CAACW,gBAAgB,IAAIZ,QAAQC,GAAG,CAACY,sBAAsB,EAAE;QACtE,MA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