@tanstack/router-core
Version:
Modern and scalable routing for React applications
1 lines • 2.67 kB
Source Map (JSON)
{"version":3,"file":"bodyScripts.cjs","names":[],"sources":["../../../src/ssr/bodyScripts.ts"],"sourcesContent":["import { _getAssetMatches } from '../load-client'\nimport type { Manifest, RouterManagedTag } from '../manifest'\nimport type { AnyRouteMatch } from '../Matches'\nimport type { InitialHydrationScriptTags } from './hydrationScripts'\n\ntype ScriptTags = Array<RouterManagedTag>\nexport type SsrBodyScriptParts = readonly [ScriptTags, ScriptTags]\n\nexport function getSsrBodyScriptParts(\n matches: Array<AnyRouteMatch>,\n manifest: Manifest | undefined,\n nonce: string | undefined,\n routeScriptAttrs?: Record<string, unknown>,\n): SsrBodyScriptParts {\n const assetMatches = _getAssetMatches(matches)\n const routeScripts: ScriptTags = []\n const manifestScripts: ScriptTags = []\n for (const match of assetMatches) {\n for (const script of Array.isArray(match.scripts) ? match.scripts : []) {\n if (!script) {\n continue\n }\n const { children, ...attrs } = script\n routeScripts.push({\n tag: 'script',\n attrs: { ...attrs, ...routeScriptAttrs, nonce },\n children,\n })\n }\n }\n if (manifest) {\n for (const match of assetMatches) {\n for (const asset of manifest.routes[match.routeId]?.scripts ?? []) {\n manifestScripts.push({\n tag: 'script',\n attrs: { ...asset.attrs, nonce },\n children: asset.children,\n })\n }\n }\n }\n return [routeScripts, manifestScripts]\n}\nexport function composeSsrBodyScripts(\n [routeScripts, manifestScripts]: SsrBodyScriptParts,\n initialHydrationScripts?: InitialHydrationScriptTags,\n): Array<RouterManagedTag> {\n if (!initialHydrationScripts) {\n return [...routeScripts, ...manifestScripts]\n }\n return [\n ...initialHydrationScripts.before,\n ...routeScripts,\n ...manifestScripts,\n initialHydrationScripts.boundary,\n ]\n}\n"],"mappings":";;AAQA,SAAgB,sBACd,SACA,UACA,OACA,kBACoB;CACpB,MAAM,eAAe,oBAAA,iBAAiB,OAAO;CAC7C,MAAM,eAA2B,CAAC;CAClC,MAAM,kBAA8B,CAAC;CACrC,KAAK,MAAM,SAAS,cAClB,KAAK,MAAM,UAAU,MAAM,QAAQ,MAAM,OAAO,IAAI,MAAM,UAAU,CAAC,GAAG;EACtE,IAAI,CAAC,QACH;EAEF,MAAM,EAAE,UAAU,GAAG,UAAU;EAC/B,aAAa,KAAK;GAChB,KAAK;GACL,OAAO;IAAE,GAAG;IAAO,GAAG;IAAkB;GAAM;GAC9C;EACF,CAAC;CACH;CAEF,IAAI,UACF,KAAK,MAAM,SAAS,cAClB,KAAK,MAAM,SAAS,SAAS,OAAO,MAAM,UAAU,WAAW,CAAC,GAC9D,gBAAgB,KAAK;EACnB,KAAK;EACL,OAAO;GAAE,GAAG,MAAM;GAAO;EAAM;EAC/B,UAAU,MAAM;CAClB,CAAC;CAIP,OAAO,CAAC,cAAc,eAAe;AACvC;AACA,SAAgB,sBACd,CAAC,cAAc,kBACf,yBACyB;CACzB,IAAI,CAAC,yBACH,OAAO,CAAC,GAAG,cAAc,GAAG,eAAe;CAE7C,OAAO;EACL,GAAG,wBAAwB;EAC3B,GAAG;EACH,GAAG;EACH,wBAAwB;CAC1B;AACF"}