@tanstack/router-core 1.168.14 → 1.168.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +3 -0
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/load-matches.cjs +1 -1
- package/dist/cjs/load-matches.cjs.map +1 -1
- package/dist/cjs/manifest.cjs +31 -0
- package/dist/cjs/manifest.cjs.map +1 -1
- package/dist/cjs/manifest.d.cts +8 -0
- package/dist/cjs/ssr/ssr-server.cjs +71 -5
- package/dist/cjs/ssr/ssr-server.cjs.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/load-matches.js +1 -1
- package/dist/esm/load-matches.js.map +1 -1
- package/dist/esm/manifest.d.ts +8 -0
- package/dist/esm/manifest.js +28 -1
- package/dist/esm/manifest.js.map +1 -1
- package/dist/esm/ssr/ssr-server.js +71 -5
- package/dist/esm/ssr/ssr-server.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +7 -1
- package/src/load-matches.ts +5 -3
- package/src/manifest.ts +46 -0
- package/src/ssr/ssr-server.ts +125 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr-server.cjs","names":[],"sources":["../../../src/ssr/ssr-server.ts"],"sourcesContent":["import { crossSerializeStream, getCrossReferenceHeader } from 'seroval'\nimport { invariant } from '../invariant'\nimport { decodePath } from '../utils'\nimport { createLRUCache } from '../lru-cache'\nimport { rootRouteId } from '../root'\nimport minifiedTsrBootStrapScript from './tsrScript?script-string'\nimport { GLOBAL_TSR, TSR_SCRIPT_BARRIER_ID } from './constants'\nimport { dehydrateSsrMatchId } from './ssr-match-id'\nimport { defaultSerovalPlugins } from './serializer/seroval-plugins'\nimport { makeSsrSerovalPlugin } from './serializer/transformer'\nimport type { LRUCache } from '../lru-cache'\nimport type { DehydratedMatch, DehydratedRouter } from './types'\nimport type { AnySerializationAdapter } from './serializer/transformer'\nimport type { AnyRouter } from '../router'\nimport type { AnyRouteMatch } from '../Matches'\nimport type { Manifest, RouterManagedTag } from '../manifest'\n\ndeclare module '../router' {\n interface ServerSsr {\n setRenderFinished: () => void\n cleanup: () => void\n }\n interface RouterEvents {\n onInjectedHtml: {\n type: 'onInjectedHtml'\n }\n onSerializationFinished: {\n type: 'onSerializationFinished'\n }\n }\n}\n\nconst SCOPE_ID = 'tsr'\n\nconst TSR_PREFIX = GLOBAL_TSR + '.router='\nconst P_PREFIX = GLOBAL_TSR + '.p(()=>'\nconst P_SUFFIX = ')'\n\nexport function dehydrateMatch(match: AnyRouteMatch): DehydratedMatch {\n const dehydratedMatch: DehydratedMatch = {\n i: dehydrateSsrMatchId(match.id),\n u: match.updatedAt,\n s: match.status,\n }\n\n const properties = [\n ['__beforeLoadContext', 'b'],\n ['loaderData', 'l'],\n ['error', 'e'],\n ['ssr', 'ssr'],\n ] as const\n\n for (const [key, shorthand] of properties) {\n if (match[key] !== undefined) {\n dehydratedMatch[shorthand] = match[key]\n }\n }\n if (match.globalNotFound) {\n dehydratedMatch.g = true\n }\n return dehydratedMatch\n}\n\nconst INITIAL_SCRIPTS = [\n getCrossReferenceHeader(SCOPE_ID),\n minifiedTsrBootStrapScript,\n]\n\nclass ScriptBuffer {\n private router: AnyRouter | undefined\n private _queue: Array<string>\n private _scriptBarrierLifted = false\n private _cleanedUp = false\n private _pendingMicrotask = false\n\n constructor(router: AnyRouter) {\n this.router = router\n // Copy INITIAL_SCRIPTS to avoid mutating the shared array\n this._queue = INITIAL_SCRIPTS.slice()\n }\n\n enqueue(script: string) {\n if (this._cleanedUp) return\n this._queue.push(script)\n // If barrier is lifted, schedule injection (if not already scheduled)\n if (this._scriptBarrierLifted && !this._pendingMicrotask) {\n this._pendingMicrotask = true\n queueMicrotask(() => {\n this._pendingMicrotask = false\n this.injectBufferedScripts()\n })\n }\n }\n\n liftBarrier() {\n if (this._scriptBarrierLifted || this._cleanedUp) return\n this._scriptBarrierLifted = true\n if (this._queue.length > 0 && !this._pendingMicrotask) {\n this._pendingMicrotask = true\n queueMicrotask(() => {\n this._pendingMicrotask = false\n this.injectBufferedScripts()\n })\n }\n }\n\n /**\n * Flushes any pending scripts synchronously.\n * Call this before emitting onSerializationFinished to ensure all scripts are injected.\n *\n * IMPORTANT: Only injects if the barrier has been lifted. Before the barrier is lifted,\n * scripts should remain in the queue so takeBufferedScripts() can retrieve them\n */\n flush() {\n if (!this._scriptBarrierLifted) return\n if (this._cleanedUp) return\n this._pendingMicrotask = false\n const scriptsToInject = this.takeAll()\n if (scriptsToInject && this.router?.serverSsr) {\n this.router.serverSsr.injectScript(scriptsToInject)\n }\n }\n\n takeAll() {\n const bufferedScripts = this._queue\n this._queue = []\n if (bufferedScripts.length === 0) {\n return undefined\n }\n // Optimization: if only one script, avoid join\n if (bufferedScripts.length === 1) {\n return bufferedScripts[0] + ';document.currentScript.remove()'\n }\n // Append cleanup script and join - avoid push() to not mutate then iterate\n return bufferedScripts.join(';') + ';document.currentScript.remove()'\n }\n\n injectBufferedScripts() {\n if (this._cleanedUp) return\n // Early return if queue is empty (avoids unnecessary takeAll() call)\n if (this._queue.length === 0) return\n const scriptsToInject = this.takeAll()\n if (scriptsToInject && this.router?.serverSsr) {\n this.router.serverSsr.injectScript(scriptsToInject)\n }\n }\n\n cleanup() {\n this._cleanedUp = true\n this._queue = []\n this.router = undefined\n }\n}\n\nconst isProd = process.env.NODE_ENV === 'production'\n\ntype FilteredRoutes = Manifest['routes']\n\ntype ManifestLRU = LRUCache<string, FilteredRoutes>\n\nconst MANIFEST_CACHE_SIZE = 100\nconst manifestCaches = new WeakMap<Manifest, ManifestLRU>()\n\nfunction getManifestCache(manifest: Manifest): ManifestLRU {\n const cache = manifestCaches.get(manifest)\n if (cache) return cache\n const newCache = createLRUCache<string, FilteredRoutes>(MANIFEST_CACHE_SIZE)\n manifestCaches.set(manifest, newCache)\n return newCache\n}\n\nexport function attachRouterServerSsrUtils({\n router,\n manifest,\n getRequestAssets,\n includeUnmatchedRouteAssets = true,\n}: {\n router: AnyRouter\n manifest: Manifest | undefined\n getRequestAssets?: () => Array<RouterManagedTag> | undefined\n includeUnmatchedRouteAssets?: boolean\n}) {\n router.ssr = {\n get manifest() {\n const requestAssets = getRequestAssets?.()\n if (!requestAssets?.length) return manifest\n // Merge request-scoped assets into root route without mutating cached manifest\n return {\n ...manifest,\n routes: {\n ...manifest?.routes,\n [rootRouteId]: {\n ...manifest?.routes?.[rootRouteId],\n assets: [\n ...requestAssets,\n ...(manifest?.routes?.[rootRouteId]?.assets ?? []),\n ],\n },\n },\n }\n },\n }\n let _dehydrated = false\n let _serializationFinished = false\n const renderFinishedListeners: Array<() => void> = []\n const serializationFinishedListeners: Array<() => void> = []\n const scriptBuffer = new ScriptBuffer(router)\n let injectedHtmlBuffer = ''\n\n router.serverSsr = {\n injectHtml: (html: string) => {\n if (!html) return\n // Buffer the HTML so it can be retrieved via takeBufferedHtml()\n injectedHtmlBuffer += html\n // Emit event to notify subscribers that new HTML is available\n router.emit({\n type: 'onInjectedHtml',\n })\n },\n injectScript: (script: string) => {\n if (!script) return\n const html = `<script${router.options.ssr?.nonce ? ` nonce='${router.options.ssr.nonce}'` : ''}>${script}</script>`\n router.serverSsr!.injectHtml(html)\n },\n dehydrate: async (opts?: { requestAssets?: Array<RouterManagedTag> }) => {\n if (_dehydrated) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Invariant failed: router is already dehydrated!')\n }\n\n invariant()\n }\n let matchesToDehydrate = router.stores.matches.get()\n if (router.isShell()) {\n // In SPA mode we only want to dehydrate the root match\n matchesToDehydrate = matchesToDehydrate.slice(0, 1)\n }\n const matches = matchesToDehydrate.map(dehydrateMatch)\n\n let manifestToDehydrate: Manifest | undefined = undefined\n // For currently matched routes, send full manifest (preloads + assets).\n // For unmatched routes, include assets only when includeUnmatchedRouteAssets\n // is true; otherwise omit them entirely. Preloads for unmatched routes are\n // still excluded because they are handled via dynamic imports.\n if (manifest) {\n // Prod-only caching; in dev manifests may be replaced/updated (HMR)\n const currentRouteIdsList = matchesToDehydrate.map((m) => m.routeId)\n const manifestCacheKey = `${currentRouteIdsList.join('\\0')}\\0includeUnmatchedRouteAssets=${includeUnmatchedRouteAssets}`\n\n let filteredRoutes: FilteredRoutes | undefined\n\n if (isProd) {\n filteredRoutes = getManifestCache(manifest).get(manifestCacheKey)\n }\n\n if (!filteredRoutes) {\n const currentRouteIds = new Set(currentRouteIdsList)\n const nextFilteredRoutes: FilteredRoutes = {}\n\n for (const routeId in manifest.routes) {\n const routeManifest = manifest.routes[routeId]!\n if (currentRouteIds.has(routeId)) {\n nextFilteredRoutes[routeId] = routeManifest\n } else if (\n includeUnmatchedRouteAssets &&\n routeManifest.assets &&\n routeManifest.assets.length > 0\n ) {\n nextFilteredRoutes[routeId] = {\n assets: routeManifest.assets,\n }\n }\n }\n\n if (isProd) {\n getManifestCache(manifest).set(manifestCacheKey, nextFilteredRoutes)\n }\n\n filteredRoutes = nextFilteredRoutes\n }\n\n manifestToDehydrate = {\n routes: filteredRoutes,\n }\n\n // Merge request-scoped assets into root route (without mutating cached manifest)\n if (opts?.requestAssets?.length) {\n const existingRoot = manifestToDehydrate.routes[rootRouteId]\n manifestToDehydrate.routes[rootRouteId] = {\n ...existingRoot,\n assets: [...opts.requestAssets, ...(existingRoot?.assets ?? [])],\n }\n }\n }\n const dehydratedRouter: DehydratedRouter = {\n manifest: manifestToDehydrate,\n matches,\n }\n const lastMatchId = matchesToDehydrate[matchesToDehydrate.length - 1]?.id\n if (lastMatchId) {\n dehydratedRouter.lastMatchId = dehydrateSsrMatchId(lastMatchId)\n }\n const dehydratedData = await router.options.dehydrate?.()\n if (dehydratedData) {\n dehydratedRouter.dehydratedData = dehydratedData\n }\n _dehydrated = true\n\n const trackPlugins = { didRun: false }\n const serializationAdapters = router.options.serializationAdapters as\n | Array<AnySerializationAdapter>\n | undefined\n const plugins = serializationAdapters\n ? serializationAdapters\n .map((t) => makeSsrSerovalPlugin(t, trackPlugins))\n .concat(defaultSerovalPlugins)\n : defaultSerovalPlugins\n\n const signalSerializationComplete = () => {\n _serializationFinished = true\n try {\n serializationFinishedListeners.forEach((l) => l())\n router.emit({ type: 'onSerializationFinished' })\n } catch (err) {\n console.error('Serialization listener error:', err)\n } finally {\n serializationFinishedListeners.length = 0\n renderFinishedListeners.length = 0\n }\n }\n\n crossSerializeStream(dehydratedRouter, {\n refs: new Map(),\n plugins,\n onSerialize: (data, initial) => {\n let serialized = initial ? TSR_PREFIX + data : data\n if (trackPlugins.didRun) {\n serialized = P_PREFIX + serialized + P_SUFFIX\n }\n scriptBuffer.enqueue(serialized)\n },\n onError: (err: unknown) => {\n console.error('Serialization error:', err)\n if (err && (err as any).stack) {\n console.error((err as any).stack)\n }\n signalSerializationComplete()\n },\n scopeId: SCOPE_ID,\n onDone: () => {\n scriptBuffer.enqueue(GLOBAL_TSR + '.e()')\n // Flush all pending scripts synchronously before signaling completion\n // This ensures all scripts are injected before onSerializationFinished is emitted\n scriptBuffer.flush()\n signalSerializationComplete()\n },\n })\n },\n isDehydrated() {\n return _dehydrated\n },\n isSerializationFinished() {\n return _serializationFinished\n },\n onRenderFinished: (listener) => renderFinishedListeners.push(listener),\n onSerializationFinished: (listener) =>\n serializationFinishedListeners.push(listener),\n setRenderFinished: () => {\n // Wrap in try-catch to ensure scriptBuffer.liftBarrier() is always called\n try {\n renderFinishedListeners.forEach((l) => l())\n } catch (err) {\n console.error('Error in render finished listener:', err)\n } finally {\n // Clear listeners after calling them to prevent memory leaks\n renderFinishedListeners.length = 0\n }\n scriptBuffer.liftBarrier()\n },\n takeBufferedScripts() {\n const scripts = scriptBuffer.takeAll()\n const serverBufferedScript: RouterManagedTag = {\n tag: 'script',\n attrs: {\n nonce: router.options.ssr?.nonce,\n className: '$tsr',\n id: TSR_SCRIPT_BARRIER_ID,\n },\n children: scripts,\n }\n return serverBufferedScript\n },\n liftScriptBarrier() {\n scriptBuffer.liftBarrier()\n },\n takeBufferedHtml() {\n if (!injectedHtmlBuffer) {\n return undefined\n }\n const buffered = injectedHtmlBuffer\n injectedHtmlBuffer = ''\n return buffered\n },\n cleanup() {\n // Guard against multiple cleanup calls\n if (!router.serverSsr) return\n renderFinishedListeners.length = 0\n serializationFinishedListeners.length = 0\n injectedHtmlBuffer = ''\n scriptBuffer.cleanup()\n router.serverSsr = undefined\n },\n }\n}\n\n/**\n * Get the origin for the request.\n *\n * SECURITY: We intentionally do NOT trust the Origin header for determining\n * the router's origin. The Origin header can be spoofed by attackers, which\n * could lead to SSRF-like vulnerabilities where redirects are constructed\n * using a malicious origin (CVE-2024-34351).\n *\n * Instead, we derive the origin from request.url, which is typically set by\n * the server infrastructure (not client-controlled headers).\n *\n * For applications behind proxies that need to trust forwarded headers,\n * use the router's `origin` option to explicitly configure a trusted origin.\n */\nexport function getOrigin(request: Request) {\n try {\n return new URL(request.url).origin\n } catch {}\n return 'http://localhost'\n}\n\n// server and browser can decode/encode characters differently in paths and search params.\n// Server generally strictly follows the WHATWG URL Standard, while browsers may differ for legacy reasons.\n// for example, in paths \"|\" is not encoded on the server but is encoded on chromium (and not on firefox) while \"대\" is encoded on both sides.\n// Another anomaly is that in Node new URLSearchParams and new URL also decode/encode characters differently.\n// new URLSearchParams() encodes \"|\" while new URL() does not, and in this instance\n// chromium treats search params differently than paths, i.e. \"|\" is not encoded in search params.\nexport function getNormalizedURL(url: string | URL, base?: string | URL) {\n // ensure backslashes are encoded correctly in the URL\n if (typeof url === 'string') url = url.replace('\\\\', '%5C')\n\n const rawUrl = new URL(url, base)\n const { path: decodedPathname, handledProtocolRelativeURL } = decodePath(\n rawUrl.pathname,\n )\n const searchParams = new URLSearchParams(rawUrl.search)\n const normalizedHref =\n decodedPathname +\n (searchParams.size > 0 ? '?' : '') +\n searchParams.toString() +\n rawUrl.hash\n\n return {\n url: new URL(normalizedHref, rawUrl.origin),\n handledProtocolRelativeURL,\n }\n}\n"],"mappings":";;;;;;;;;;;AAgCA,IAAM,WAAW;AAEjB,IA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I,MAAM,MAC/B,aAAa,UAAU,GACvB,OAAO;AAET,QAAO;EACL,KAAK,IAAI,IAAI,gBAAgB,OAAO,OAAO;EAC3C;EACD"}
|
|
1
|
+
{"version":3,"file":"ssr-server.cjs","names":[],"sources":["../../../src/ssr/ssr-server.ts"],"sourcesContent":["import { crossSerializeStream, getCrossReferenceHeader } from 'seroval'\nimport { invariant } from '../invariant'\nimport {\n createInlineCssPlaceholderAsset,\n createInlineCssStyleAsset,\n getStylesheetHref,\n isInlinableStylesheet,\n} from '../manifest'\nimport { decodePath } from '../utils'\nimport { createLRUCache } from '../lru-cache'\nimport { rootRouteId } from '../root'\nimport minifiedTsrBootStrapScript from './tsrScript?script-string'\nimport { GLOBAL_TSR, TSR_SCRIPT_BARRIER_ID } from './constants'\nimport { dehydrateSsrMatchId } from './ssr-match-id'\nimport { defaultSerovalPlugins } from './serializer/seroval-plugins'\nimport { makeSsrSerovalPlugin } from './serializer/transformer'\nimport type { LRUCache } from '../lru-cache'\nimport type { DehydratedMatch, DehydratedRouter } from './types'\nimport type { AnySerializationAdapter } from './serializer/transformer'\nimport type { AnyRouter } from '../router'\nimport type { AnyRouteMatch } from '../Matches'\nimport type { Manifest, RouterManagedTag } from '../manifest'\n\ndeclare module '../router' {\n interface ServerSsr {\n setRenderFinished: () => void\n cleanup: () => void\n }\n interface RouterEvents {\n onInjectedHtml: {\n type: 'onInjectedHtml'\n }\n onSerializationFinished: {\n type: 'onSerializationFinished'\n }\n }\n}\n\nconst SCOPE_ID = 'tsr'\n\nconst TSR_PREFIX = GLOBAL_TSR + '.router='\nconst P_PREFIX = GLOBAL_TSR + '.p(()=>'\nconst P_SUFFIX = ')'\n\nexport function dehydrateMatch(match: AnyRouteMatch): DehydratedMatch {\n const dehydratedMatch: DehydratedMatch = {\n i: dehydrateSsrMatchId(match.id),\n u: match.updatedAt,\n s: match.status,\n }\n\n const properties = [\n ['__beforeLoadContext', 'b'],\n ['loaderData', 'l'],\n ['error', 'e'],\n ['ssr', 'ssr'],\n ] as const\n\n for (const [key, shorthand] of properties) {\n if (match[key] !== undefined) {\n dehydratedMatch[shorthand] = match[key]\n }\n }\n if (match.globalNotFound) {\n dehydratedMatch.g = true\n }\n return dehydratedMatch\n}\n\nconst INITIAL_SCRIPTS = [\n getCrossReferenceHeader(SCOPE_ID),\n minifiedTsrBootStrapScript,\n]\n\nclass ScriptBuffer {\n private router: AnyRouter | undefined\n private _queue: Array<string>\n private _scriptBarrierLifted = false\n private _cleanedUp = false\n private _pendingMicrotask = false\n\n constructor(router: AnyRouter) {\n this.router = router\n // Copy INITIAL_SCRIPTS to avoid mutating the shared array\n this._queue = INITIAL_SCRIPTS.slice()\n }\n\n enqueue(script: string) {\n if (this._cleanedUp) return\n this._queue.push(script)\n // If barrier is lifted, schedule injection (if not already scheduled)\n if (this._scriptBarrierLifted && !this._pendingMicrotask) {\n this._pendingMicrotask = true\n queueMicrotask(() => {\n this._pendingMicrotask = false\n this.injectBufferedScripts()\n })\n }\n }\n\n liftBarrier() {\n if (this._scriptBarrierLifted || this._cleanedUp) return\n this._scriptBarrierLifted = true\n if (this._queue.length > 0 && !this._pendingMicrotask) {\n this._pendingMicrotask = true\n queueMicrotask(() => {\n this._pendingMicrotask = false\n this.injectBufferedScripts()\n })\n }\n }\n\n /**\n * Flushes any pending scripts synchronously.\n * Call this before emitting onSerializationFinished to ensure all scripts are injected.\n *\n * IMPORTANT: Only injects if the barrier has been lifted. Before the barrier is lifted,\n * scripts should remain in the queue so takeBufferedScripts() can retrieve them\n */\n flush() {\n if (!this._scriptBarrierLifted) return\n if (this._cleanedUp) return\n this._pendingMicrotask = false\n const scriptsToInject = this.takeAll()\n if (scriptsToInject && this.router?.serverSsr) {\n this.router.serverSsr.injectScript(scriptsToInject)\n }\n }\n\n takeAll() {\n const bufferedScripts = this._queue\n this._queue = []\n if (bufferedScripts.length === 0) {\n return undefined\n }\n // Optimization: if only one script, avoid join\n if (bufferedScripts.length === 1) {\n return bufferedScripts[0] + ';document.currentScript.remove()'\n }\n // Append cleanup script and join - avoid push() to not mutate then iterate\n return bufferedScripts.join(';') + ';document.currentScript.remove()'\n }\n\n injectBufferedScripts() {\n if (this._cleanedUp) return\n // Early return if queue is empty (avoids unnecessary takeAll() call)\n if (this._queue.length === 0) return\n const scriptsToInject = this.takeAll()\n if (scriptsToInject && this.router?.serverSsr) {\n this.router.serverSsr.injectScript(scriptsToInject)\n }\n }\n\n cleanup() {\n this._cleanedUp = true\n this._queue = []\n this.router = undefined\n }\n}\n\nconst isProd = process.env.NODE_ENV === 'production'\n\ntype FilteredRoutes = Manifest['routes']\n\ntype ManifestLRU = LRUCache<string, FilteredRoutes>\ntype InlineCssLRU = LRUCache<string, string>\n\nconst MANIFEST_CACHE_SIZE = 100\nconst manifestCaches = new WeakMap<Manifest, ManifestLRU>()\nconst inlineCssCaches = new WeakMap<Manifest, InlineCssLRU>()\n\nfunction getManifestCache(manifest: Manifest): ManifestLRU {\n const cache = manifestCaches.get(manifest)\n if (cache) return cache\n const newCache = createLRUCache<string, FilteredRoutes>(MANIFEST_CACHE_SIZE)\n manifestCaches.set(manifest, newCache)\n return newCache\n}\n\nfunction getInlineCssCache(manifest: Manifest): InlineCssLRU {\n const cache = inlineCssCaches.get(manifest)\n if (cache) return cache\n const newCache = createLRUCache<string, string>(MANIFEST_CACHE_SIZE)\n inlineCssCaches.set(manifest, newCache)\n return newCache\n}\n\nfunction getInlineCssHrefsForMatches(\n manifest: Manifest | undefined,\n matches: Array<AnyRouteMatch>,\n) {\n const styles = manifest?.inlineCss?.styles\n if (!styles) return []\n\n const seen = new Set<string>()\n const hrefs: Array<string> = []\n\n for (const match of matches) {\n const assets = manifest?.routes[match.routeId]?.assets ?? []\n for (const asset of assets) {\n const href = getStylesheetHref(asset)\n if (!href || seen.has(href) || styles[href] === undefined) {\n continue\n }\n seen.add(href)\n hrefs.push(href)\n }\n }\n\n return hrefs\n}\n\nfunction getInlineCssForHrefs(manifest: Manifest, hrefs: Array<string>) {\n const styles = manifest.inlineCss?.styles\n if (!styles || hrefs.length === 0) return undefined\n\n const cacheKey = hrefs.join('\\0')\n if (isProd) {\n const cached = getInlineCssCache(manifest).get(cacheKey)\n if (cached !== undefined) return cached\n }\n\n const css = hrefs.map((href) => styles[href]!).join('')\n\n if (isProd) {\n getInlineCssCache(manifest).set(cacheKey, css)\n }\n\n return css\n}\n\nfunction getInlineCssAssetForMatches(\n manifest: Manifest | undefined,\n matches: Array<AnyRouteMatch>,\n) {\n if (!manifest?.inlineCss) return undefined\n\n const hrefs = getInlineCssHrefsForMatches(manifest, matches)\n const css = getInlineCssForHrefs(manifest, hrefs)\n\n return css === undefined ? undefined : createInlineCssStyleAsset(css)\n}\n\nfunction stripInlinedStylesheetAssets(\n manifest: Manifest,\n routes: FilteredRoutes,\n matches: Array<AnyRouteMatch>,\n): FilteredRoutes {\n if (!manifest.inlineCss) {\n return routes\n }\n\n const nextRoutes: FilteredRoutes = {}\n\n for (const [routeId, route] of Object.entries(routes)) {\n const assets = route.assets?.filter(\n (asset) => !isInlinableStylesheet(manifest, asset),\n )\n\n const nextRoute = { ...route }\n if (assets) {\n if (assets.length > 0) {\n nextRoute.assets = assets\n } else {\n delete nextRoute.assets\n }\n }\n nextRoutes[routeId] = nextRoute\n }\n\n if (getInlineCssAssetForMatches(manifest, matches)) {\n const rootRoute = nextRoutes[rootRouteId] ?? {}\n nextRoutes[rootRouteId] = {\n ...rootRoute,\n assets: [createInlineCssPlaceholderAsset(), ...(rootRoute.assets ?? [])],\n }\n }\n\n return nextRoutes\n}\n\nexport function attachRouterServerSsrUtils({\n router,\n manifest,\n getRequestAssets,\n includeUnmatchedRouteAssets = true,\n}: {\n router: AnyRouter\n manifest: Manifest | undefined\n getRequestAssets?: () => Array<RouterManagedTag> | undefined\n includeUnmatchedRouteAssets?: boolean\n}) {\n router.ssr = {\n get manifest() {\n const requestAssets = getRequestAssets?.()\n const inlineCssAsset = getInlineCssAssetForMatches(\n manifest,\n router.stores.matches.get(),\n )\n if (!requestAssets?.length && !inlineCssAsset) return manifest\n // Merge request-scoped assets into root route without mutating cached manifest\n return {\n ...manifest,\n routes: {\n ...manifest?.routes,\n [rootRouteId]: {\n ...manifest?.routes?.[rootRouteId],\n assets: [\n ...(requestAssets ?? []),\n ...(inlineCssAsset ? [inlineCssAsset] : []),\n ...(manifest?.routes?.[rootRouteId]?.assets ?? []),\n ],\n },\n },\n }\n },\n }\n let _dehydrated = false\n let _serializationFinished = false\n const renderFinishedListeners: Array<() => void> = []\n const serializationFinishedListeners: Array<() => void> = []\n const scriptBuffer = new ScriptBuffer(router)\n let injectedHtmlBuffer = ''\n\n router.serverSsr = {\n injectHtml: (html: string) => {\n if (!html) return\n // Buffer the HTML so it can be retrieved via takeBufferedHtml()\n injectedHtmlBuffer += html\n // Emit event to notify subscribers that new HTML is available\n router.emit({\n type: 'onInjectedHtml',\n })\n },\n injectScript: (script: string) => {\n if (!script) return\n const html = `<script${router.options.ssr?.nonce ? ` nonce='${router.options.ssr.nonce}'` : ''}>${script}</script>`\n router.serverSsr!.injectHtml(html)\n },\n dehydrate: async (opts?: { requestAssets?: Array<RouterManagedTag> }) => {\n if (_dehydrated) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Invariant failed: router is already dehydrated!')\n }\n\n invariant()\n }\n let matchesToDehydrate = router.stores.matches.get()\n if (router.isShell()) {\n // In SPA mode we only want to dehydrate the root match\n matchesToDehydrate = matchesToDehydrate.slice(0, 1)\n }\n const matches = matchesToDehydrate.map(dehydrateMatch)\n\n let manifestToDehydrate: Manifest | undefined = undefined\n // For currently matched routes, send full manifest (preloads + assets).\n // For unmatched routes, include assets only when includeUnmatchedRouteAssets\n // is true; otherwise omit them entirely. Preloads for unmatched routes are\n // still excluded because they are handled via dynamic imports.\n if (manifest) {\n // Prod-only caching; in dev manifests may be replaced/updated (HMR)\n const currentRouteIdsList = matchesToDehydrate.map((m) => m.routeId)\n const manifestCacheKey = `${currentRouteIdsList.join('\\0')}\\0includeUnmatchedRouteAssets=${includeUnmatchedRouteAssets}`\n\n let filteredRoutes: FilteredRoutes | undefined\n\n if (isProd) {\n filteredRoutes = getManifestCache(manifest).get(manifestCacheKey)\n }\n\n if (!filteredRoutes) {\n const currentRouteIds = new Set(currentRouteIdsList)\n const nextFilteredRoutes: FilteredRoutes = {}\n\n for (const routeId in manifest.routes) {\n const routeManifest = manifest.routes[routeId]!\n if (currentRouteIds.has(routeId)) {\n nextFilteredRoutes[routeId] = routeManifest\n } else if (\n includeUnmatchedRouteAssets &&\n routeManifest.assets &&\n routeManifest.assets.length > 0\n ) {\n nextFilteredRoutes[routeId] = {\n assets: routeManifest.assets,\n }\n }\n }\n\n filteredRoutes = stripInlinedStylesheetAssets(\n manifest,\n nextFilteredRoutes,\n matchesToDehydrate,\n )\n\n if (isProd) {\n getManifestCache(manifest).set(manifestCacheKey, filteredRoutes)\n }\n }\n\n manifestToDehydrate = {\n routes: { ...filteredRoutes },\n }\n\n // Merge request-scoped assets into root route (without mutating cached manifest)\n if (opts?.requestAssets?.length) {\n const existingRoot = manifestToDehydrate.routes[rootRouteId]\n manifestToDehydrate.routes[rootRouteId] = {\n ...existingRoot,\n assets: [...opts.requestAssets, ...(existingRoot?.assets ?? [])],\n }\n }\n }\n const dehydratedRouter: DehydratedRouter = {\n manifest: manifestToDehydrate,\n matches,\n }\n const lastMatchId = matchesToDehydrate[matchesToDehydrate.length - 1]?.id\n if (lastMatchId) {\n dehydratedRouter.lastMatchId = dehydrateSsrMatchId(lastMatchId)\n }\n const dehydratedData = await router.options.dehydrate?.()\n if (dehydratedData) {\n dehydratedRouter.dehydratedData = dehydratedData\n }\n _dehydrated = true\n\n const trackPlugins = { didRun: false }\n const serializationAdapters = router.options.serializationAdapters as\n | Array<AnySerializationAdapter>\n | undefined\n const plugins = serializationAdapters\n ? serializationAdapters\n .map((t) => makeSsrSerovalPlugin(t, trackPlugins))\n .concat(defaultSerovalPlugins)\n : defaultSerovalPlugins\n\n const signalSerializationComplete = () => {\n _serializationFinished = true\n try {\n serializationFinishedListeners.forEach((l) => l())\n router.emit({ type: 'onSerializationFinished' })\n } catch (err) {\n console.error('Serialization listener error:', err)\n } finally {\n serializationFinishedListeners.length = 0\n renderFinishedListeners.length = 0\n }\n }\n\n crossSerializeStream(dehydratedRouter, {\n refs: new Map(),\n plugins,\n onSerialize: (data, initial) => {\n let serialized = initial ? TSR_PREFIX + data : data\n if (trackPlugins.didRun) {\n serialized = P_PREFIX + serialized + P_SUFFIX\n }\n scriptBuffer.enqueue(serialized)\n },\n onError: (err: unknown) => {\n console.error('Serialization error:', err)\n if (err && (err as any).stack) {\n console.error((err as any).stack)\n }\n signalSerializationComplete()\n },\n scopeId: SCOPE_ID,\n onDone: () => {\n scriptBuffer.enqueue(GLOBAL_TSR + '.e()')\n // Flush all pending scripts synchronously before signaling completion\n // This ensures all scripts are injected before onSerializationFinished is emitted\n scriptBuffer.flush()\n signalSerializationComplete()\n },\n })\n },\n isDehydrated() {\n return _dehydrated\n },\n isSerializationFinished() {\n return _serializationFinished\n },\n onRenderFinished: (listener) => renderFinishedListeners.push(listener),\n onSerializationFinished: (listener) =>\n serializationFinishedListeners.push(listener),\n setRenderFinished: () => {\n // Wrap in try-catch to ensure scriptBuffer.liftBarrier() is always called\n try {\n renderFinishedListeners.forEach((l) => l())\n } catch (err) {\n console.error('Error in render finished listener:', err)\n } finally {\n // Clear listeners after calling them to prevent memory leaks\n renderFinishedListeners.length = 0\n }\n scriptBuffer.liftBarrier()\n },\n takeBufferedScripts() {\n const scripts = scriptBuffer.takeAll()\n const serverBufferedScript: RouterManagedTag = {\n tag: 'script',\n attrs: {\n nonce: router.options.ssr?.nonce,\n className: '$tsr',\n id: TSR_SCRIPT_BARRIER_ID,\n },\n children: scripts,\n }\n return serverBufferedScript\n },\n liftScriptBarrier() {\n scriptBuffer.liftBarrier()\n },\n takeBufferedHtml() {\n if (!injectedHtmlBuffer) {\n return undefined\n }\n const buffered = injectedHtmlBuffer\n injectedHtmlBuffer = ''\n return buffered\n },\n cleanup() {\n // Guard against multiple cleanup calls\n if (!router.serverSsr) return\n renderFinishedListeners.length = 0\n serializationFinishedListeners.length = 0\n injectedHtmlBuffer = ''\n scriptBuffer.cleanup()\n router.serverSsr = undefined\n },\n }\n}\n\n/**\n * Get the origin for the request.\n *\n * SECURITY: We intentionally do NOT trust the Origin header for determining\n * the router's origin. The Origin header can be spoofed by attackers, which\n * could lead to SSRF-like vulnerabilities where redirects are constructed\n * using a malicious origin (CVE-2024-34351).\n *\n * Instead, we derive the origin from request.url, which is typically set by\n * the server infrastructure (not client-controlled headers).\n *\n * For applications behind proxies that need to trust forwarded headers,\n * use the router's `origin` option to explicitly configure a trusted origin.\n */\nexport function getOrigin(request: Request) {\n try {\n return new URL(request.url).origin\n } catch {}\n return 'http://localhost'\n}\n\n// server and browser can decode/encode characters differently in paths and search params.\n// Server generally strictly follows the WHATWG URL Standard, while browsers may differ for legacy reasons.\n// for example, in paths \"|\" is not encoded on the server but is encoded on chromium (and not on firefox) while \"대\" is encoded on both sides.\n// Another anomaly is that in Node new URLSearchParams and new URL also decode/encode characters differently.\n// new URLSearchParams() encodes \"|\" while new URL() does not, and in this instance\n// chromium treats search params differently than paths, i.e. \"|\" is not encoded in search params.\nexport function getNormalizedURL(url: string | URL, base?: string | URL) {\n // ensure backslashes are encoded correctly in the URL\n if (typeof url === 'string') url = url.replace('\\\\', '%5C')\n\n const rawUrl = new URL(url, base)\n const { path: decodedPathname, handledProtocolRelativeURL } = decodePath(\n rawUrl.pathname,\n )\n const searchParams = new URLSearchParams(rawUrl.search)\n const normalizedHref =\n decodedPathname +\n (searchParams.size > 0 ? '?' : '') +\n searchParams.toString() +\n rawUrl.hash\n\n return {\n url: new URL(normalizedHref, rawUrl.origin),\n handledProtocolRelativeURL,\n }\n}\n"],"mappings":";;;;;;;;;;;;AAsCA,IAAM,WAAW;AAEjB,IAAM,aAAa,kBAAA,aAAa;AAChC,IAAM,WAAW,kBAAA,aAAa;AAC9B,IAAM,WAAW;AAE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,kBAAA;KACL;IACD,UAAU;IACX;;EAGH,oBAAoB;AAClB,gBAAa,aAAa;;EAE5B,mBAAmB;AACjB,OAAI,CAAC,mBACH;GAEF,MAAM,WAAW;AACjB,wBAAqB;AACrB,UAAO;;EAET,UAAU;AAER,OAAI,CAAC,OAAO,UAAW;AACvB,2BAAwB,SAAS;AACjC,kCAA+B,SAAS;AACxC,wBAAqB;AACrB,gBAAa,SAAS;AACtB,UAAO,YAAY,KAAA;;EAEtB;;;;;;;;;;;;;;;;AAiBH,SAAgB,UAAU,SAAkB;AAC1C,KAAI;AACF,SAAO,IAAI,IAAI,QAAQ,IAAI,CAAC;SACtB;AACR,QAAO;;AAST,SAAgB,iBAAiB,KAAmB,MAAqB;AAEvE,KAAI,OAAO,QAAQ,SAAU,OAAM,IAAI,QAAQ,MAAM,MAAM;CAE3D,MAAM,SAAS,IAAI,IAAI,KAAK,KAAK;CACjC,MAAM,EAAE,MAAM,iBAAiB,+BAA+B,cAAA,WAC5D,OAAO,SACR;CACD,MAAM,eAAe,IAAI,gBAAgB,OAAO,OAAO;CACvD,MAAM,iBACJ,mBACC,aAAa,OAAO,IAAI,MAAM,MAC/B,aAAa,UAAU,GACvB,OAAO;AAET,QAAO;EACL,KAAK,IAAI,IAAI,gBAAgB,OAAO,OAAO;EAC3C;EACD"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export type { RouteToPath, TrailingSlashOptionByRouter, ParseRoute, CodeRouteToP
|
|
|
8
8
|
export type { InferFileRouteTypes, FileRouteTypes, FileRoutesByPath, CreateFileRoute, LazyRoute, LazyRouteOptions, CreateLazyFileRoute, } from './fileRoute.js';
|
|
9
9
|
export type { ParsedLocation } from './location.js';
|
|
10
10
|
export type { Manifest, RouterManagedTag, AssetCrossOrigin, AssetCrossOriginConfig, ManifestAssetLink, } from './manifest.js';
|
|
11
|
-
export { getAssetCrossOrigin, resolveManifestAssetLink } from './manifest.js';
|
|
11
|
+
export { createInlineCssStyleAsset, getAssetCrossOrigin, getStylesheetHref, isInlinableStylesheet, resolveManifestAssetLink, } from './manifest.js';
|
|
12
12
|
export { isMatch } from './Matches.js';
|
|
13
13
|
export type { AnyMatchAndValue, FindValueByIndex, FindValueByKey, CreateMatchAndValue, NextMatchAndValue, IsMatchKeyOf, IsMatchPath, IsMatchResult, IsMatchParse, IsMatch, RouteMatch, RouteMatchExtensions, MakeRouteMatchUnion, MakeRouteMatch, AnyRouteMatch, MakeRouteMatchFromRoute, MatchRouteOptions, } from './Matches.js';
|
|
14
14
|
export { joinPaths, cleanPath, trimPathLeft, trimPathRight, trimPath, removeTrailingSlash, exactPathTest, resolvePath, interpolatePath, } from './path.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import { createNonReactiveMutableStore, createNonReactiveReadonlyStore } from ".
|
|
|
12
12
|
import { PathParamError, RouterCore, SearchParamError, defaultSerializeError, getInitialRouterState, getLocationChangeInfo, getMatchedRoutes, lazyFn, trailingSlashOptions } from "./router.js";
|
|
13
13
|
import { TSR_DEFERRED_PROMISE, defer } from "./defer.js";
|
|
14
14
|
import { preloadWarning } from "./link.js";
|
|
15
|
-
import { getAssetCrossOrigin, resolveManifestAssetLink } from "./manifest.js";
|
|
15
|
+
import { createInlineCssStyleAsset, getAssetCrossOrigin, getStylesheetHref, isInlinableStylesheet, resolveManifestAssetLink } from "./manifest.js";
|
|
16
16
|
import { isMatch } from "./Matches.js";
|
|
17
17
|
import { BaseRootRoute, BaseRoute, BaseRouteApi } from "./route.js";
|
|
18
18
|
import { createRouterConfig } from "./config.js";
|
|
@@ -21,4 +21,4 @@ import { handleHashScroll } from "./hash-scroll.js";
|
|
|
21
21
|
import { createSerializationAdapter, makeSerovalPlugin, makeSsrSerovalPlugin } from "./ssr/serializer/transformer.js";
|
|
22
22
|
import { RawStream, createRawStreamDeserializePlugin, createRawStreamRPCPlugin } from "./ssr/serializer/RawStream.js";
|
|
23
23
|
import { defaultSerovalPlugins } from "./ssr/serializer/seroval-plugins.js";
|
|
24
|
-
export { BaseRootRoute, BaseRoute, BaseRouteApi, DEFAULT_PROTOCOL_ALLOWLIST, PathParamError, RawStream, RouterCore, SearchParamError, TSR_DEFERRED_PROMISE, buildDevStylesUrl, cleanPath, composeRewrites, createControlledPromise, createNonReactiveMutableStore, createNonReactiveReadonlyStore, createRawStreamDeserializePlugin, createRawStreamRPCPlugin, createRouterConfig, createSerializationAdapter, decode, deepEqual, defaultGetScrollRestorationKey, defaultParseSearch, defaultSerializeError, defaultSerovalPlugins, defaultStringifySearch, defer, encode, escapeHtml, exactPathTest, executeRewriteInput, functionalUpdate, getAssetCrossOrigin, getElementScrollRestorationEntry, getInitialRouterState, getLocationChangeInfo, getMatchedRoutes, handleHashScroll, interpolatePath, invariant, isDangerousProtocol, isMatch, isModuleNotFoundError, isNotFound, isPlainArray, isPlainObject, isRedirect, isResolvedRedirect, joinPaths, lazyFn, makeSerovalPlugin, makeSsrSerovalPlugin, notFound, parseRedirect, parseSearchWith, preloadWarning, redirect, removeTrailingSlash, replaceEqualDeep, resolveManifestAssetLink, resolvePath, retainSearchParams, rootRouteId, scrollRestorationCache, setupScrollRestoration, storageKey, stringifySearchWith, stripSearchParams, trailingSlashOptions, trimPath, trimPathLeft, trimPathRight };
|
|
24
|
+
export { BaseRootRoute, BaseRoute, BaseRouteApi, DEFAULT_PROTOCOL_ALLOWLIST, PathParamError, RawStream, RouterCore, SearchParamError, TSR_DEFERRED_PROMISE, buildDevStylesUrl, cleanPath, composeRewrites, createControlledPromise, createInlineCssStyleAsset, createNonReactiveMutableStore, createNonReactiveReadonlyStore, createRawStreamDeserializePlugin, createRawStreamRPCPlugin, createRouterConfig, createSerializationAdapter, decode, deepEqual, defaultGetScrollRestorationKey, defaultParseSearch, defaultSerializeError, defaultSerovalPlugins, defaultStringifySearch, defer, encode, escapeHtml, exactPathTest, executeRewriteInput, functionalUpdate, getAssetCrossOrigin, getElementScrollRestorationEntry, getInitialRouterState, getLocationChangeInfo, getMatchedRoutes, getStylesheetHref, handleHashScroll, interpolatePath, invariant, isDangerousProtocol, isInlinableStylesheet, isMatch, isModuleNotFoundError, isNotFound, isPlainArray, isPlainObject, isRedirect, isResolvedRedirect, joinPaths, lazyFn, makeSerovalPlugin, makeSsrSerovalPlugin, notFound, parseRedirect, parseSearchWith, preloadWarning, redirect, removeTrailingSlash, replaceEqualDeep, resolveManifestAssetLink, resolvePath, retainSearchParams, rootRouteId, scrollRestorationCache, setupScrollRestoration, storageKey, stringifySearchWith, stripSearchParams, trailingSlashOptions, trimPath, trimPathLeft, trimPathRight };
|
package/dist/esm/load-matches.js
CHANGED
|
@@ -59,7 +59,7 @@ var handleRedirectAndNotFound = (inner, match, err) => {
|
|
|
59
59
|
match._nonReactive.error = err;
|
|
60
60
|
inner.updateMatch(match.id, (prev) => ({
|
|
61
61
|
...prev,
|
|
62
|
-
status: isRedirect(err) ? "redirected" : prev.status === "pending" ? "success" : prev.status,
|
|
62
|
+
status: isRedirect(err) ? "redirected" : isNotFound(err) ? "notFound" : prev.status === "pending" ? "success" : prev.status,
|
|
63
63
|
context: buildMatchContext(inner, match.index),
|
|
64
64
|
isFetching: false,
|
|
65
65
|
error: err
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-matches.js","names":[],"sources":["../../src/load-matches.ts"],"sourcesContent":["import { isServer } from '@tanstack/router-core/isServer'\nimport { invariant } from './invariant'\nimport { createControlledPromise, isPromise } from './utils'\nimport { isNotFound } from './not-found'\nimport { rootRouteId } from './root'\nimport { isRedirect } from './redirect'\nimport type { NotFoundError } from './not-found'\nimport type { ParsedLocation } from './location'\nimport type {\n AnyRoute,\n BeforeLoadContextOptions,\n LoaderFnContext,\n SsrContextOptions,\n} from './route'\nimport type { AnyRouteMatch, MakeRouteMatch } from './Matches'\nimport type { AnyRouter, SSROption, UpdateMatchFn } from './router'\n\n/**\n * An object of this shape is created when calling `loadMatches`.\n * It contains everything we need for all other functions in this file\n * to work. (It's basically the function's argument, plus a few mutable states)\n */\ntype InnerLoadContext = {\n /** the calling router instance */\n router: AnyRouter\n location: ParsedLocation\n /** mutable state, scoped to a `loadMatches` call */\n firstBadMatchIndex?: number\n /** mutable state, scoped to a `loadMatches` call */\n rendered?: boolean\n serialError?: unknown\n updateMatch: UpdateMatchFn\n matches: Array<AnyRouteMatch>\n preload?: boolean\n forceStaleReload?: boolean\n onReady?: () => Promise<void>\n sync?: boolean\n}\n\nconst triggerOnReady = (inner: InnerLoadContext): void | Promise<void> => {\n if (!inner.rendered) {\n inner.rendered = true\n return inner.onReady?.()\n }\n}\n\nconst hasForcePendingActiveMatch = (router: AnyRouter): boolean => {\n return router.stores.matchesId.get().some((matchId) => {\n return router.stores.matchStores.get(matchId)?.get()._forcePending\n })\n}\n\nconst resolvePreload = (inner: InnerLoadContext, matchId: string): boolean => {\n return !!(inner.preload && !inner.router.stores.matchStores.has(matchId))\n}\n\n/**\n * Builds the accumulated context from router options and all matches up to (and optionally including) the given index.\n * Merges __routeContext and __beforeLoadContext from each match.\n */\nconst buildMatchContext = (\n inner: InnerLoadContext,\n index: number,\n includeCurrentMatch: boolean = true,\n): Record<string, unknown> => {\n const context: Record<string, unknown> = {\n ...(inner.router.options.context ?? {}),\n }\n const end = includeCurrentMatch ? index : index - 1\n for (let i = 0; i <= end; i++) {\n const innerMatch = inner.matches[i]\n if (!innerMatch) continue\n const m = inner.router.getMatch(innerMatch.id)\n if (!m) continue\n Object.assign(context, m.__routeContext, m.__beforeLoadContext)\n }\n return context\n}\n\nconst getNotFoundBoundaryIndex = (\n inner: InnerLoadContext,\n err: NotFoundError,\n): number | undefined => {\n if (!inner.matches.length) {\n return undefined\n }\n\n const requestedRouteId = err.routeId\n const matchedRootIndex = inner.matches.findIndex(\n (m) => m.routeId === inner.router.routeTree.id,\n )\n const rootIndex = matchedRootIndex >= 0 ? matchedRootIndex : 0\n\n let startIndex = requestedRouteId\n ? inner.matches.findIndex((match) => match.routeId === requestedRouteId)\n : (inner.firstBadMatchIndex ?? inner.matches.length - 1)\n\n if (startIndex < 0) {\n startIndex = rootIndex\n }\n\n for (let i = startIndex; i >= 0; i--) {\n const match = inner.matches[i]!\n const route = inner.router.looseRoutesById[match.routeId]!\n if (route.options.notFoundComponent) {\n return i\n }\n }\n\n // If no boundary component is found, preserve explicit routeId targeting behavior,\n // otherwise default to root for untargeted notFounds.\n return requestedRouteId ? startIndex : rootIndex\n}\n\nconst handleRedirectAndNotFound = (\n inner: InnerLoadContext,\n match: AnyRouteMatch | undefined,\n err: unknown,\n): void => {\n if (!isRedirect(err) && !isNotFound(err)) return\n\n if (isRedirect(err) && err.redirectHandled && !err.options.reloadDocument) {\n throw err\n }\n\n // in case of a redirecting match during preload, the match does not exist\n if (match) {\n match._nonReactive.beforeLoadPromise?.resolve()\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.beforeLoadPromise = undefined\n match._nonReactive.loaderPromise = undefined\n\n match._nonReactive.error = err\n\n inner.updateMatch(match.id, (prev) => ({\n ...prev,\n status: isRedirect(err)\n ? 'redirected'\n : prev.status === 'pending'\n ? 'success'\n : prev.status,\n context: buildMatchContext(inner, match.index),\n isFetching: false,\n error: err,\n }))\n\n if (isNotFound(err) && !err.routeId) {\n // Stamp the throwing match's routeId so that the finalization step in\n // loadMatches knows where the notFound originated. The actual boundary\n // resolution (walking up to the nearest notFoundComponent) is deferred to\n // the finalization step, where firstBadMatchIndex is stable and\n // headMaxIndex can be capped correctly.\n err.routeId = match.routeId\n }\n\n match._nonReactive.loadPromise?.resolve()\n }\n\n if (isRedirect(err)) {\n inner.rendered = true\n err.options._fromLocation = inner.location\n err.redirectHandled = true\n err = inner.router.resolveRedirect(err)\n }\n\n throw err\n}\n\nconst shouldSkipLoader = (\n inner: InnerLoadContext,\n matchId: string,\n): boolean => {\n const match = inner.router.getMatch(matchId)\n if (!match) {\n return true\n }\n // upon hydration, we skip the loader if the match has been dehydrated on the server\n if (!(isServer ?? inner.router.isServer) && match._nonReactive.dehydrated) {\n return true\n }\n\n if ((isServer ?? inner.router.isServer) && match.ssr === false) {\n return true\n }\n\n return false\n}\n\nconst syncMatchContext = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n): void => {\n const nextContext = buildMatchContext(inner, index)\n\n inner.updateMatch(matchId, (prev) => {\n return {\n ...prev,\n context: nextContext,\n }\n })\n}\n\nconst handleSerialError = (\n inner: InnerLoadContext,\n index: number,\n err: any,\n routerCode: string,\n): void => {\n const { id: matchId, routeId } = inner.matches[index]!\n const route = inner.router.looseRoutesById[routeId]!\n\n // Much like suspense, we use a promise here to know if\n // we've been outdated by a new loadMatches call and\n // should abort the current async operation\n if (err instanceof Promise) {\n throw err\n }\n\n err.routerCode = routerCode\n inner.firstBadMatchIndex ??= index\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), err)\n\n try {\n route.options.onError?.(err)\n } catch (errorHandlerErr) {\n err = errorHandlerErr\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), err)\n }\n\n inner.updateMatch(matchId, (prev) => {\n prev._nonReactive.beforeLoadPromise?.resolve()\n prev._nonReactive.beforeLoadPromise = undefined\n prev._nonReactive.loadPromise?.resolve()\n\n return {\n ...prev,\n error: err,\n status: 'error',\n isFetching: false,\n updatedAt: Date.now(),\n abortController: new AbortController(),\n }\n })\n\n if (!inner.preload && !isRedirect(err) && !isNotFound(err)) {\n inner.serialError ??= err\n }\n}\n\nconst isBeforeLoadSsr = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): void | Promise<void> => {\n const existingMatch = inner.router.getMatch(matchId)!\n const parentMatchId = inner.matches[index - 1]?.id\n const parentMatch = parentMatchId\n ? inner.router.getMatch(parentMatchId)!\n : undefined\n\n // in SPA mode, only SSR the root route\n if (inner.router.isShell()) {\n existingMatch.ssr = route.id === rootRouteId\n return\n }\n\n if (parentMatch?.ssr === false) {\n existingMatch.ssr = false\n return\n }\n\n const parentOverride = (tempSsr: SSROption) => {\n if (tempSsr === true && parentMatch?.ssr === 'data-only') {\n return 'data-only'\n }\n return tempSsr\n }\n\n const defaultSsr = inner.router.options.defaultSsr ?? true\n\n if (route.options.ssr === undefined) {\n existingMatch.ssr = parentOverride(defaultSsr)\n return\n }\n\n if (typeof route.options.ssr !== 'function') {\n existingMatch.ssr = parentOverride(route.options.ssr)\n return\n }\n const { search, params } = existingMatch\n\n const ssrFnContext: SsrContextOptions<any, any, any> = {\n search: makeMaybe(search, existingMatch.searchError),\n params: makeMaybe(params, existingMatch.paramsError),\n location: inner.location,\n matches: inner.matches.map((match) => ({\n index: match.index,\n pathname: match.pathname,\n fullPath: match.fullPath,\n staticData: match.staticData,\n id: match.id,\n routeId: match.routeId,\n search: makeMaybe(match.search, match.searchError),\n params: makeMaybe(match.params, match.paramsError),\n ssr: match.ssr,\n })),\n }\n\n const tempSsr = route.options.ssr(ssrFnContext)\n if (isPromise(tempSsr)) {\n return tempSsr.then((ssr) => {\n existingMatch.ssr = parentOverride(ssr ?? defaultSsr)\n })\n }\n\n existingMatch.ssr = parentOverride(tempSsr ?? defaultSsr)\n return\n}\n\nconst setupPendingTimeout = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n match: AnyRouteMatch,\n): void => {\n if (match._nonReactive.pendingTimeout !== undefined) return\n\n const pendingMs =\n route.options.pendingMs ?? inner.router.options.defaultPendingMs\n const shouldPending = !!(\n inner.onReady &&\n !(isServer ?? inner.router.isServer) &&\n !resolvePreload(inner, matchId) &&\n (route.options.loader ||\n route.options.beforeLoad ||\n routeNeedsPreload(route)) &&\n typeof pendingMs === 'number' &&\n pendingMs !== Infinity &&\n (route.options.pendingComponent ??\n (inner.router.options as any)?.defaultPendingComponent)\n )\n\n if (shouldPending) {\n const pendingTimeout = setTimeout(() => {\n // Update the match and prematurely resolve the loadMatches promise so that\n // the pending component can start rendering\n triggerOnReady(inner)\n }, pendingMs)\n match._nonReactive.pendingTimeout = pendingTimeout\n }\n}\n\nconst preBeforeLoadSetup = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n): void | Promise<void> => {\n const existingMatch = inner.router.getMatch(matchId)!\n\n // If we are in the middle of a load, either of these will be present\n // (not to be confused with `loadPromise`, which is always defined)\n if (\n !existingMatch._nonReactive.beforeLoadPromise &&\n !existingMatch._nonReactive.loaderPromise\n )\n return\n\n setupPendingTimeout(inner, matchId, route, existingMatch)\n\n const then = () => {\n const match = inner.router.getMatch(matchId)!\n if (\n match.preload &&\n (match.status === 'redirected' || match.status === 'notFound')\n ) {\n handleRedirectAndNotFound(inner, match, match.error)\n }\n }\n\n // Wait for the previous beforeLoad to resolve before we continue\n return existingMatch._nonReactive.beforeLoadPromise\n ? existingMatch._nonReactive.beforeLoadPromise.then(then)\n : then()\n}\n\nconst executeBeforeLoad = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): void | Promise<void> => {\n const match = inner.router.getMatch(matchId)!\n\n // explicitly capture the previous loadPromise\n let prevLoadPromise = match._nonReactive.loadPromise\n match._nonReactive.loadPromise = createControlledPromise<void>(() => {\n prevLoadPromise?.resolve()\n prevLoadPromise = undefined\n })\n\n const { paramsError, searchError } = match\n\n if (paramsError) {\n handleSerialError(inner, index, paramsError, 'PARSE_PARAMS')\n }\n\n if (searchError) {\n handleSerialError(inner, index, searchError, 'VALIDATE_SEARCH')\n }\n\n setupPendingTimeout(inner, matchId, route, match)\n\n const abortController = new AbortController()\n\n let isPending = false\n const pending = () => {\n if (isPending) return\n isPending = true\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: 'beforeLoad',\n fetchCount: prev.fetchCount + 1,\n abortController,\n // Note: We intentionally don't update context here.\n // Context should only be updated after beforeLoad resolves to avoid\n // components seeing incomplete context during async beforeLoad execution.\n }))\n }\n\n const resolve = () => {\n match._nonReactive.beforeLoadPromise?.resolve()\n match._nonReactive.beforeLoadPromise = undefined\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: false,\n }))\n }\n\n // if there is no `beforeLoad` option, just mark as pending and resolve\n // Context will be updated later in loadRouteMatch after loader completes\n if (!route.options.beforeLoad) {\n inner.router.batch(() => {\n pending()\n resolve()\n })\n return\n }\n\n match._nonReactive.beforeLoadPromise = createControlledPromise<void>()\n\n // Build context from all parent matches, excluding current match's __beforeLoadContext\n // (since we're about to execute beforeLoad for this match)\n const context = {\n ...buildMatchContext(inner, index, false),\n ...match.__routeContext,\n }\n const { search, params, cause } = match\n const preload = resolvePreload(inner, matchId)\n const beforeLoadFnContext: BeforeLoadContextOptions<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n > = {\n search,\n abortController,\n params,\n preload,\n context,\n location: inner.location,\n navigate: (opts: any) =>\n inner.router.navigate({\n ...opts,\n _fromLocation: inner.location,\n }),\n buildLocation: inner.router.buildLocation,\n cause: preload ? 'preload' : cause,\n matches: inner.matches,\n routeId: route.id,\n ...inner.router.options.additionalContext,\n }\n\n const updateContext = (beforeLoadContext: any) => {\n if (beforeLoadContext === undefined) {\n inner.router.batch(() => {\n pending()\n resolve()\n })\n return\n }\n if (isRedirect(beforeLoadContext) || isNotFound(beforeLoadContext)) {\n pending()\n handleSerialError(inner, index, beforeLoadContext, 'BEFORE_LOAD')\n }\n\n inner.router.batch(() => {\n pending()\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n __beforeLoadContext: beforeLoadContext,\n }))\n resolve()\n })\n }\n\n let beforeLoadContext\n try {\n beforeLoadContext = route.options.beforeLoad(beforeLoadFnContext)\n if (isPromise(beforeLoadContext)) {\n pending()\n return beforeLoadContext\n .catch((err) => {\n handleSerialError(inner, index, err, 'BEFORE_LOAD')\n })\n .then(updateContext)\n }\n } catch (err) {\n pending()\n handleSerialError(inner, index, err, 'BEFORE_LOAD')\n }\n\n updateContext(beforeLoadContext)\n return\n}\n\nconst handleBeforeLoad = (\n inner: InnerLoadContext,\n index: number,\n): void | Promise<void> => {\n const { id: matchId, routeId } = inner.matches[index]!\n const route = inner.router.looseRoutesById[routeId]!\n\n const serverSsr = () => {\n // on the server, determine whether SSR the current match or not\n if (isServer ?? inner.router.isServer) {\n const maybePromise = isBeforeLoadSsr(inner, matchId, index, route)\n if (isPromise(maybePromise)) return maybePromise.then(queueExecution)\n }\n return queueExecution()\n }\n\n const execute = () => executeBeforeLoad(inner, matchId, index, route)\n\n const queueExecution = () => {\n if (shouldSkipLoader(inner, matchId)) return\n const result = preBeforeLoadSetup(inner, matchId, route)\n return isPromise(result) ? result.then(execute) : execute()\n }\n\n return serverSsr()\n}\n\nconst executeHead = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n): void | Promise<\n Pick<\n AnyRouteMatch,\n 'meta' | 'links' | 'headScripts' | 'headers' | 'scripts' | 'styles'\n >\n> => {\n const match = inner.router.getMatch(matchId)\n // in case of a redirecting match during preload, the match does not exist\n if (!match) {\n return\n }\n if (!route.options.head && !route.options.scripts && !route.options.headers) {\n return\n }\n const assetContext = {\n ssr: inner.router.options.ssr,\n matches: inner.matches,\n match,\n params: match.params,\n loaderData: match.loaderData,\n }\n\n return Promise.all([\n route.options.head?.(assetContext),\n route.options.scripts?.(assetContext),\n route.options.headers?.(assetContext),\n ]).then(([headFnContent, scripts, headers]) => {\n const meta = headFnContent?.meta\n const links = headFnContent?.links\n const headScripts = headFnContent?.scripts\n const styles = headFnContent?.styles\n\n return {\n meta,\n links,\n headScripts,\n headers,\n scripts,\n styles,\n }\n })\n}\n\nconst getLoaderContext = (\n inner: InnerLoadContext,\n matchPromises: Array<Promise<AnyRouteMatch>>,\n matchId: string,\n index: number,\n route: AnyRoute,\n): LoaderFnContext => {\n const parentMatchPromise = matchPromises[index - 1] as any\n const { params, loaderDeps, abortController, cause } =\n inner.router.getMatch(matchId)!\n\n const context = buildMatchContext(inner, index)\n\n const preload = resolvePreload(inner, matchId)\n\n return {\n params,\n deps: loaderDeps,\n preload: !!preload,\n parentMatchPromise,\n abortController,\n context,\n location: inner.location,\n navigate: (opts) =>\n inner.router.navigate({\n ...opts,\n _fromLocation: inner.location,\n }),\n cause: preload ? 'preload' : cause,\n route,\n ...inner.router.options.additionalContext,\n }\n}\n\nconst runLoader = async (\n inner: InnerLoadContext,\n matchPromises: Array<Promise<AnyRouteMatch>>,\n matchId: string,\n index: number,\n route: AnyRoute,\n): Promise<void> => {\n try {\n // If the Matches component rendered\n // the pending component and needs to show it for\n // a minimum duration, we''ll wait for it to resolve\n // before committing to the match and resolving\n // the loadPromise\n\n const match = inner.router.getMatch(matchId)!\n\n // Actually run the loader and handle the result\n try {\n if (!(isServer ?? inner.router.isServer) || match.ssr === true) {\n loadRouteChunk(route)\n }\n\n // Kick off the loader!\n const routeLoader = route.options.loader\n const loader =\n typeof routeLoader === 'function' ? routeLoader : routeLoader?.handler\n const loaderResult = loader?.(\n getLoaderContext(inner, matchPromises, matchId, index, route),\n )\n const loaderResultIsPromise = !!loader && isPromise(loaderResult)\n\n const willLoadSomething = !!(\n loaderResultIsPromise ||\n route._lazyPromise ||\n route._componentsPromise ||\n route.options.head ||\n route.options.scripts ||\n route.options.headers ||\n match._nonReactive.minPendingPromise\n )\n\n if (willLoadSomething) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: 'loader',\n }))\n }\n\n if (loader) {\n const loaderData = loaderResultIsPromise\n ? await loaderResult\n : loaderResult\n\n handleRedirectAndNotFound(\n inner,\n inner.router.getMatch(matchId),\n loaderData,\n )\n if (loaderData !== undefined) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n loaderData,\n }))\n }\n }\n\n // Lazy option can modify the route options,\n // so we need to wait for it to resolve before\n // we can use the options\n if (route._lazyPromise) await route._lazyPromise\n const pendingPromise = match._nonReactive.minPendingPromise\n if (pendingPromise) await pendingPromise\n\n // Last but not least, wait for the the components\n // to be preloaded before we resolve the match\n if (route._componentsPromise) await route._componentsPromise\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n error: undefined,\n context: buildMatchContext(inner, index),\n status: 'success',\n isFetching: false,\n updatedAt: Date.now(),\n }))\n } catch (e) {\n let error = e\n\n if ((error as any)?.name === 'AbortError') {\n if (match.abortController.signal.aborted) {\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.loaderPromise = undefined\n return\n }\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n status: prev.status === 'pending' ? 'success' : prev.status,\n isFetching: false,\n context: buildMatchContext(inner, index),\n }))\n return\n }\n\n const pendingPromise = match._nonReactive.minPendingPromise\n if (pendingPromise) await pendingPromise\n\n if (isNotFound(e)) {\n await (route.options.notFoundComponent as any)?.preload?.()\n }\n\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), e)\n\n try {\n route.options.onError?.(e)\n } catch (onErrorError) {\n error = onErrorError\n handleRedirectAndNotFound(\n inner,\n inner.router.getMatch(matchId),\n onErrorError,\n )\n }\n if (!isRedirect(error) && !isNotFound(error)) {\n await loadRouteChunk(route, ['errorComponent'])\n }\n\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n error,\n context: buildMatchContext(inner, index),\n status: 'error',\n isFetching: false,\n }))\n }\n } catch (err) {\n const match = inner.router.getMatch(matchId)\n // in case of a redirecting match during preload, the match does not exist\n if (match) {\n match._nonReactive.loaderPromise = undefined\n }\n handleRedirectAndNotFound(inner, match, err)\n }\n}\n\nconst loadRouteMatch = async (\n inner: InnerLoadContext,\n matchPromises: Array<Promise<AnyRouteMatch>>,\n index: number,\n): Promise<AnyRouteMatch> => {\n async function handleLoader(\n preload: boolean,\n prevMatch: AnyRouteMatch,\n previousRouteMatchId: string | undefined,\n match: AnyRouteMatch,\n route: AnyRoute,\n ) {\n const age = Date.now() - prevMatch.updatedAt\n\n const staleAge = preload\n ? (route.options.preloadStaleTime ??\n inner.router.options.defaultPreloadStaleTime ??\n 30_000) // 30 seconds for preloads by default\n : (route.options.staleTime ?? inner.router.options.defaultStaleTime ?? 0)\n\n const shouldReloadOption = route.options.shouldReload\n\n // Default to reloading the route all the time\n // Allow shouldReload to get the last say,\n // if provided.\n const shouldReload =\n typeof shouldReloadOption === 'function'\n ? shouldReloadOption(\n getLoaderContext(inner, matchPromises, matchId, index, route),\n )\n : shouldReloadOption\n\n // If the route is successful and still fresh, just resolve\n const { status, invalid } = match\n const staleMatchShouldReload =\n age >= staleAge &&\n (!!inner.forceStaleReload ||\n match.cause === 'enter' ||\n (previousRouteMatchId !== undefined &&\n previousRouteMatchId !== match.id))\n loaderShouldRunAsync =\n status === 'success' &&\n (invalid || (shouldReload ?? staleMatchShouldReload))\n if (preload && route.options.preload === false) {\n // Do nothing\n } else if (\n loaderShouldRunAsync &&\n !inner.sync &&\n shouldReloadInBackground\n ) {\n loaderIsRunningAsync = true\n ;(async () => {\n try {\n await runLoader(inner, matchPromises, matchId, index, route)\n const match = inner.router.getMatch(matchId)!\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.loadPromise?.resolve()\n match._nonReactive.loaderPromise = undefined\n match._nonReactive.loadPromise = undefined\n } catch (err) {\n if (isRedirect(err)) {\n await inner.router.navigate(err.options)\n }\n }\n })()\n } else if (status !== 'success' || loaderShouldRunAsync) {\n await runLoader(inner, matchPromises, matchId, index, route)\n } else {\n syncMatchContext(inner, matchId, index)\n }\n }\n\n const { id: matchId, routeId } = inner.matches[index]!\n let loaderShouldRunAsync = false\n let loaderIsRunningAsync = false\n const route = inner.router.looseRoutesById[routeId]!\n const routeLoader = route.options.loader\n const shouldReloadInBackground =\n ((typeof routeLoader === 'function'\n ? undefined\n : routeLoader?.staleReloadMode) ??\n inner.router.options.defaultStaleReloadMode) !== 'blocking'\n\n if (shouldSkipLoader(inner, matchId)) {\n const match = inner.router.getMatch(matchId)\n if (!match) {\n return inner.matches[index]!\n }\n\n syncMatchContext(inner, matchId, index)\n\n if (isServer ?? inner.router.isServer) {\n return inner.router.getMatch(matchId)!\n }\n } else {\n const prevMatch = inner.router.getMatch(matchId)! // This is where all of the stale-while-revalidate magic happens\n const activeIdAtIndex = inner.router.stores.matchesId.get()[index]\n const activeAtIndex =\n (activeIdAtIndex &&\n inner.router.stores.matchStores.get(activeIdAtIndex)) ||\n null\n const previousRouteMatchId =\n activeAtIndex?.routeId === routeId\n ? activeIdAtIndex\n : inner.router.stores.matches.get().find((d) => d.routeId === routeId)\n ?.id\n const preload = resolvePreload(inner, matchId)\n\n // there is a loaderPromise, so we are in the middle of a load\n if (prevMatch._nonReactive.loaderPromise) {\n // do not block if we already have stale data we can show\n // but only if the ongoing load is not a preload since error handling is different for preloads\n // and we don't want to swallow errors\n if (\n prevMatch.status === 'success' &&\n !inner.sync &&\n !prevMatch.preload &&\n shouldReloadInBackground\n ) {\n return prevMatch\n }\n await prevMatch._nonReactive.loaderPromise\n const match = inner.router.getMatch(matchId)!\n const error = match._nonReactive.error || match.error\n if (error) {\n handleRedirectAndNotFound(inner, match, error)\n }\n\n if (match.status === 'pending') {\n await handleLoader(\n preload,\n prevMatch,\n previousRouteMatchId,\n match,\n route,\n )\n }\n } else {\n const nextPreload =\n preload && !inner.router.stores.matchStores.has(matchId)\n const match = inner.router.getMatch(matchId)!\n match._nonReactive.loaderPromise = createControlledPromise<void>()\n if (nextPreload !== match.preload) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n preload: nextPreload,\n }))\n }\n\n await handleLoader(preload, prevMatch, previousRouteMatchId, match, route)\n }\n }\n const match = inner.router.getMatch(matchId)!\n if (!loaderIsRunningAsync) {\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.loadPromise?.resolve()\n match._nonReactive.loadPromise = undefined\n }\n\n clearTimeout(match._nonReactive.pendingTimeout)\n match._nonReactive.pendingTimeout = undefined\n if (!loaderIsRunningAsync) match._nonReactive.loaderPromise = undefined\n match._nonReactive.dehydrated = undefined\n\n const nextIsFetching = loaderIsRunningAsync ? match.isFetching : false\n if (nextIsFetching !== match.isFetching || match.invalid !== false) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: nextIsFetching,\n invalid: false,\n }))\n return inner.router.getMatch(matchId)!\n } else {\n return match\n }\n}\n\nexport async function loadMatches(arg: {\n router: AnyRouter\n location: ParsedLocation\n matches: Array<AnyRouteMatch>\n preload?: boolean\n forceStaleReload?: boolean\n onReady?: () => Promise<void>\n updateMatch: UpdateMatchFn\n sync?: boolean\n}): Promise<Array<MakeRouteMatch>> {\n const inner: InnerLoadContext = arg\n const matchPromises: Array<Promise<AnyRouteMatch>> = []\n\n // make sure the pending component is immediately rendered when hydrating a match that is not SSRed\n // the pending component was already rendered on the server and we want to keep it shown on the client until minPendingMs is reached\n if (\n !(isServer ?? inner.router.isServer) &&\n hasForcePendingActiveMatch(inner.router)\n ) {\n triggerOnReady(inner)\n }\n\n let beforeLoadNotFound: NotFoundError | undefined\n\n // Execute all beforeLoads one by one\n for (let i = 0; i < inner.matches.length; i++) {\n try {\n const beforeLoad = handleBeforeLoad(inner, i)\n if (isPromise(beforeLoad)) await beforeLoad\n } catch (err) {\n if (isRedirect(err)) {\n throw err\n }\n if (isNotFound(err)) {\n beforeLoadNotFound = err\n } else {\n if (!inner.preload) throw err\n }\n break\n }\n\n if (inner.serialError || inner.firstBadMatchIndex != null) {\n break\n }\n }\n\n // Execute loaders once, with max index adapted for beforeLoad notFound handling.\n const baseMaxIndexExclusive = inner.firstBadMatchIndex ?? inner.matches.length\n\n const boundaryIndex =\n beforeLoadNotFound && !inner.preload\n ? getNotFoundBoundaryIndex(inner, beforeLoadNotFound)\n : undefined\n\n const maxIndexExclusive =\n beforeLoadNotFound && inner.preload\n ? 0\n : boundaryIndex !== undefined\n ? Math.min(boundaryIndex + 1, baseMaxIndexExclusive)\n : baseMaxIndexExclusive\n\n let firstNotFound: NotFoundError | undefined\n let firstUnhandledRejection: unknown\n\n for (let i = 0; i < maxIndexExclusive; i++) {\n matchPromises.push(loadRouteMatch(inner, matchPromises, i))\n }\n\n try {\n await Promise.all(matchPromises)\n } catch {\n const settled = await Promise.allSettled(matchPromises)\n\n for (const result of settled) {\n if (result.status !== 'rejected') continue\n\n const reason = result.reason\n if (isRedirect(reason)) {\n throw reason\n }\n if (isNotFound(reason)) {\n firstNotFound ??= reason\n } else {\n firstUnhandledRejection ??= reason\n }\n }\n\n if (firstUnhandledRejection !== undefined) {\n throw firstUnhandledRejection\n }\n }\n\n const notFoundToThrow =\n firstNotFound ??\n (beforeLoadNotFound && !inner.preload ? beforeLoadNotFound : undefined)\n\n let headMaxIndex =\n inner.firstBadMatchIndex !== undefined\n ? inner.firstBadMatchIndex\n : inner.matches.length - 1\n\n if (!notFoundToThrow && beforeLoadNotFound && inner.preload) {\n return inner.matches\n }\n\n if (notFoundToThrow) {\n // Determine once which matched route will actually render the\n // notFoundComponent, then pass this precomputed index through the remaining\n // finalization steps.\n // This can differ from the throwing route when routeId targets an ancestor\n // boundary (or when bubbling resolves to a parent/root boundary).\n const renderedBoundaryIndex = getNotFoundBoundaryIndex(\n inner,\n notFoundToThrow,\n )\n\n if (renderedBoundaryIndex === undefined) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n 'Invariant failed: Could not find match for notFound boundary',\n )\n }\n\n invariant()\n }\n const boundaryMatch = inner.matches[renderedBoundaryIndex]!\n\n const boundaryRoute = inner.router.looseRoutesById[boundaryMatch.routeId]!\n const defaultNotFoundComponent = (inner.router.options as any)\n ?.defaultNotFoundComponent\n\n // Ensure a notFoundComponent exists on the boundary route\n if (!boundaryRoute.options.notFoundComponent && defaultNotFoundComponent) {\n boundaryRoute.options.notFoundComponent = defaultNotFoundComponent\n }\n\n notFoundToThrow.routeId = boundaryMatch.routeId\n\n const boundaryIsRoot = boundaryMatch.routeId === inner.router.routeTree.id\n\n inner.updateMatch(boundaryMatch.id, (prev) => ({\n ...prev,\n ...(boundaryIsRoot\n ? // For root boundary, use globalNotFound so the root component's\n // shell still renders and <Outlet> handles the not-found display,\n // instead of replacing the entire root shell via status='notFound'.\n { status: 'success' as const, globalNotFound: true, error: undefined }\n : // For non-root boundaries, set status:'notFound' so MatchInner\n // renders the notFoundComponent directly.\n { status: 'notFound' as const, error: notFoundToThrow }),\n isFetching: false,\n }))\n\n headMaxIndex = renderedBoundaryIndex\n\n // Ensure the rendering boundary route chunk (and its lazy components, including\n // lazy notFoundComponent) is loaded before we continue to head execution/render.\n await loadRouteChunk(boundaryRoute, ['notFoundComponent'])\n } else if (!inner.preload) {\n // Clear stale root global-not-found state on normal navigations that do not\n // throw notFound. This must live here (instead of only in runLoader success)\n // because the root loader may be skipped when data is still fresh.\n const rootMatch = inner.matches[0]!\n // `rootMatch` is the next match for this navigation. If it is not global\n // not-found, then any currently stored root global-not-found is stale.\n if (!rootMatch.globalNotFound) {\n // `currentRootMatch` is the current store state (from the previous\n // navigation/load). Update only when a stale flag is actually present.\n const currentRootMatch = inner.router.getMatch(rootMatch.id)\n if (currentRootMatch?.globalNotFound) {\n inner.updateMatch(rootMatch.id, (prev) => ({\n ...prev,\n globalNotFound: false,\n error: undefined,\n }))\n }\n }\n }\n\n // When a serial error occurred (e.g. beforeLoad threw a regular Error),\n // the erroring route's lazy chunk wasn't loaded because loaders were skipped.\n // We need to load it so the code-split errorComponent is available for rendering.\n if (inner.serialError && inner.firstBadMatchIndex !== undefined) {\n const errorRoute =\n inner.router.looseRoutesById[\n inner.matches[inner.firstBadMatchIndex]!.routeId\n ]!\n await loadRouteChunk(errorRoute, ['errorComponent'])\n }\n\n // serially execute heads once after loaders/notFound handling, ensuring\n // all head functions get a chance even if one throws.\n for (let i = 0; i <= headMaxIndex; i++) {\n const match = inner.matches[i]!\n const { id: matchId, routeId } = match\n const route = inner.router.looseRoutesById[routeId]!\n try {\n const headResult = executeHead(inner, matchId, route)\n if (headResult) {\n const head = await headResult\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n ...head,\n }))\n }\n } catch (err) {\n console.error(`Error executing head for route ${routeId}:`, err)\n }\n }\n\n const readyPromise = triggerOnReady(inner)\n if (isPromise(readyPromise)) {\n await readyPromise\n }\n\n if (notFoundToThrow) {\n throw notFoundToThrow\n }\n\n if (inner.serialError && !inner.preload && !inner.onReady) {\n throw inner.serialError\n }\n\n return inner.matches\n}\n\nexport type RouteComponentType =\n | 'component'\n | 'errorComponent'\n | 'pendingComponent'\n | 'notFoundComponent'\n\nfunction preloadRouteComponents(\n route: AnyRoute,\n componentTypesToLoad: Array<RouteComponentType>,\n): Promise<void> | undefined {\n const preloads = componentTypesToLoad\n .map((type) => (route.options[type] as any)?.preload?.())\n .filter(Boolean)\n\n if (preloads.length === 0) return undefined\n\n return Promise.all(preloads) as any as Promise<void>\n}\n\nexport function loadRouteChunk(\n route: AnyRoute,\n componentTypesToLoad: Array<RouteComponentType> = componentTypes,\n) {\n if (!route._lazyLoaded && route._lazyPromise === undefined) {\n if (route.lazyFn) {\n route._lazyPromise = route.lazyFn().then((lazyRoute) => {\n // explicitly don't copy over the lazy route's id\n const { id: _id, ...options } = lazyRoute.options\n Object.assign(route.options, options)\n route._lazyLoaded = true\n route._lazyPromise = undefined // gc promise, we won't need it anymore\n })\n } else {\n route._lazyLoaded = true\n }\n }\n\n const runAfterLazy = () =>\n route._componentsLoaded\n ? undefined\n : componentTypesToLoad === componentTypes\n ? (() => {\n if (route._componentsPromise === undefined) {\n const componentsPromise = preloadRouteComponents(\n route,\n componentTypes,\n )\n\n if (componentsPromise) {\n route._componentsPromise = componentsPromise.then(() => {\n route._componentsLoaded = true\n route._componentsPromise = undefined // gc promise, we won't need it anymore\n })\n } else {\n route._componentsLoaded = true\n }\n }\n\n return route._componentsPromise\n })()\n : preloadRouteComponents(route, componentTypesToLoad)\n\n return route._lazyPromise\n ? route._lazyPromise.then(runAfterLazy)\n : runAfterLazy()\n}\n\nfunction makeMaybe<TValue, TError>(\n value: TValue,\n error: TError,\n): { status: 'success'; value: TValue } | { status: 'error'; error: TError } {\n if (error) {\n return { status: 'error' as const, error }\n }\n return { status: 'success' as const, value }\n}\n\nexport function routeNeedsPreload(route: AnyRoute) {\n for (const componentType of componentTypes) {\n if ((route.options[componentType] as any)?.preload) {\n return true\n }\n }\n return false\n}\n\nexport const componentTypes: Array<RouteComponentType> = [\n 'component',\n 'errorComponent',\n 'pend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AAM,cAAc;EAEtD,MAAM,EAAE,IAAI,KAAK,GAAG,YAAY,UAAU;AAC1C,SAAO,OAAO,MAAM,SAAS,QAAQ;AACrC,QAAM,cAAc;AACpB,QAAM,eAAe,KAAA;GACrB;KAEF,OAAM,cAAc;CAIxB,MAAM,qBACJ,MAAM,oBACF,KAAA,IACA,yBAAyB,wBAChB;AACL,MAAI,MAAM,uBAAuB,KAAA,GAAW;GAC1C,MAAM,oBAAoB,uBACxB,OACA,eACD;AAED,OAAI,kBACF,OAAM,qBAAqB,kBAAkB,WAAW;AACtD,UAAM,oBAAoB;AAC1B,UAAM,qBAAqB,KAAA;KAC3B;OAEF,OAAM,oBAAoB;;AAI9B,SAAO,MAAM;KACX,GACJ,uBAAuB,OAAO,qBAAqB;AAE3D,QAAO,MAAM,eACT,MAAM,aAAa,KAAK,aAAa,GACrC,cAAc;;AAGpB,SAAS,UACP,OACA,OAC2E;AAC3E,KAAI,MACF,QAAO;EAAE,QAAQ;EAAkB;EAAO;AAE5C,QAAO;EAAE,QAAQ;EAAoB;EAAO;;AAG9C,SAAgB,kBAAkB,OAAiB;AACjD,MAAK,MAAM,iBAAiB,eAC1B,KAAK,MAAM,QAAQ,gBAAwB,QACzC,QAAO;AAGX,QAAO;;AAGT,IAAa,iBAA4C;CACvD;CACA;CACA;CACA;CACD"}
|
|
1
|
+
{"version":3,"file":"load-matches.js","names":[],"sources":["../../src/load-matches.ts"],"sourcesContent":["import { isServer } from '@tanstack/router-core/isServer'\nimport { invariant } from './invariant'\nimport { createControlledPromise, isPromise } from './utils'\nimport { isNotFound } from './not-found'\nimport { rootRouteId } from './root'\nimport { isRedirect } from './redirect'\nimport type { NotFoundError } from './not-found'\nimport type { ParsedLocation } from './location'\nimport type {\n AnyRoute,\n BeforeLoadContextOptions,\n LoaderFnContext,\n SsrContextOptions,\n} from './route'\nimport type { AnyRouteMatch, MakeRouteMatch } from './Matches'\nimport type { AnyRouter, SSROption, UpdateMatchFn } from './router'\n\n/**\n * An object of this shape is created when calling `loadMatches`.\n * It contains everything we need for all other functions in this file\n * to work. (It's basically the function's argument, plus a few mutable states)\n */\ntype InnerLoadContext = {\n /** the calling router instance */\n router: AnyRouter\n location: ParsedLocation\n /** mutable state, scoped to a `loadMatches` call */\n firstBadMatchIndex?: number\n /** mutable state, scoped to a `loadMatches` call */\n rendered?: boolean\n serialError?: unknown\n updateMatch: UpdateMatchFn\n matches: Array<AnyRouteMatch>\n preload?: boolean\n forceStaleReload?: boolean\n onReady?: () => Promise<void>\n sync?: boolean\n}\n\nconst triggerOnReady = (inner: InnerLoadContext): void | Promise<void> => {\n if (!inner.rendered) {\n inner.rendered = true\n return inner.onReady?.()\n }\n}\n\nconst hasForcePendingActiveMatch = (router: AnyRouter): boolean => {\n return router.stores.matchesId.get().some((matchId) => {\n return router.stores.matchStores.get(matchId)?.get()._forcePending\n })\n}\n\nconst resolvePreload = (inner: InnerLoadContext, matchId: string): boolean => {\n return !!(inner.preload && !inner.router.stores.matchStores.has(matchId))\n}\n\n/**\n * Builds the accumulated context from router options and all matches up to (and optionally including) the given index.\n * Merges __routeContext and __beforeLoadContext from each match.\n */\nconst buildMatchContext = (\n inner: InnerLoadContext,\n index: number,\n includeCurrentMatch: boolean = true,\n): Record<string, unknown> => {\n const context: Record<string, unknown> = {\n ...(inner.router.options.context ?? {}),\n }\n const end = includeCurrentMatch ? index : index - 1\n for (let i = 0; i <= end; i++) {\n const innerMatch = inner.matches[i]\n if (!innerMatch) continue\n const m = inner.router.getMatch(innerMatch.id)\n if (!m) continue\n Object.assign(context, m.__routeContext, m.__beforeLoadContext)\n }\n return context\n}\n\nconst getNotFoundBoundaryIndex = (\n inner: InnerLoadContext,\n err: NotFoundError,\n): number | undefined => {\n if (!inner.matches.length) {\n return undefined\n }\n\n const requestedRouteId = err.routeId\n const matchedRootIndex = inner.matches.findIndex(\n (m) => m.routeId === inner.router.routeTree.id,\n )\n const rootIndex = matchedRootIndex >= 0 ? matchedRootIndex : 0\n\n let startIndex = requestedRouteId\n ? inner.matches.findIndex((match) => match.routeId === requestedRouteId)\n : (inner.firstBadMatchIndex ?? inner.matches.length - 1)\n\n if (startIndex < 0) {\n startIndex = rootIndex\n }\n\n for (let i = startIndex; i >= 0; i--) {\n const match = inner.matches[i]!\n const route = inner.router.looseRoutesById[match.routeId]!\n if (route.options.notFoundComponent) {\n return i\n }\n }\n\n // If no boundary component is found, preserve explicit routeId targeting behavior,\n // otherwise default to root for untargeted notFounds.\n return requestedRouteId ? startIndex : rootIndex\n}\n\nconst handleRedirectAndNotFound = (\n inner: InnerLoadContext,\n match: AnyRouteMatch | undefined,\n err: unknown,\n): void => {\n if (!isRedirect(err) && !isNotFound(err)) return\n\n if (isRedirect(err) && err.redirectHandled && !err.options.reloadDocument) {\n throw err\n }\n\n // in case of a redirecting match during preload, the match does not exist\n if (match) {\n match._nonReactive.beforeLoadPromise?.resolve()\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.beforeLoadPromise = undefined\n match._nonReactive.loaderPromise = undefined\n\n match._nonReactive.error = err\n\n inner.updateMatch(match.id, (prev) => ({\n ...prev,\n status: isRedirect(err)\n ? 'redirected'\n : isNotFound(err)\n ? 'notFound'\n : prev.status === 'pending'\n ? 'success'\n : prev.status,\n context: buildMatchContext(inner, match.index),\n isFetching: false,\n error: err,\n }))\n\n if (isNotFound(err) && !err.routeId) {\n // Stamp the throwing match's routeId so that the finalization step in\n // loadMatches knows where the notFound originated. The actual boundary\n // resolution (walking up to the nearest notFoundComponent) is deferred to\n // the finalization step, where firstBadMatchIndex is stable and\n // headMaxIndex can be capped correctly.\n err.routeId = match.routeId\n }\n\n match._nonReactive.loadPromise?.resolve()\n }\n\n if (isRedirect(err)) {\n inner.rendered = true\n err.options._fromLocation = inner.location\n err.redirectHandled = true\n err = inner.router.resolveRedirect(err)\n }\n\n throw err\n}\n\nconst shouldSkipLoader = (\n inner: InnerLoadContext,\n matchId: string,\n): boolean => {\n const match = inner.router.getMatch(matchId)\n if (!match) {\n return true\n }\n // upon hydration, we skip the loader if the match has been dehydrated on the server\n if (!(isServer ?? inner.router.isServer) && match._nonReactive.dehydrated) {\n return true\n }\n\n if ((isServer ?? inner.router.isServer) && match.ssr === false) {\n return true\n }\n\n return false\n}\n\nconst syncMatchContext = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n): void => {\n const nextContext = buildMatchContext(inner, index)\n\n inner.updateMatch(matchId, (prev) => {\n return {\n ...prev,\n context: nextContext,\n }\n })\n}\n\nconst handleSerialError = (\n inner: InnerLoadContext,\n index: number,\n err: any,\n routerCode: string,\n): void => {\n const { id: matchId, routeId } = inner.matches[index]!\n const route = inner.router.looseRoutesById[routeId]!\n\n // Much like suspense, we use a promise here to know if\n // we've been outdated by a new loadMatches call and\n // should abort the current async operation\n if (err instanceof Promise) {\n throw err\n }\n\n err.routerCode = routerCode\n inner.firstBadMatchIndex ??= index\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), err)\n\n try {\n route.options.onError?.(err)\n } catch (errorHandlerErr) {\n err = errorHandlerErr\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), err)\n }\n\n inner.updateMatch(matchId, (prev) => {\n prev._nonReactive.beforeLoadPromise?.resolve()\n prev._nonReactive.beforeLoadPromise = undefined\n prev._nonReactive.loadPromise?.resolve()\n\n return {\n ...prev,\n error: err,\n status: 'error',\n isFetching: false,\n updatedAt: Date.now(),\n abortController: new AbortController(),\n }\n })\n\n if (!inner.preload && !isRedirect(err) && !isNotFound(err)) {\n inner.serialError ??= err\n }\n}\n\nconst isBeforeLoadSsr = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): void | Promise<void> => {\n const existingMatch = inner.router.getMatch(matchId)!\n const parentMatchId = inner.matches[index - 1]?.id\n const parentMatch = parentMatchId\n ? inner.router.getMatch(parentMatchId)!\n : undefined\n\n // in SPA mode, only SSR the root route\n if (inner.router.isShell()) {\n existingMatch.ssr = route.id === rootRouteId\n return\n }\n\n if (parentMatch?.ssr === false) {\n existingMatch.ssr = false\n return\n }\n\n const parentOverride = (tempSsr: SSROption) => {\n if (tempSsr === true && parentMatch?.ssr === 'data-only') {\n return 'data-only'\n }\n return tempSsr\n }\n\n const defaultSsr = inner.router.options.defaultSsr ?? true\n\n if (route.options.ssr === undefined) {\n existingMatch.ssr = parentOverride(defaultSsr)\n return\n }\n\n if (typeof route.options.ssr !== 'function') {\n existingMatch.ssr = parentOverride(route.options.ssr)\n return\n }\n const { search, params } = existingMatch\n\n const ssrFnContext: SsrContextOptions<any, any, any> = {\n search: makeMaybe(search, existingMatch.searchError),\n params: makeMaybe(params, existingMatch.paramsError),\n location: inner.location,\n matches: inner.matches.map((match) => ({\n index: match.index,\n pathname: match.pathname,\n fullPath: match.fullPath,\n staticData: match.staticData,\n id: match.id,\n routeId: match.routeId,\n search: makeMaybe(match.search, match.searchError),\n params: makeMaybe(match.params, match.paramsError),\n ssr: match.ssr,\n })),\n }\n\n const tempSsr = route.options.ssr(ssrFnContext)\n if (isPromise(tempSsr)) {\n return tempSsr.then((ssr) => {\n existingMatch.ssr = parentOverride(ssr ?? defaultSsr)\n })\n }\n\n existingMatch.ssr = parentOverride(tempSsr ?? defaultSsr)\n return\n}\n\nconst setupPendingTimeout = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n match: AnyRouteMatch,\n): void => {\n if (match._nonReactive.pendingTimeout !== undefined) return\n\n const pendingMs =\n route.options.pendingMs ?? inner.router.options.defaultPendingMs\n const shouldPending = !!(\n inner.onReady &&\n !(isServer ?? inner.router.isServer) &&\n !resolvePreload(inner, matchId) &&\n (route.options.loader ||\n route.options.beforeLoad ||\n routeNeedsPreload(route)) &&\n typeof pendingMs === 'number' &&\n pendingMs !== Infinity &&\n (route.options.pendingComponent ??\n (inner.router.options as any)?.defaultPendingComponent)\n )\n\n if (shouldPending) {\n const pendingTimeout = setTimeout(() => {\n // Update the match and prematurely resolve the loadMatches promise so that\n // the pending component can start rendering\n triggerOnReady(inner)\n }, pendingMs)\n match._nonReactive.pendingTimeout = pendingTimeout\n }\n}\n\nconst preBeforeLoadSetup = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n): void | Promise<void> => {\n const existingMatch = inner.router.getMatch(matchId)!\n\n // If we are in the middle of a load, either of these will be present\n // (not to be confused with `loadPromise`, which is always defined)\n if (\n !existingMatch._nonReactive.beforeLoadPromise &&\n !existingMatch._nonReactive.loaderPromise\n )\n return\n\n setupPendingTimeout(inner, matchId, route, existingMatch)\n\n const then = () => {\n const match = inner.router.getMatch(matchId)!\n if (\n match.preload &&\n (match.status === 'redirected' || match.status === 'notFound')\n ) {\n handleRedirectAndNotFound(inner, match, match.error)\n }\n }\n\n // Wait for the previous beforeLoad to resolve before we continue\n return existingMatch._nonReactive.beforeLoadPromise\n ? existingMatch._nonReactive.beforeLoadPromise.then(then)\n : then()\n}\n\nconst executeBeforeLoad = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): void | Promise<void> => {\n const match = inner.router.getMatch(matchId)!\n\n // explicitly capture the previous loadPromise\n let prevLoadPromise = match._nonReactive.loadPromise\n match._nonReactive.loadPromise = createControlledPromise<void>(() => {\n prevLoadPromise?.resolve()\n prevLoadPromise = undefined\n })\n\n const { paramsError, searchError } = match\n\n if (paramsError) {\n handleSerialError(inner, index, paramsError, 'PARSE_PARAMS')\n }\n\n if (searchError) {\n handleSerialError(inner, index, searchError, 'VALIDATE_SEARCH')\n }\n\n setupPendingTimeout(inner, matchId, route, match)\n\n const abortController = new AbortController()\n\n let isPending = false\n const pending = () => {\n if (isPending) return\n isPending = true\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: 'beforeLoad',\n fetchCount: prev.fetchCount + 1,\n abortController,\n // Note: We intentionally don't update context here.\n // Context should only be updated after beforeLoad resolves to avoid\n // components seeing incomplete context during async beforeLoad execution.\n }))\n }\n\n const resolve = () => {\n match._nonReactive.beforeLoadPromise?.resolve()\n match._nonReactive.beforeLoadPromise = undefined\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: false,\n }))\n }\n\n // if there is no `beforeLoad` option, just mark as pending and resolve\n // Context will be updated later in loadRouteMatch after loader completes\n if (!route.options.beforeLoad) {\n inner.router.batch(() => {\n pending()\n resolve()\n })\n return\n }\n\n match._nonReactive.beforeLoadPromise = createControlledPromise<void>()\n\n // Build context from all parent matches, excluding current match's __beforeLoadContext\n // (since we're about to execute beforeLoad for this match)\n const context = {\n ...buildMatchContext(inner, index, false),\n ...match.__routeContext,\n }\n const { search, params, cause } = match\n const preload = resolvePreload(inner, matchId)\n const beforeLoadFnContext: BeforeLoadContextOptions<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n > = {\n search,\n abortController,\n params,\n preload,\n context,\n location: inner.location,\n navigate: (opts: any) =>\n inner.router.navigate({\n ...opts,\n _fromLocation: inner.location,\n }),\n buildLocation: inner.router.buildLocation,\n cause: preload ? 'preload' : cause,\n matches: inner.matches,\n routeId: route.id,\n ...inner.router.options.additionalContext,\n }\n\n const updateContext = (beforeLoadContext: any) => {\n if (beforeLoadContext === undefined) {\n inner.router.batch(() => {\n pending()\n resolve()\n })\n return\n }\n if (isRedirect(beforeLoadContext) || isNotFound(beforeLoadContext)) {\n pending()\n handleSerialError(inner, index, beforeLoadContext, 'BEFORE_LOAD')\n }\n\n inner.router.batch(() => {\n pending()\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n __beforeLoadContext: beforeLoadContext,\n }))\n resolve()\n })\n }\n\n let beforeLoadContext\n try {\n beforeLoadContext = route.options.beforeLoad(beforeLoadFnContext)\n if (isPromise(beforeLoadContext)) {\n pending()\n return beforeLoadContext\n .catch((err) => {\n handleSerialError(inner, index, err, 'BEFORE_LOAD')\n })\n .then(updateContext)\n }\n } catch (err) {\n pending()\n handleSerialError(inner, index, err, 'BEFORE_LOAD')\n }\n\n updateContext(beforeLoadContext)\n return\n}\n\nconst handleBeforeLoad = (\n inner: InnerLoadContext,\n index: number,\n): void | Promise<void> => {\n const { id: matchId, routeId } = inner.matches[index]!\n const route = inner.router.looseRoutesById[routeId]!\n\n const serverSsr = () => {\n // on the server, determine whether SSR the current match or not\n if (isServer ?? inner.router.isServer) {\n const maybePromise = isBeforeLoadSsr(inner, matchId, index, route)\n if (isPromise(maybePromise)) return maybePromise.then(queueExecution)\n }\n return queueExecution()\n }\n\n const execute = () => executeBeforeLoad(inner, matchId, index, route)\n\n const queueExecution = () => {\n if (shouldSkipLoader(inner, matchId)) return\n const result = preBeforeLoadSetup(inner, matchId, route)\n return isPromise(result) ? result.then(execute) : execute()\n }\n\n return serverSsr()\n}\n\nconst executeHead = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n): void | Promise<\n Pick<\n AnyRouteMatch,\n 'meta' | 'links' | 'headScripts' | 'headers' | 'scripts' | 'styles'\n >\n> => {\n const match = inner.router.getMatch(matchId)\n // in case of a redirecting match during preload, the match does not exist\n if (!match) {\n return\n }\n if (!route.options.head && !route.options.scripts && !route.options.headers) {\n return\n }\n const assetContext = {\n ssr: inner.router.options.ssr,\n matches: inner.matches,\n match,\n params: match.params,\n loaderData: match.loaderData,\n }\n\n return Promise.all([\n route.options.head?.(assetContext),\n route.options.scripts?.(assetContext),\n route.options.headers?.(assetContext),\n ]).then(([headFnContent, scripts, headers]) => {\n const meta = headFnContent?.meta\n const links = headFnContent?.links\n const headScripts = headFnContent?.scripts\n const styles = headFnContent?.styles\n\n return {\n meta,\n links,\n headScripts,\n headers,\n scripts,\n styles,\n }\n })\n}\n\nconst getLoaderContext = (\n inner: InnerLoadContext,\n matchPromises: Array<Promise<AnyRouteMatch>>,\n matchId: string,\n index: number,\n route: AnyRoute,\n): LoaderFnContext => {\n const parentMatchPromise = matchPromises[index - 1] as any\n const { params, loaderDeps, abortController, cause } =\n inner.router.getMatch(matchId)!\n\n const context = buildMatchContext(inner, index)\n\n const preload = resolvePreload(inner, matchId)\n\n return {\n params,\n deps: loaderDeps,\n preload: !!preload,\n parentMatchPromise,\n abortController,\n context,\n location: inner.location,\n navigate: (opts) =>\n inner.router.navigate({\n ...opts,\n _fromLocation: inner.location,\n }),\n cause: preload ? 'preload' : cause,\n route,\n ...inner.router.options.additionalContext,\n }\n}\n\nconst runLoader = async (\n inner: InnerLoadContext,\n matchPromises: Array<Promise<AnyRouteMatch>>,\n matchId: string,\n index: number,\n route: AnyRoute,\n): Promise<void> => {\n try {\n // If the Matches component rendered\n // the pending component and needs to show it for\n // a minimum duration, we''ll wait for it to resolve\n // before committing to the match and resolving\n // the loadPromise\n\n const match = inner.router.getMatch(matchId)!\n\n // Actually run the loader and handle the result\n try {\n if (!(isServer ?? inner.router.isServer) || match.ssr === true) {\n loadRouteChunk(route)\n }\n\n // Kick off the loader!\n const routeLoader = route.options.loader\n const loader =\n typeof routeLoader === 'function' ? routeLoader : routeLoader?.handler\n const loaderResult = loader?.(\n getLoaderContext(inner, matchPromises, matchId, index, route),\n )\n const loaderResultIsPromise = !!loader && isPromise(loaderResult)\n\n const willLoadSomething = !!(\n loaderResultIsPromise ||\n route._lazyPromise ||\n route._componentsPromise ||\n route.options.head ||\n route.options.scripts ||\n route.options.headers ||\n match._nonReactive.minPendingPromise\n )\n\n if (willLoadSomething) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: 'loader',\n }))\n }\n\n if (loader) {\n const loaderData = loaderResultIsPromise\n ? await loaderResult\n : loaderResult\n\n handleRedirectAndNotFound(\n inner,\n inner.router.getMatch(matchId),\n loaderData,\n )\n if (loaderData !== undefined) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n loaderData,\n }))\n }\n }\n\n // Lazy option can modify the route options,\n // so we need to wait for it to resolve before\n // we can use the options\n if (route._lazyPromise) await route._lazyPromise\n const pendingPromise = match._nonReactive.minPendingPromise\n if (pendingPromise) await pendingPromise\n\n // Last but not least, wait for the the components\n // to be preloaded before we resolve the match\n if (route._componentsPromise) await route._componentsPromise\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n error: undefined,\n context: buildMatchContext(inner, index),\n status: 'success',\n isFetching: false,\n updatedAt: Date.now(),\n }))\n } catch (e) {\n let error = e\n\n if ((error as any)?.name === 'AbortError') {\n if (match.abortController.signal.aborted) {\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.loaderPromise = undefined\n return\n }\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n status: prev.status === 'pending' ? 'success' : prev.status,\n isFetching: false,\n context: buildMatchContext(inner, index),\n }))\n return\n }\n\n const pendingPromise = match._nonReactive.minPendingPromise\n if (pendingPromise) await pendingPromise\n\n if (isNotFound(e)) {\n await (route.options.notFoundComponent as any)?.preload?.()\n }\n\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), e)\n\n try {\n route.options.onError?.(e)\n } catch (onErrorError) {\n error = onErrorError\n handleRedirectAndNotFound(\n inner,\n inner.router.getMatch(matchId),\n onErrorError,\n )\n }\n if (!isRedirect(error) && !isNotFound(error)) {\n await loadRouteChunk(route, ['errorComponent'])\n }\n\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n error,\n context: buildMatchContext(inner, index),\n status: 'error',\n isFetching: false,\n }))\n }\n } catch (err) {\n const match = inner.router.getMatch(matchId)\n // in case of a redirecting match during preload, the match does not exist\n if (match) {\n match._nonReactive.loaderPromise = undefined\n }\n handleRedirectAndNotFound(inner, match, err)\n }\n}\n\nconst loadRouteMatch = async (\n inner: InnerLoadContext,\n matchPromises: Array<Promise<AnyRouteMatch>>,\n index: number,\n): Promise<AnyRouteMatch> => {\n async function handleLoader(\n preload: boolean,\n prevMatch: AnyRouteMatch,\n previousRouteMatchId: string | undefined,\n match: AnyRouteMatch,\n route: AnyRoute,\n ) {\n const age = Date.now() - prevMatch.updatedAt\n\n const staleAge = preload\n ? (route.options.preloadStaleTime ??\n inner.router.options.defaultPreloadStaleTime ??\n 30_000) // 30 seconds for preloads by default\n : (route.options.staleTime ?? inner.router.options.defaultStaleTime ?? 0)\n\n const shouldReloadOption = route.options.shouldReload\n\n // Default to reloading the route all the time\n // Allow shouldReload to get the last say,\n // if provided.\n const shouldReload =\n typeof shouldReloadOption === 'function'\n ? shouldReloadOption(\n getLoaderContext(inner, matchPromises, matchId, index, route),\n )\n : shouldReloadOption\n\n // If the route is successful and still fresh, just resolve\n const { status, invalid } = match\n const staleMatchShouldReload =\n age >= staleAge &&\n (!!inner.forceStaleReload ||\n match.cause === 'enter' ||\n (previousRouteMatchId !== undefined &&\n previousRouteMatchId !== match.id))\n loaderShouldRunAsync =\n status === 'success' &&\n (invalid || (shouldReload ?? staleMatchShouldReload))\n if (preload && route.options.preload === false) {\n // Do nothing\n } else if (\n loaderShouldRunAsync &&\n !inner.sync &&\n shouldReloadInBackground\n ) {\n loaderIsRunningAsync = true\n ;(async () => {\n try {\n await runLoader(inner, matchPromises, matchId, index, route)\n const match = inner.router.getMatch(matchId)!\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.loadPromise?.resolve()\n match._nonReactive.loaderPromise = undefined\n match._nonReactive.loadPromise = undefined\n } catch (err) {\n if (isRedirect(err)) {\n await inner.router.navigate(err.options)\n }\n }\n })()\n } else if (status !== 'success' || loaderShouldRunAsync) {\n await runLoader(inner, matchPromises, matchId, index, route)\n } else {\n syncMatchContext(inner, matchId, index)\n }\n }\n\n const { id: matchId, routeId } = inner.matches[index]!\n let loaderShouldRunAsync = false\n let loaderIsRunningAsync = false\n const route = inner.router.looseRoutesById[routeId]!\n const routeLoader = route.options.loader\n const shouldReloadInBackground =\n ((typeof routeLoader === 'function'\n ? undefined\n : routeLoader?.staleReloadMode) ??\n inner.router.options.defaultStaleReloadMode) !== 'blocking'\n\n if (shouldSkipLoader(inner, matchId)) {\n const match = inner.router.getMatch(matchId)\n if (!match) {\n return inner.matches[index]!\n }\n\n syncMatchContext(inner, matchId, index)\n\n if (isServer ?? inner.router.isServer) {\n return inner.router.getMatch(matchId)!\n }\n } else {\n const prevMatch = inner.router.getMatch(matchId)! // This is where all of the stale-while-revalidate magic happens\n const activeIdAtIndex = inner.router.stores.matchesId.get()[index]\n const activeAtIndex =\n (activeIdAtIndex &&\n inner.router.stores.matchStores.get(activeIdAtIndex)) ||\n null\n const previousRouteMatchId =\n activeAtIndex?.routeId === routeId\n ? activeIdAtIndex\n : inner.router.stores.matches.get().find((d) => d.routeId === routeId)\n ?.id\n const preload = resolvePreload(inner, matchId)\n\n // there is a loaderPromise, so we are in the middle of a load\n if (prevMatch._nonReactive.loaderPromise) {\n // do not block if we already have stale data we can show\n // but only if the ongoing load is not a preload since error handling is different for preloads\n // and we don't want to swallow errors\n if (\n prevMatch.status === 'success' &&\n !inner.sync &&\n !prevMatch.preload &&\n shouldReloadInBackground\n ) {\n return prevMatch\n }\n await prevMatch._nonReactive.loaderPromise\n const match = inner.router.getMatch(matchId)!\n const error = match._nonReactive.error || match.error\n if (error) {\n handleRedirectAndNotFound(inner, match, error)\n }\n\n if (match.status === 'pending') {\n await handleLoader(\n preload,\n prevMatch,\n previousRouteMatchId,\n match,\n route,\n )\n }\n } else {\n const nextPreload =\n preload && !inner.router.stores.matchStores.has(matchId)\n const match = inner.router.getMatch(matchId)!\n match._nonReactive.loaderPromise = createControlledPromise<void>()\n if (nextPreload !== match.preload) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n preload: nextPreload,\n }))\n }\n\n await handleLoader(preload, prevMatch, previousRouteMatchId, match, route)\n }\n }\n const match = inner.router.getMatch(matchId)!\n if (!loaderIsRunningAsync) {\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.loadPromise?.resolve()\n match._nonReactive.loadPromise = undefined\n }\n\n clearTimeout(match._nonReactive.pendingTimeout)\n match._nonReactive.pendingTimeout = undefined\n if (!loaderIsRunningAsync) match._nonReactive.loaderPromise = undefined\n match._nonReactive.dehydrated = undefined\n\n const nextIsFetching = loaderIsRunningAsync ? match.isFetching : false\n if (nextIsFetching !== match.isFetching || match.invalid !== false) {\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n isFetching: nextIsFetching,\n invalid: false,\n }))\n return inner.router.getMatch(matchId)!\n } else {\n return match\n }\n}\n\nexport async function loadMatches(arg: {\n router: AnyRouter\n location: ParsedLocation\n matches: Array<AnyRouteMatch>\n preload?: boolean\n forceStaleReload?: boolean\n onReady?: () => Promise<void>\n updateMatch: UpdateMatchFn\n sync?: boolean\n}): Promise<Array<MakeRouteMatch>> {\n const inner: InnerLoadContext = arg\n const matchPromises: Array<Promise<AnyRouteMatch>> = []\n\n // make sure the pending component is immediately rendered when hydrating a match that is not SSRed\n // the pending component was already rendered on the server and we want to keep it shown on the client until minPendingMs is reached\n if (\n !(isServer ?? inner.router.isServer) &&\n hasForcePendingActiveMatch(inner.router)\n ) {\n triggerOnReady(inner)\n }\n\n let beforeLoadNotFound: NotFoundError | undefined\n\n // Execute all beforeLoads one by one\n for (let i = 0; i < inner.matches.length; i++) {\n try {\n const beforeLoad = handleBeforeLoad(inner, i)\n if (isPromise(beforeLoad)) await beforeLoad\n } catch (err) {\n if (isRedirect(err)) {\n throw err\n }\n if (isNotFound(err)) {\n beforeLoadNotFound = err\n } else {\n if (!inner.preload) throw err\n }\n break\n }\n\n if (inner.serialError || inner.firstBadMatchIndex != null) {\n break\n }\n }\n\n // Execute loaders once, with max index adapted for beforeLoad notFound handling.\n const baseMaxIndexExclusive = inner.firstBadMatchIndex ?? inner.matches.length\n\n const boundaryIndex =\n beforeLoadNotFound && !inner.preload\n ? getNotFoundBoundaryIndex(inner, beforeLoadNotFound)\n : undefined\n\n const maxIndexExclusive =\n beforeLoadNotFound && inner.preload\n ? 0\n : boundaryIndex !== undefined\n ? Math.min(boundaryIndex + 1, baseMaxIndexExclusive)\n : baseMaxIndexExclusive\n\n let firstNotFound: NotFoundError | undefined\n let firstUnhandledRejection: unknown\n\n for (let i = 0; i < maxIndexExclusive; i++) {\n matchPromises.push(loadRouteMatch(inner, matchPromises, i))\n }\n\n try {\n await Promise.all(matchPromises)\n } catch {\n const settled = await Promise.allSettled(matchPromises)\n\n for (const result of settled) {\n if (result.status !== 'rejected') continue\n\n const reason = result.reason\n if (isRedirect(reason)) {\n throw reason\n }\n if (isNotFound(reason)) {\n firstNotFound ??= reason\n } else {\n firstUnhandledRejection ??= reason\n }\n }\n\n if (firstUnhandledRejection !== undefined) {\n throw firstUnhandledRejection\n }\n }\n\n const notFoundToThrow =\n firstNotFound ??\n (beforeLoadNotFound && !inner.preload ? beforeLoadNotFound : undefined)\n\n let headMaxIndex =\n inner.firstBadMatchIndex !== undefined\n ? inner.firstBadMatchIndex\n : inner.matches.length - 1\n\n if (!notFoundToThrow && beforeLoadNotFound && inner.preload) {\n return inner.matches\n }\n\n if (notFoundToThrow) {\n // Determine once which matched route will actually render the\n // notFoundComponent, then pass this precomputed index through the remaining\n // finalization steps.\n // This can differ from the throwing route when routeId targets an ancestor\n // boundary (or when bubbling resolves to a parent/root boundary).\n const renderedBoundaryIndex = getNotFoundBoundaryIndex(\n inner,\n notFoundToThrow,\n )\n\n if (renderedBoundaryIndex === undefined) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n 'Invariant failed: Could not find match for notFound boundary',\n )\n }\n\n invariant()\n }\n const boundaryMatch = inner.matches[renderedBoundaryIndex]!\n\n const boundaryRoute = inner.router.looseRoutesById[boundaryMatch.routeId]!\n const defaultNotFoundComponent = (inner.router.options as any)\n ?.defaultNotFoundComponent\n\n // Ensure a notFoundComponent exists on the boundary route\n if (!boundaryRoute.options.notFoundComponent && defaultNotFoundComponent) {\n boundaryRoute.options.notFoundComponent = defaultNotFoundComponent\n }\n\n notFoundToThrow.routeId = boundaryMatch.routeId\n\n const boundaryIsRoot = boundaryMatch.routeId === inner.router.routeTree.id\n\n inner.updateMatch(boundaryMatch.id, (prev) => ({\n ...prev,\n ...(boundaryIsRoot\n ? // For root boundary, use globalNotFound so the root component's\n // shell still renders and <Outlet> handles the not-found display,\n // instead of replacing the entire root shell via status='notFound'.\n { status: 'success' as const, globalNotFound: true, error: undefined }\n : // For non-root boundaries, set status:'notFound' so MatchInner\n // renders the notFoundComponent directly.\n { status: 'notFound' as const, error: notFoundToThrow }),\n isFetching: false,\n }))\n\n headMaxIndex = renderedBoundaryIndex\n\n // Ensure the rendering boundary route chunk (and its lazy components, including\n // lazy notFoundComponent) is loaded before we continue to head execution/render.\n await loadRouteChunk(boundaryRoute, ['notFoundComponent'])\n } else if (!inner.preload) {\n // Clear stale root global-not-found state on normal navigations that do not\n // throw notFound. This must live here (instead of only in runLoader success)\n // because the root loader may be skipped when data is still fresh.\n const rootMatch = inner.matches[0]!\n // `rootMatch` is the next match for this navigation. If it is not global\n // not-found, then any currently stored root global-not-found is stale.\n if (!rootMatch.globalNotFound) {\n // `currentRootMatch` is the current store state (from the previous\n // navigation/load). Update only when a stale flag is actually present.\n const currentRootMatch = inner.router.getMatch(rootMatch.id)\n if (currentRootMatch?.globalNotFound) {\n inner.updateMatch(rootMatch.id, (prev) => ({\n ...prev,\n globalNotFound: false,\n error: undefined,\n }))\n }\n }\n }\n\n // When a serial error occurred (e.g. beforeLoad threw a regular Error),\n // the erroring route's lazy chunk wasn't loaded because loaders were skipped.\n // We need to load it so the code-split errorComponent is available for rendering.\n if (inner.serialError && inner.firstBadMatchIndex !== undefined) {\n const errorRoute =\n inner.router.looseRoutesById[\n inner.matches[inner.firstBadMatchIndex]!.routeId\n ]!\n await loadRouteChunk(errorRoute, ['errorComponent'])\n }\n\n // serially execute heads once after loaders/notFound handling, ensuring\n // all head functions get a chance even if one throws.\n for (let i = 0; i <= headMaxIndex; i++) {\n const match = inner.matches[i]!\n const { id: matchId, routeId } = match\n const route = inner.router.looseRoutesById[routeId]!\n try {\n const headResult = executeHead(inner, matchId, route)\n if (headResult) {\n const head = await headResult\n inner.updateMatch(matchId, (prev) => ({\n ...prev,\n ...head,\n }))\n }\n } catch (err) {\n console.error(`Error executing head for route ${routeId}:`, err)\n }\n }\n\n const readyPromise = triggerOnReady(inner)\n if (isPromise(readyPromise)) {\n await readyPromise\n }\n\n if (notFoundToThrow) {\n throw notFoundToThrow\n }\n\n if (inner.serialError && !inner.preload && !inner.onReady) {\n throw inner.serialError\n }\n\n return inner.matches\n}\n\nexport type RouteComponentType =\n | 'component'\n | 'errorComponent'\n | 'pendingComponent'\n | 'notFoundComponent'\n\nfunction preloadRouteComponents(\n route: AnyRoute,\n componentTypesToLoad: Array<RouteComponentType>,\n): Promise<void> | undefined {\n const preloads = componentTypesToLoad\n .map((type) => (route.options[type] as any)?.preload?.())\n .filter(Boolean)\n\n if (preloads.length === 0) return undefined\n\n return Promise.all(preloads) as any as Promise<void>\n}\n\nexport function loadRouteChunk(\n route: AnyRoute,\n componentTypesToLoad: Array<RouteComponentType> = componentTypes,\n) {\n if (!route._lazyLoaded && route._lazyPromise === undefined) {\n if (route.lazyFn) {\n route._lazyPromise = route.lazyFn().then((lazyRoute) => {\n // explicitly don't copy over the lazy route's id\n const { id: _id, ...options } = lazyRoute.options\n Object.assign(route.options, options)\n route._lazyLoaded = true\n route._lazyPromise = undefined // gc promise, we won't need it anymore\n })\n } else {\n route._lazyLoaded = true\n }\n }\n\n const runAfterLazy = () =>\n route._componentsLoaded\n ? undefined\n : componentTypesToLoad === componentTypes\n ? (() => {\n if (route._componentsPromise === undefined) {\n const componentsPromise = preloadRouteComponents(\n route,\n componentTypes,\n )\n\n if (componentsPromise) {\n route._componentsPromise = componentsPromise.then(() => {\n route._componentsLoaded = true\n route._componentsPromise = undefined // gc promise, we won't need it anymore\n })\n } else {\n route._componentsLoaded = true\n }\n }\n\n return route._componentsPromise\n })()\n : preloadRouteComponents(route, componentTypesToLoad)\n\n return route._lazyPromise\n ? route._lazyPromise.then(runAfterLazy)\n : runAfterLazy()\n}\n\nfunction makeMaybe<TValue, TError>(\n value: TValue,\n error: TError,\n): { status: 'success'; value: TValue } | { status: 'error'; error: TError } {\n if (error) {\n return { status: 'error' as const, error }\n }\n return { status: 'success' as const, value }\n}\n\nexport function routeNeedsPreload(route: AnyRoute) {\n for (const componentType of componentTypes) {\n if ((route.options[componentType] as any)?.preload) {\n return true\n }\n }\n return false\n}\n\nexport const componentTypes: Array<RouteComponentType> = [\n 'component',\n 'errorComponent',\n 'pendingComponent',\n 'notFoundComponent',\n] as const\n"],"mappings":";;;;;;;AAuCA,IAAM,kBAAkB,UAAkD;AACxE,KAAI,CAAC,MAAM,UAAU;AACnB,QAAM,WAAW;AACjB,SAAO,MAAM,WAAW;;;AAI5B,IAAM,8BAA8B,WAA+B;AACjE,QAAO,OAAO,OAAO,UAAU,KAAK,CAAC,MAAM,YAAY;AACrD,SAAO,OAAO,OAAO,YAAY,IAAI,QAAQ,EAAE,KAAK,CAAC;GACrD;;AAGJ,IAAM,kBAAkB,OAAyB,YAA6B;AAC5E,QAAO,CAAC,EAAE,MAAM,WAAW,CAAC,MAAM,OAAO,OAAO,YAAY,IAAI,QAAQ;;;;;;AAO1E,IAAM,qBACJ,OACA,OACA,sBAA+B,SACH;CAC5B,MAAM,UAAmC,EACvC,GAAI,MAAM,OAAO,QAAQ,WAAW,EAAE,EACvC;CACD,MAAM,MAAM,sBAAsB,QAAQ,QAAQ;AAClD,MAAK,IAAI,IAAI,GAAG,KAAK,KAAK,KAAK;EAC7B,MAAM,aAAa,MAAM,QAAQ;AACjC,MAAI,CAAC,WAAY;EACjB,MAAM,IAAI,MAAM,OAAO,SAAS,WAAW,GAAG;AAC9C,MAAI,CAAC,EAAG;AACR,SAAO,OAAO,SAAS,EAAE,gBAAgB,EAAE,oBAAoB;;AAEjE,QAAO;;AAGT,IAAM,4BACJ,OACA,QACuB;AACvB,KAAI,CAAC,MAAM,QAAQ,OACjB;CAGF,MAAM,mBAAmB,IAAI;CAC7B,MAAM,mBAAmB,MAAM,QAAQ,WACpC,MAAM,EAAE,YAAY,MAAM,OAAO,UAAU,GAC7C;CACD,MAAM,YAAY,oBAAoB,IAAI,mBAAmB;CAE7D,IAAI,aAAa,mBACb,MAAM,QAAQ,WAAW,UAAU,MAAM,YAAY,iBAAiB,GACrE,MAAM,sBAAsB,MAAM,Q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D,gBAClD;AACA,KAAI,CAAC,MAAM,eAAe,MAAM,iBAAiB,KAAA,EAC/C,KAAI,MAAM,OACR,OAAM,eAAe,MAAM,QAAQ,CAAC,MAAM,cAAc;EAEtD,MAAM,EAAE,IAAI,KAAK,GAAG,YAAY,UAAU;AAC1C,SAAO,OAAO,MAAM,SAAS,QAAQ;AACrC,QAAM,cAAc;AACpB,QAAM,eAAe,KAAA;GACrB;KAEF,OAAM,cAAc;CAIxB,MAAM,qBACJ,MAAM,oBACF,KAAA,IACA,yBAAyB,wBAChB;AACL,MAAI,MAAM,uBAAuB,KAAA,GAAW;GAC1C,MAAM,oBAAoB,uBACxB,OACA,eACD;AAED,OAAI,kBACF,OAAM,qBAAqB,kBAAkB,WAAW;AACtD,UAAM,oBAAoB;AAC1B,UAAM,qBAAqB,KAAA;KAC3B;OAEF,OAAM,oBAAoB;;AAI9B,SAAO,MAAM;KACX,GACJ,uBAAuB,OAAO,qBAAqB;AAE3D,QAAO,MAAM,eACT,MAAM,aAAa,KAAK,aAAa,GACrC,cAAc;;AAGpB,SAAS,UACP,OACA,OAC2E;AAC3E,KAAI,MACF,QAAO;EAAE,QAAQ;EAAkB;EAAO;AAE5C,QAAO;EAAE,QAAQ;EAAoB;EAAO;;AAG9C,SAAgB,kBAAkB,OAAiB;AACjD,MAAK,MAAM,iBAAiB,eAC1B,KAAK,MAAM,QAAQ,gBAAwB,QACzC,QAAO;AAGX,QAAO;;AAGT,IAAa,iBAA4C;CACvD;CACA;CACA;CACA;CACD"}
|
package/dist/esm/manifest.d.ts
CHANGED
|
@@ -10,6 +10,9 @@ export declare function resolveManifestAssetLink(link: ManifestAssetLink): {
|
|
|
10
10
|
crossOrigin?: AssetCrossOrigin;
|
|
11
11
|
};
|
|
12
12
|
export type Manifest = {
|
|
13
|
+
inlineCss?: {
|
|
14
|
+
styles: Record<string, string>;
|
|
15
|
+
};
|
|
13
16
|
routes: Record<string, {
|
|
14
17
|
filePath?: string;
|
|
15
18
|
preloads?: Array<ManifestAssetLink>;
|
|
@@ -32,4 +35,9 @@ export type RouterManagedTag = {
|
|
|
32
35
|
tag: 'style';
|
|
33
36
|
attrs?: Record<string, any>;
|
|
34
37
|
children?: string;
|
|
38
|
+
inlineCss?: true;
|
|
35
39
|
};
|
|
40
|
+
export declare function getStylesheetHref(asset: RouterManagedTag): string | undefined;
|
|
41
|
+
export declare function isInlinableStylesheet(manifest: Manifest | undefined, asset: RouterManagedTag): boolean;
|
|
42
|
+
export declare function createInlineCssStyleAsset(css: string): RouterManagedTag;
|
|
43
|
+
export declare function createInlineCssPlaceholderAsset(): RouterManagedTag;
|
package/dist/esm/manifest.js
CHANGED
|
@@ -11,7 +11,34 @@ function resolveManifestAssetLink(link) {
|
|
|
11
11
|
};
|
|
12
12
|
return link;
|
|
13
13
|
}
|
|
14
|
+
function getStylesheetHref(asset) {
|
|
15
|
+
if (asset.tag !== "link") return void 0;
|
|
16
|
+
const rel = asset.attrs?.rel;
|
|
17
|
+
const href = asset.attrs?.href;
|
|
18
|
+
if (typeof href !== "string") return void 0;
|
|
19
|
+
if (!(typeof rel === "string" ? rel.split(/\s+/) : []).includes("stylesheet")) return void 0;
|
|
20
|
+
return href;
|
|
21
|
+
}
|
|
22
|
+
function isInlinableStylesheet(manifest, asset) {
|
|
23
|
+
const href = getStylesheetHref(asset);
|
|
24
|
+
return !!href && manifest?.inlineCss?.styles[href] !== void 0;
|
|
25
|
+
}
|
|
26
|
+
function createInlineCssStyleAsset(css) {
|
|
27
|
+
return {
|
|
28
|
+
tag: "style",
|
|
29
|
+
attrs: { suppressHydrationWarning: true },
|
|
30
|
+
inlineCss: true,
|
|
31
|
+
children: css
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function createInlineCssPlaceholderAsset() {
|
|
35
|
+
return {
|
|
36
|
+
tag: "style",
|
|
37
|
+
attrs: { suppressHydrationWarning: true },
|
|
38
|
+
inlineCss: true
|
|
39
|
+
};
|
|
40
|
+
}
|
|
14
41
|
//#endregion
|
|
15
|
-
export { getAssetCrossOrigin, resolveManifestAssetLink };
|
|
42
|
+
export { createInlineCssPlaceholderAsset, createInlineCssStyleAsset, getAssetCrossOrigin, getStylesheetHref, isInlinableStylesheet, resolveManifestAssetLink };
|
|
16
43
|
|
|
17
44
|
//# sourceMappingURL=manifest.js.map
|
package/dist/esm/manifest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.js","names":[],"sources":["../../src/manifest.ts"],"sourcesContent":["export type AssetCrossOrigin = 'anonymous' | 'use-credentials'\n\nexport type AssetCrossOriginConfig =\n | AssetCrossOrigin\n | Partial<Record<'modulepreload' | 'stylesheet', AssetCrossOrigin>>\n\nexport type ManifestAssetLink =\n | string\n | {\n href: string\n crossOrigin?: AssetCrossOrigin\n }\n\nexport function getAssetCrossOrigin(\n assetCrossOrigin: AssetCrossOriginConfig | undefined,\n kind: 'modulepreload' | 'stylesheet',\n): AssetCrossOrigin | undefined {\n if (!assetCrossOrigin) {\n return undefined\n }\n\n if (typeof assetCrossOrigin === 'string') {\n return assetCrossOrigin\n }\n\n return assetCrossOrigin[kind]\n}\n\nexport function resolveManifestAssetLink(link: ManifestAssetLink) {\n if (typeof link === 'string') {\n return { href: link, crossOrigin: undefined }\n }\n\n return link\n}\n\nexport type Manifest = {\n routes: Record<\n string,\n {\n filePath?: string\n preloads?: Array<ManifestAssetLink>\n assets?: Array<RouterManagedTag>\n }\n >\n}\n\nexport type RouterManagedTag =\n | {\n tag: 'title'\n attrs?: Record<string, any>\n children: string\n }\n | {\n tag: 'meta' | 'link'\n attrs?: Record<string, any>\n children?: never\n }\n | {\n tag: 'script'\n attrs?: Record<string, any>\n children?: string\n }\n | {\n tag: 'style'\n attrs?: Record<string, any>\n children?: string\n }\n"],"mappings":";AAaA,SAAgB,oBACd,kBACA,MAC8B;AAC9B,KAAI,CAAC,iBACH;AAGF,KAAI,OAAO,qBAAqB,SAC9B,QAAO;AAGT,QAAO,iBAAiB;;AAG1B,SAAgB,yBAAyB,MAAyB;AAChE,KAAI,OAAO,SAAS,SAClB,QAAO;EAAE,MAAM;EAAM,aAAa,KAAA;EAAW;AAG/C,QAAO"}
|
|
1
|
+
{"version":3,"file":"manifest.js","names":[],"sources":["../../src/manifest.ts"],"sourcesContent":["export type AssetCrossOrigin = 'anonymous' | 'use-credentials'\n\nexport type AssetCrossOriginConfig =\n | AssetCrossOrigin\n | Partial<Record<'modulepreload' | 'stylesheet', AssetCrossOrigin>>\n\nexport type ManifestAssetLink =\n | string\n | {\n href: string\n crossOrigin?: AssetCrossOrigin\n }\n\nexport function getAssetCrossOrigin(\n assetCrossOrigin: AssetCrossOriginConfig | undefined,\n kind: 'modulepreload' | 'stylesheet',\n): AssetCrossOrigin | undefined {\n if (!assetCrossOrigin) {\n return undefined\n }\n\n if (typeof assetCrossOrigin === 'string') {\n return assetCrossOrigin\n }\n\n return assetCrossOrigin[kind]\n}\n\nexport function resolveManifestAssetLink(link: ManifestAssetLink) {\n if (typeof link === 'string') {\n return { href: link, crossOrigin: undefined }\n }\n\n return link\n}\n\nexport type Manifest = {\n inlineCss?: {\n styles: Record<string, string>\n }\n routes: Record<\n string,\n {\n filePath?: string\n preloads?: Array<ManifestAssetLink>\n assets?: Array<RouterManagedTag>\n }\n >\n}\n\nexport type RouterManagedTag =\n | {\n tag: 'title'\n attrs?: Record<string, any>\n children: string\n }\n | {\n tag: 'meta' | 'link'\n attrs?: Record<string, any>\n children?: never\n }\n | {\n tag: 'script'\n attrs?: Record<string, any>\n children?: string\n }\n | {\n tag: 'style'\n attrs?: Record<string, any>\n children?: string\n inlineCss?: true\n }\n\nexport function getStylesheetHref(asset: RouterManagedTag) {\n if (asset.tag !== 'link') return undefined\n\n const rel = asset.attrs?.rel\n const href = asset.attrs?.href\n if (typeof href !== 'string') return undefined\n\n const relTokens = typeof rel === 'string' ? rel.split(/\\s+/) : []\n if (!relTokens.includes('stylesheet')) return undefined\n\n return href\n}\n\nexport function isInlinableStylesheet(\n manifest: Manifest | undefined,\n asset: RouterManagedTag,\n) {\n const href = getStylesheetHref(asset)\n return !!href && manifest?.inlineCss?.styles[href] !== undefined\n}\n\nexport function createInlineCssStyleAsset(css: string): RouterManagedTag {\n return {\n tag: 'style',\n attrs: {\n suppressHydrationWarning: true,\n },\n inlineCss: true,\n children: css,\n }\n}\n\nexport function createInlineCssPlaceholderAsset(): RouterManagedTag {\n return {\n tag: 'style',\n attrs: {\n suppressHydrationWarning: true,\n },\n inlineCss: true,\n }\n}\n"],"mappings":";AAaA,SAAgB,oBACd,kBACA,MAC8B;AAC9B,KAAI,CAAC,iBACH;AAGF,KAAI,OAAO,qBAAqB,SAC9B,QAAO;AAGT,QAAO,iBAAiB;;AAG1B,SAAgB,yBAAyB,MAAyB;AAChE,KAAI,OAAO,SAAS,SAClB,QAAO;EAAE,MAAM;EAAM,aAAa,KAAA;EAAW;AAG/C,QAAO;;AAwCT,SAAgB,kBAAkB,OAAyB;AACzD,KAAI,MAAM,QAAQ,OAAQ,QAAO,KAAA;CAEjC,MAAM,MAAM,MAAM,OAAO;CACzB,MAAM,OAAO,MAAM,OAAO;AAC1B,KAAI,OAAO,SAAS,SAAU,QAAO,KAAA;AAGrC,KAAI,EADc,OAAO,QAAQ,WAAW,IAAI,MAAM,MAAM,GAAG,EAAE,EAClD,SAAS,aAAa,CAAE,QAAO,KAAA;AAE9C,QAAO;;AAGT,SAAgB,sBACd,UACA,OACA;CACA,MAAM,OAAO,kBAAkB,MAAM;AACrC,QAAO,CAAC,CAAC,QAAQ,UAAU,WAAW,OAAO,UAAU,KAAA;;AAGzD,SAAgB,0BAA0B,KAA+B;AACvE,QAAO;EACL,KAAK;EACL,OAAO,EACL,0BAA0B,MAC3B;EACD,WAAW;EACX,UAAU;EACX;;AAGH,SAAgB,kCAAoD;AAClE,QAAO;EACL,KAAK;EACL,OAAO,EACL,0BAA0B,MAC3B;EACD,WAAW;EACZ"}
|
|
@@ -2,6 +2,7 @@ import { decodePath } from "../utils.js";
|
|
|
2
2
|
import { invariant } from "../invariant.js";
|
|
3
3
|
import { createLRUCache } from "../lru-cache.js";
|
|
4
4
|
import { rootRouteId } from "../root.js";
|
|
5
|
+
import { createInlineCssPlaceholderAsset, createInlineCssStyleAsset, getStylesheetHref, isInlinableStylesheet } from "../manifest.js";
|
|
5
6
|
import { GLOBAL_TSR, TSR_SCRIPT_BARRIER_ID } from "./constants.js";
|
|
6
7
|
import { makeSsrSerovalPlugin } from "./serializer/transformer.js";
|
|
7
8
|
import { defaultSerovalPlugins } from "./serializer/seroval-plugins.js";
|
|
@@ -95,6 +96,7 @@ var ScriptBuffer = class {
|
|
|
95
96
|
var isProd = process.env.NODE_ENV === "production";
|
|
96
97
|
var MANIFEST_CACHE_SIZE = 100;
|
|
97
98
|
var manifestCaches = /* @__PURE__ */ new WeakMap();
|
|
99
|
+
var inlineCssCaches = /* @__PURE__ */ new WeakMap();
|
|
98
100
|
function getManifestCache(manifest) {
|
|
99
101
|
const cache = manifestCaches.get(manifest);
|
|
100
102
|
if (cache) return cache;
|
|
@@ -102,17 +104,81 @@ function getManifestCache(manifest) {
|
|
|
102
104
|
manifestCaches.set(manifest, newCache);
|
|
103
105
|
return newCache;
|
|
104
106
|
}
|
|
107
|
+
function getInlineCssCache(manifest) {
|
|
108
|
+
const cache = inlineCssCaches.get(manifest);
|
|
109
|
+
if (cache) return cache;
|
|
110
|
+
const newCache = createLRUCache(MANIFEST_CACHE_SIZE);
|
|
111
|
+
inlineCssCaches.set(manifest, newCache);
|
|
112
|
+
return newCache;
|
|
113
|
+
}
|
|
114
|
+
function getInlineCssHrefsForMatches(manifest, matches) {
|
|
115
|
+
const styles = manifest?.inlineCss?.styles;
|
|
116
|
+
if (!styles) return [];
|
|
117
|
+
const seen = /* @__PURE__ */ new Set();
|
|
118
|
+
const hrefs = [];
|
|
119
|
+
for (const match of matches) {
|
|
120
|
+
const assets = manifest?.routes[match.routeId]?.assets ?? [];
|
|
121
|
+
for (const asset of assets) {
|
|
122
|
+
const href = getStylesheetHref(asset);
|
|
123
|
+
if (!href || seen.has(href) || styles[href] === void 0) continue;
|
|
124
|
+
seen.add(href);
|
|
125
|
+
hrefs.push(href);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return hrefs;
|
|
129
|
+
}
|
|
130
|
+
function getInlineCssForHrefs(manifest, hrefs) {
|
|
131
|
+
const styles = manifest.inlineCss?.styles;
|
|
132
|
+
if (!styles || hrefs.length === 0) return void 0;
|
|
133
|
+
const cacheKey = hrefs.join("\0");
|
|
134
|
+
if (isProd) {
|
|
135
|
+
const cached = getInlineCssCache(manifest).get(cacheKey);
|
|
136
|
+
if (cached !== void 0) return cached;
|
|
137
|
+
}
|
|
138
|
+
const css = hrefs.map((href) => styles[href]).join("");
|
|
139
|
+
if (isProd) getInlineCssCache(manifest).set(cacheKey, css);
|
|
140
|
+
return css;
|
|
141
|
+
}
|
|
142
|
+
function getInlineCssAssetForMatches(manifest, matches) {
|
|
143
|
+
if (!manifest?.inlineCss) return void 0;
|
|
144
|
+
const css = getInlineCssForHrefs(manifest, getInlineCssHrefsForMatches(manifest, matches));
|
|
145
|
+
return css === void 0 ? void 0 : createInlineCssStyleAsset(css);
|
|
146
|
+
}
|
|
147
|
+
function stripInlinedStylesheetAssets(manifest, routes, matches) {
|
|
148
|
+
if (!manifest.inlineCss) return routes;
|
|
149
|
+
const nextRoutes = {};
|
|
150
|
+
for (const [routeId, route] of Object.entries(routes)) {
|
|
151
|
+
const assets = route.assets?.filter((asset) => !isInlinableStylesheet(manifest, asset));
|
|
152
|
+
const nextRoute = { ...route };
|
|
153
|
+
if (assets) if (assets.length > 0) nextRoute.assets = assets;
|
|
154
|
+
else delete nextRoute.assets;
|
|
155
|
+
nextRoutes[routeId] = nextRoute;
|
|
156
|
+
}
|
|
157
|
+
if (getInlineCssAssetForMatches(manifest, matches)) {
|
|
158
|
+
const rootRoute = nextRoutes["__root__"] ?? {};
|
|
159
|
+
nextRoutes[rootRouteId] = {
|
|
160
|
+
...rootRoute,
|
|
161
|
+
assets: [createInlineCssPlaceholderAsset(), ...rootRoute.assets ?? []]
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
return nextRoutes;
|
|
165
|
+
}
|
|
105
166
|
function attachRouterServerSsrUtils({ router, manifest, getRequestAssets, includeUnmatchedRouteAssets = true }) {
|
|
106
167
|
router.ssr = { get manifest() {
|
|
107
168
|
const requestAssets = getRequestAssets?.();
|
|
108
|
-
|
|
169
|
+
const inlineCssAsset = getInlineCssAssetForMatches(manifest, router.stores.matches.get());
|
|
170
|
+
if (!requestAssets?.length && !inlineCssAsset) return manifest;
|
|
109
171
|
return {
|
|
110
172
|
...manifest,
|
|
111
173
|
routes: {
|
|
112
174
|
...manifest?.routes,
|
|
113
175
|
[rootRouteId]: {
|
|
114
176
|
...manifest?.routes?.[rootRouteId],
|
|
115
|
-
assets: [
|
|
177
|
+
assets: [
|
|
178
|
+
...requestAssets ?? [],
|
|
179
|
+
...inlineCssAsset ? [inlineCssAsset] : [],
|
|
180
|
+
...manifest?.routes?.["__root__"]?.assets ?? []
|
|
181
|
+
]
|
|
116
182
|
}
|
|
117
183
|
}
|
|
118
184
|
};
|
|
@@ -156,10 +222,10 @@ function attachRouterServerSsrUtils({ router, manifest, getRequestAssets, includ
|
|
|
156
222
|
if (currentRouteIds.has(routeId)) nextFilteredRoutes[routeId] = routeManifest;
|
|
157
223
|
else if (includeUnmatchedRouteAssets && routeManifest.assets && routeManifest.assets.length > 0) nextFilteredRoutes[routeId] = { assets: routeManifest.assets };
|
|
158
224
|
}
|
|
159
|
-
|
|
160
|
-
|
|
225
|
+
filteredRoutes = stripInlinedStylesheetAssets(manifest, nextFilteredRoutes, matchesToDehydrate);
|
|
226
|
+
if (isProd) getManifestCache(manifest).set(manifestCacheKey, filteredRoutes);
|
|
161
227
|
}
|
|
162
|
-
manifestToDehydrate = { routes: filteredRoutes };
|
|
228
|
+
manifestToDehydrate = { routes: { ...filteredRoutes } };
|
|
163
229
|
if (opts?.requestAssets?.length) {
|
|
164
230
|
const existingRoot = manifestToDehydrate.routes[rootRouteId];
|
|
165
231
|
manifestToDehydrate.routes[rootRouteId] = {
|