/opt/canhelp/node_modules/next/dist/server/app-render
Edit: /opt/canhelp/node_modules/next/dist/server/app-render/use-flight-response.js.map (11174B)
{"version":3,"sources":["../../../src/server/app-render/use-flight-response.tsx"],"sourcesContent":["import type { ClientReferenceManifest } from '../../build/webpack/plugins/flight-manifest-plugin'\nimport type { BinaryStreamOf } from './app-render'\n\nimport { htmlEscapeJsonString } from '../htmlescape'\nimport type { DeepReadonly } from '../../shared/lib/deep-readonly'\nimport { workUnitAsyncStorage } from './work-unit-async-storage.external'\nimport { InvariantError } from '../../shared/lib/invariant-error'\n\nconst isEdgeRuntime = process.env.NEXT_RUNTIME === 'edge'\n\nconst INLINE_FLIGHT_PAYLOAD_BOOTSTRAP = 0\nconst INLINE_FLIGHT_PAYLOAD_DATA = 1\nconst INLINE_FLIGHT_PAYLOAD_FORM_STATE = 2\nconst INLINE_FLIGHT_PAYLOAD_BINARY = 3\n\nconst flightResponses = new WeakMap
, Promise>()\nconst encoder = new TextEncoder()\n\nconst findSourceMapURL =\n process.env.NODE_ENV !== 'production'\n ? (require('../lib/source-maps') as typeof import('../lib/source-maps'))\n .findSourceMapURLDEV\n : undefined\n\n/**\n * Render Flight stream.\n * This is only used for renderToHTML, the Flight response does not need additional wrappers.\n */\nexport function useFlightStream(\n flightStream: BinaryStreamOf,\n clientReferenceManifest: DeepReadonly,\n nonce?: string\n): Promise {\n const response = flightResponses.get(flightStream)\n\n if (response) {\n return response\n }\n\n // react-server-dom-webpack/client.edge must not be hoisted for require cache clearing to work correctly\n const { createFromReadableStream } =\n // eslint-disable-next-line import/no-extraneous-dependencies\n require('react-server-dom-webpack/client') as typeof import('react-server-dom-webpack/client')\n\n const newResponse = createFromReadableStream(flightStream, {\n findSourceMapURL,\n serverConsumerManifest: {\n moduleLoading: clientReferenceManifest.moduleLoading,\n moduleMap: isEdgeRuntime\n ? clientReferenceManifest.edgeSSRModuleMapping\n : clientReferenceManifest.ssrModuleMapping,\n serverModuleMap: null,\n },\n nonce,\n })\n\n // Edge pages are never prerendered so they necessarily cannot have a workUnitStore type\n // that requires the nextTick behavior. This is why it is safe to access a node only API here\n if (process.env.NEXT_RUNTIME !== 'edge') {\n const workUnitStore = workUnitAsyncStorage.getStore()\n\n if (!workUnitStore) {\n throw new InvariantError('Expected workUnitAsyncStorage to have a store.')\n }\n\n switch (workUnitStore.type) {\n case 'prerender-client':\n const responseOnNextTick = new Promise((resolve) => {\n process.nextTick(() => resolve(newResponse))\n })\n flightResponses.set(flightStream, responseOnNextTick)\n return responseOnNextTick\n case 'prerender':\n case 'prerender-runtime':\n case 'prerender-ppr':\n case 'prerender-legacy':\n case 'request':\n case 'cache':\n case 'private-cache':\n case 'unstable-cache':\n break\n default:\n workUnitStore satisfies never\n }\n }\n\n flightResponses.set(flightStream, newResponse)\n\n return newResponse\n}\n\n/**\n * Creates a ReadableStream provides inline script tag chunks for writing hydration\n * data to the client outside the React render itself.\n *\n * @param flightStream The RSC render stream\n * @param nonce optionally a nonce used during this particular render\n * @param formState optionally the formState used with this particular render\n * @returns a ReadableStream without the complete property. This signifies a lazy ReadableStream\n */\nexport function createInlinedDataReadableStream(\n flightStream: ReadableStream,\n nonce: string | undefined,\n formState: unknown | null\n): ReadableStream {\n const startScriptTag = nonce\n ? ``\n )\n )\n } else {\n controller.enqueue(\n encoder.encode(\n `${scriptStart}(self.__next_f=self.__next_f||[]).push(${htmlEscapeJsonString(\n JSON.stringify([INLINE_FLIGHT_PAYLOAD_BOOTSTRAP])\n )})`\n )\n )\n }\n}\n\nfunction writeFlightDataInstruction(\n controller: ReadableStreamDefaultController,\n scriptStart: string,\n chunk: string | Uint8Array\n) {\n let htmlInlinedData: string\n\n if (typeof chunk === 'string') {\n htmlInlinedData = htmlEscapeJsonString(\n JSON.stringify([INLINE_FLIGHT_PAYLOAD_DATA, chunk])\n )\n } else {\n // The chunk cannot be embedded as a UTF-8 string in the script tag.\n // Instead let's inline it in base64.\n // Credits to Devon Govett (devongovett) for the technique.\n // https://github.com/devongovett/rsc-html-stream\n const base64 = btoa(String.fromCodePoint(...chunk))\n htmlInlinedData = htmlEscapeJsonString(\n JSON.stringify([INLINE_FLIGHT_PAYLOAD_BINARY, base64])\n )\n }\n\n controller.enqueue(\n encoder.encode(\n `${scriptStart}self.__next_f.push(${htmlInlinedData})`\n )\n )\n}\n"],"names":["createInlinedDataReadableStream","useFlightStream","isEdgeRuntime","process","env","NEXT_RUNTIME","INLINE_FLIGHT_PAYLOAD_BOOTSTRAP","INLINE_FLIGHT_PAYLOAD_DATA","INLINE_FLIGHT_PAYLOAD_FORM_STATE","INLINE_FLIGHT_PAYLOAD_BINARY","flightResponses","WeakMap","encoder","TextEncoder","findSourceMapURL","NODE_ENV","require","findSourceMapURLDEV","undefined","flightStream","clientReferenceManifest","nonce","response","get","createFromReadableStream","newResponse","serverConsumerManifest","moduleLoading","moduleMap","edgeSSRModuleMapping","ssrModuleMapping","serverModuleMap","workUnitStore","workUnitAsyncStorage","getStore","InvariantError","type","responseOnNextTick","Promise","resolve","nextTick","set","formState","startScriptTag","JSON","stringify","flightReader","getReader","decoder","TextDecoder","fatal","readable","ReadableStream","start","controller","writeInitialInstructions","error","pull","done","value","read","decodedString","decode","stream","writeFlightDataInstruction","close","scriptStart","enqueue","encode","htmlEscapeJsonString","chunk","htmlInlinedData","base64","btoa","String","fromCodePoint"],"mappings":";;;;;;;;;;;;;;;IAoGgBA,+BAA+B;eAA/BA;;IAxEAC,eAAe;eAAfA;;;4BAzBqB;8CAEA;gCACN;AAE/B,MAAMC,gBAAgBC,QAAQC,GAAG,CAACC,YAAY,KAAK;AAEnD,MAAMC,kCAAkC;AACxC,MAAMC,6BAA6B;AACnC,MAAMC,mCAAmC;AACzC,MAAMC,+BAA+B;AAErC,MAAMC,kBAAkB,IAAIC;AAC5B,MAAMC,UAAU,IAAIC;AAEpB,MAAMC,mBACJX,QAAQC,GAAG,CAACW,QAAQ,KAAK,eACrB,AAACC,QAAQ,sBACNC,mBAAmB,GACtBC;AAMC,SAASjB,gBACdkB,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