Next.js website for Rocky Mountain Vending company featuring: - Product catalog with Stripe integration - Service areas and parts pages - Admin dashboard with Clerk authentication - SEO optimized pages with JSON-LD structured data Co-authored-by: Cursor <cursoragent@cursor.com>
1 line
No EOL
11 KiB
Text
1 line
No EOL
11 KiB
Text
{"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<BinaryStreamOf<any>, Promise<any>>()\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<T>(\n flightStream: BinaryStreamOf<T>,\n debugStream: ReadableStream<Uint8Array> | undefined,\n clientReferenceManifest: DeepReadonly<ClientReferenceManifest>,\n nonce: string | undefined\n): Promise<T> {\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<T>(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 debugChannel: debugStream ? { readable: debugStream } : undefined,\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<T>((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<Uint8Array>,\n nonce: string | undefined,\n formState: unknown | null\n): ReadableStream<Uint8Array> {\n const startScriptTag = nonce\n ? `<script nonce=${JSON.stringify(nonce)}>`\n : '<script>'\n\n const flightReader = flightStream.getReader()\n const decoder = new TextDecoder('utf-8', { fatal: true })\n\n const readable = new ReadableStream({\n type: 'bytes',\n start(controller) {\n try {\n writeInitialInstructions(controller, startScriptTag, formState)\n } catch (error) {\n // during encoding or enqueueing forward the error downstream\n controller.error(error)\n }\n },\n async pull(controller) {\n try {\n const { done, value } = await flightReader.read()\n\n if (value) {\n try {\n const decodedString = decoder.decode(value, { stream: !done })\n\n // The chunk cannot be decoded as valid UTF-8 string as it might\n // have arbitrary binary data.\n writeFlightDataInstruction(\n controller,\n startScriptTag,\n decodedString\n )\n } catch {\n // The chunk cannot be decoded as valid UTF-8 string.\n writeFlightDataInstruction(controller, startScriptTag, value)\n }\n }\n\n if (done) {\n controller.close()\n }\n } catch (error) {\n // There was a problem in the upstream reader or during decoding or enqueuing\n // forward the error downstream\n controller.error(error)\n }\n },\n })\n\n return readable\n}\n\nfunction writeInitialInstructions(\n controller: ReadableStreamDefaultController,\n scriptStart: string,\n formState: unknown | null\n) {\n let scriptContents = `(self.__next_f=self.__next_f||[]).push(${htmlEscapeJsonString(\n JSON.stringify([INLINE_FLIGHT_PAYLOAD_BOOTSTRAP])\n )})`\n\n if (formState != null) {\n scriptContents += `;self.__next_f.push(${htmlEscapeJsonString(\n JSON.stringify([INLINE_FLIGHT_PAYLOAD_FORM_STATE, formState])\n )})`\n }\n\n controller.enqueue(encoder.encode(`${scriptStart}${scriptContents}</script>`))\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})</script>`\n )\n )\n}\n"],"names":["htmlEscapeJsonString","workUnitAsyncStorage","InvariantError","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","useFlightStream","flightStream","debugStream","clientReferenceManifest","nonce","response","get","createFromReadableStream","newResponse","serverConsumerManifest","moduleLoading","moduleMap","edgeSSRModuleMapping","ssrModuleMapping","serverModuleMap","debugChannel","readable","workUnitStore","getStore","type","responseOnNextTick","Promise","resolve","nextTick","set","createInlinedDataReadableStream","formState","startScriptTag","JSON","stringify","flightReader","getReader","decoder","TextDecoder","fatal","ReadableStream","start","controller","writeInitialInstructions","error","pull","done","value","read","decodedString","decode","stream","writeFlightDataInstruction","close","scriptStart","scriptContents","enqueue","encode","chunk","htmlInlinedData","base64","btoa","String","fromCodePoint"],"mappings":"AAGA,SAASA,oBAAoB,QAAQ,gBAAe;AAEpD,SAASC,oBAAoB,QAAQ,qCAAoC;AACzE,SAASC,cAAc,QAAQ,mCAAkC;AAEjE,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;AAEN;;;CAGC,GACD,OAAO,SAASC,gBACdC,YAA+B,EAC/BC,WAAmD,EACnDC,uBAA8D,EAC9DC,KAAyB;IAEzB,MAAMC,WAAWd,gBAAgBe,GAAG,CAACL;IAErC,IAAII,UAAU;QACZ,OAAOA;IACT;IAEA,wGAAwG;IACxG,MAAM,EAAEE,wBAAwB,EAAE,GAChC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