{"version":3,"sources":["../../../../../src/server/app-render/instant-validation/boundary-impl.tsx"],"sourcesContent":["/* eslint-disable @next/internal/no-ambiguous-jsx -- React Client */\n\n// Do not put a \"use client\" directive here. Import this module via the shim in\n// `packages/next/src/client/components/instant-validation/boundary.tsx` instead.\n// 'use client'\n\nimport { createContext, type ReactNode } from 'react'\nimport { INSTANT_VALIDATION_BOUNDARY_NAME } from './boundary-constants'\nimport { InvariantError } from '../../../shared/lib/invariant-error'\nimport type { ValidationBoundaryTracking } from './boundary-tracking'\nimport { workUnitAsyncStorage } from '../work-unit-async-storage.external'\n\nif (typeof window !== 'undefined') {\n  throw new InvariantError(\n    'Instant validation boundaries should never appear in browser bundles.'\n  )\n}\n\nfunction getValidationBoundaryTracking(): ValidationBoundaryTracking | null {\n  const store = workUnitAsyncStorage.getStore()\n  if (!store) return null\n  switch (store.type) {\n    case 'validation-client':\n      return store.boundaryState\n    case 'prerender':\n    case 'prerender-client':\n    case 'prerender-ppr':\n    case 'prerender-legacy':\n    case 'prerender-runtime':\n    case 'request':\n    case 'cache':\n    case 'private-cache':\n    case 'unstable-cache':\n    case 'generate-static-params':\n      break\n    default:\n      store satisfies never\n  }\n  return null\n}\n\n// We use a namespace object to allow us to recover the name of the function\n// at runtime even when production bundling/minification is used.\nconst NameSpace = {\n  [INSTANT_VALIDATION_BOUNDARY_NAME]: function ({\n    id,\n    children,\n  }: {\n    id: string\n    children: ReactNode\n  }) {\n    // Track which boundaries we actually managed to render.\n    const state = getValidationBoundaryTracking()\n    if (state === null) {\n      throw new InvariantError('Missing boundary tracking state')\n    }\n    state.renderedIds.add(id)\n\n    return children\n  },\n}\n\ntype BoundaryPlacement =\n  | null // do not place here\n  | string // boundaryId -- place here\n\nexport const InstantValidationBoundaryContext =\n  createContext<BoundaryPlacement>(null)\n\nexport function PlaceValidationBoundaryBelowThisLevel({\n  id,\n  children,\n}: {\n  id: string\n  children: ReactNode\n}) {\n  return (\n    // OuterLayoutRouter will see this and render a `RenderValidationBoundaryAtThisLevel`.\n    <InstantValidationBoundaryContext value={id}>\n      {children}\n    </InstantValidationBoundaryContext>\n  )\n}\n\nexport function RenderValidationBoundaryAtThisLevel({\n  id,\n  children,\n}: {\n  id: string\n  children: ReactNode\n}) {\n  // We got a boundaryId from the context. Clear the context so that the children don't render another boundary.\n  return (\n    <InstantValidationBoundary id={id}>\n      <InstantValidationBoundaryContext value={null}>\n        {children}\n      </InstantValidationBoundaryContext>\n    </InstantValidationBoundary>\n  )\n}\n\nconst InstantValidationBoundary =\n  // We use slice(0) to trick the bundler into not inlining/minifying the function\n  // so it retains the name inferred from the namespace object\n  NameSpace[\n    INSTANT_VALIDATION_BOUNDARY_NAME.slice(\n      0\n    ) as typeof INSTANT_VALIDATION_BOUNDARY_NAME\n  ]\n"],"names":["createContext","INSTANT_VALIDATION_BOUNDARY_NAME","InvariantError","workUnitAsyncStorage","window","getValidationBoundaryTracking","store","getStore","type","boundaryState","NameSpace","id","children","state","renderedIds","add","InstantValidationBoundaryContext","PlaceValidationBoundaryBelowThisLevel","value","RenderValidationBoundaryAtThisLevel","InstantValidationBoundary","slice"],"mappings":"AAAA,kEAAkE,GAElE,+EAA+E;AAC/E,iFAAiF;AACjF,eAAe;;AAEf,SAASA,aAAa,QAAwB,QAAO;AACrD,SAASC,gCAAgC,QAAQ,uBAAsB;AACvE,SAASC,cAAc,QAAQ,sCAAqC;AAEpE,SAASC,oBAAoB,QAAQ,sCAAqC;AAE1E,IAAI,OAAOC,WAAW,aAAa;IACjC,MAAM,qBAEL,CAFK,IAAIF,eACR,0EADI,qBAAA;eAAA;oBAAA;sBAAA;IAEN;AACF;AAEA,SAASG;IACP,MAAMC,QAAQH,qBAAqBI,QAAQ;IAC3C,IAAI,CAACD,OAAO,OAAO;IACnB,OAAQA,MAAME,IAAI;QAChB,KAAK;YACH,OAAOF,MAAMG,aAAa;QAC5B,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,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