/opt/canhelp/node_modules/next/dist/esm/server/app-render
Edit: /opt/canhelp/node_modules/next/dist/esm/server/app-render/postponed-state.js.map (9091B)
{"version":3,"sources":["../../../src/server/app-render/postponed-state.ts"],"sourcesContent":["import type { FallbackRouteParams } from '../../server/request/fallback-params'\nimport type { Params } from '../request/params'\nimport {\n createPrerenderResumeDataCache,\n createRenderResumeDataCache,\n type PrerenderResumeDataCache,\n type RenderResumeDataCache,\n} from '../resume-data-cache/resume-data-cache'\nimport { stringifyResumeDataCache } from '../resume-data-cache/resume-data-cache'\n\nexport enum DynamicState {\n /**\n * The dynamic access occurred during the RSC render phase.\n */\n DATA = 1,\n\n /**\n * The dynamic access occurred during the HTML shell render phase.\n */\n HTML = 2,\n}\n\n/**\n * The postponed state for dynamic data.\n */\nexport type DynamicDataPostponedState = {\n /**\n * The type of dynamic state.\n */\n readonly type: DynamicState.DATA\n\n /**\n * The immutable resume data cache.\n */\n readonly renderResumeDataCache: RenderResumeDataCache\n}\n\n/**\n * The postponed state for dynamic HTML.\n */\nexport type DynamicHTMLPostponedState = {\n /**\n * The type of dynamic state.\n */\n readonly type: DynamicState.HTML\n\n /**\n * The postponed data used by React.\n */\n readonly data: [\n preludeState: DynamicHTMLPreludeState,\n postponed: ReactPostponed,\n ]\n\n /**\n * The immutable resume data cache.\n */\n readonly renderResumeDataCache: RenderResumeDataCache\n}\n\nexport const enum DynamicHTMLPreludeState {\n Empty = 0,\n Full = 1,\n}\n\ntype ReactPostponed = NonNullable<\n import('react-dom/static').PrerenderResult['postponed']\n>\n\nexport type PostponedState =\n | DynamicDataPostponedState\n | DynamicHTMLPostponedState\n\nexport async function getDynamicHTMLPostponedState(\n postponed: ReactPostponed,\n preludeState: DynamicHTMLPreludeState,\n fallbackRouteParams: FallbackRouteParams | null,\n resumeDataCache: PrerenderResumeDataCache | RenderResumeDataCache\n): Promise
{\n const data: DynamicHTMLPostponedState['data'] = [preludeState, postponed]\n const dataString = JSON.stringify(data)\n\n if (!fallbackRouteParams || fallbackRouteParams.size === 0) {\n // Serialized as `:`\n return `${dataString.length}:${dataString}${await stringifyResumeDataCache(\n createRenderResumeDataCache(resumeDataCache)\n )}`\n }\n\n const replacements: Array<[string, string]> = Array.from(fallbackRouteParams)\n const replacementsString = JSON.stringify(replacements)\n\n // Serialized as ``\n const postponedString = `${replacementsString.length}${replacementsString}${dataString}`\n\n // Serialized as `:`\n return `${postponedString.length}:${postponedString}${await stringifyResumeDataCache(resumeDataCache)}`\n}\n\nexport async function getDynamicDataPostponedState(\n resumeDataCache: PrerenderResumeDataCache | RenderResumeDataCache\n): Promise {\n return `4:null${await stringifyResumeDataCache(createRenderResumeDataCache(resumeDataCache))}`\n}\n\nexport function parsePostponedState(\n state: string,\n params: Params | undefined\n): PostponedState {\n try {\n const postponedStringLengthMatch = state.match(/^([0-9]*):/)?.[1]\n if (!postponedStringLengthMatch) {\n throw new Error(`Invariant: invalid postponed state ${state}`)\n }\n\n const postponedStringLength = parseInt(postponedStringLengthMatch)\n\n // We add a `:` to the end of the length as the first character of the\n // postponed string is the length of the replacement entries.\n const postponedString = state.slice(\n postponedStringLengthMatch.length + 1,\n postponedStringLengthMatch.length + postponedStringLength + 1\n )\n\n const renderResumeDataCache = createRenderResumeDataCache(\n state.slice(postponedStringLengthMatch.length + postponedStringLength + 1)\n )\n\n try {\n if (postponedString === 'null') {\n return { type: DynamicState.DATA, renderResumeDataCache }\n }\n\n if (/^[0-9]/.test(postponedString)) {\n const match = postponedString.match(/^([0-9]*)/)?.[1]\n if (!match) {\n throw new Error(\n `Invariant: invalid postponed state ${JSON.stringify(postponedString)}`\n )\n }\n\n // This is the length of the replacements entries.\n const length = parseInt(match)\n const replacements = JSON.parse(\n postponedString.slice(\n match.length,\n // We then go to the end of the string.\n match.length + length\n )\n ) as ReadonlyArray<[string, string]>\n\n let postponed = postponedString.slice(match.length + length)\n for (const [key, searchValue] of replacements) {\n const value = params?.[key] ?? ''\n const replaceValue = Array.isArray(value) ? value.join('/') : value\n postponed = postponed.replaceAll(searchValue, replaceValue)\n }\n\n return {\n type: DynamicState.HTML,\n data: JSON.parse(postponed),\n renderResumeDataCache,\n }\n }\n\n return {\n type: DynamicState.HTML,\n data: JSON.parse(postponedString),\n renderResumeDataCache,\n }\n } catch (err) {\n console.error('Failed to parse postponed state', err)\n return { type: DynamicState.DATA, renderResumeDataCache }\n }\n } catch (err) {\n console.error('Failed to parse postponed state', err)\n return {\n type: DynamicState.DATA,\n renderResumeDataCache: createPrerenderResumeDataCache(),\n }\n }\n}\n\nexport function getPostponedFromState(state: DynamicHTMLPostponedState) {\n const [preludeState, postponed] = state.data\n return { preludeState, postponed }\n}\n"],"names":["createPrerenderResumeDataCache","createRenderResumeDataCache","stringifyResumeDataCache","DynamicState","DynamicHTMLPreludeState","getDynamicHTMLPostponedState","postponed","preludeState","fallbackRouteParams","resumeDataCache","data","dataString","JSON","stringify","size","length","replacements","Array","from","replacementsString","postponedString","getDynamicDataPostponedState","parsePostponedState","state","params","postponedStringLengthMatch","match","Error","postponedStringLength","parseInt","slice","renderResumeDataCache","type","test","parse","key","searchValue","value","replaceValue","isArray","join","replaceAll","err","console","error","getPostponedFromState"],"mappings":"AAEA,SACEA,8BAA8B,EAC9BC,2BAA2B,QAGtB,yCAAwC;AAC/C,SAASC,wBAAwB,QAAQ,yCAAwC;AAEjF,OAAO,IAAA,AAAKC,sCAAAA;IACV;;GAEC;IAGD;;GAEC;WARSA;MAUX;AAwCD,OAAO,IAAA,AAAWC,iDAAAA;;;WAAAA;MAGjB;AAUD,OAAO,eAAeC,6BACpBC,SAAyB,EACzBC,YAAqC,EACrCC,mBAA+C,EAC/CC,eAAiE;IAEjE,MAAMC,OAA0C;QAACH;QAAcD;KAAU;IACzE,MAAMK,aAAaC,KAAKC,SAAS,CAACH;IAElC,IAAI,CAACF,uBAAuBA,oBAAoBM,IAAI,KAAK,GAAG;QAC1D,oFAAoF;QACpF,OAAO,GAAGH,WAAWI,MAAM,CAAC,CAAC,EAAEJ,aAAa,MA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