@tanstack/router-core 1.168.17 → 1.168.18
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/Matches.cjs +1 -1
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/config.cjs +1 -1
- package/dist/cjs/config.cjs.map +1 -1
- package/dist/cjs/defer.cjs +1 -1
- package/dist/cjs/defer.cjs.map +1 -1
- package/dist/cjs/isServer/client.cjs +1 -1
- package/dist/cjs/isServer/client.cjs.map +1 -1
- package/dist/cjs/isServer/development.cjs +1 -1
- package/dist/cjs/isServer/development.cjs.map +1 -1
- package/dist/cjs/isServer/server.cjs +1 -1
- package/dist/cjs/isServer/server.cjs.map +1 -1
- package/dist/cjs/link.cjs +1 -1
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/load-matches.cjs +19 -19
- package/dist/cjs/load-matches.cjs.map +1 -1
- package/dist/cjs/new-process-route-tree.cjs +2 -2
- package/dist/cjs/new-process-route-tree.cjs.map +1 -1
- package/dist/cjs/root.cjs +1 -1
- package/dist/cjs/root.cjs.map +1 -1
- package/dist/cjs/router.cjs +2 -2
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/scroll-restoration-script/server.cjs +1 -1
- package/dist/cjs/scroll-restoration-script/server.cjs.map +1 -1
- package/dist/cjs/scroll-restoration.cjs +6 -6
- package/dist/cjs/scroll-restoration.cjs.map +1 -1
- package/dist/cjs/searchParams.cjs +2 -2
- package/dist/cjs/searchParams.cjs.map +1 -1
- package/dist/cjs/ssr/constants.cjs +2 -2
- package/dist/cjs/ssr/constants.cjs.map +1 -1
- package/dist/cjs/ssr/serializer/RawStream.cjs +12 -12
- package/dist/cjs/ssr/serializer/RawStream.cjs.map +1 -1
- package/dist/cjs/ssr/serializer/ShallowErrorPlugin.cjs +1 -1
- package/dist/cjs/ssr/serializer/ShallowErrorPlugin.cjs.map +1 -1
- package/dist/cjs/ssr/serializer/seroval-plugins.cjs +1 -1
- package/dist/cjs/ssr/serializer/seroval-plugins.cjs.map +1 -1
- package/dist/cjs/ssr/ssr-server.cjs +9 -9
- package/dist/cjs/ssr/ssr-server.cjs.map +1 -1
- package/dist/cjs/ssr/transformStreamWithRouter.cjs +6 -6
- package/dist/cjs/ssr/transformStreamWithRouter.cjs.map +1 -1
- package/dist/cjs/utils.cjs +7 -7
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/esm/Matches.js +1 -1
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/config.js +1 -1
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/defer.js +1 -1
- package/dist/esm/defer.js.map +1 -1
- package/dist/esm/isServer/client.js +1 -1
- package/dist/esm/isServer/client.js.map +1 -1
- package/dist/esm/isServer/development.js +1 -1
- package/dist/esm/isServer/development.js.map +1 -1
- package/dist/esm/isServer/server.js +1 -1
- package/dist/esm/isServer/server.js.map +1 -1
- package/dist/esm/link.js +1 -1
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/load-matches.js +19 -19
- package/dist/esm/load-matches.js.map +1 -1
- package/dist/esm/new-process-route-tree.js +2 -2
- package/dist/esm/new-process-route-tree.js.map +1 -1
- package/dist/esm/root.js +1 -1
- package/dist/esm/root.js.map +1 -1
- package/dist/esm/router.js +2 -2
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/scroll-restoration-script/server.js +1 -1
- package/dist/esm/scroll-restoration-script/server.js.map +1 -1
- package/dist/esm/scroll-restoration.js +6 -6
- package/dist/esm/scroll-restoration.js.map +1 -1
- package/dist/esm/searchParams.js +2 -2
- package/dist/esm/searchParams.js.map +1 -1
- package/dist/esm/ssr/constants.js +2 -2
- package/dist/esm/ssr/constants.js.map +1 -1
- package/dist/esm/ssr/serializer/RawStream.js +10 -10
- package/dist/esm/ssr/serializer/RawStream.js.map +1 -1
- package/dist/esm/ssr/serializer/ShallowErrorPlugin.js +1 -1
- package/dist/esm/ssr/serializer/ShallowErrorPlugin.js.map +1 -1
- package/dist/esm/ssr/serializer/seroval-plugins.js +1 -1
- package/dist/esm/ssr/serializer/seroval-plugins.js.map +1 -1
- package/dist/esm/ssr/ssr-server.js +9 -9
- package/dist/esm/ssr/ssr-server.js.map +1 -1
- package/dist/esm/ssr/transformStreamWithRouter.js +6 -6
- package/dist/esm/ssr/transformStreamWithRouter.js.map +1 -1
- package/dist/esm/utils.js +7 -7
- package/dist/esm/utils.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-matches.cjs","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;;;;;;A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ACrB;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.cjs","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":";;;;;;;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xD,OAAO,QAAQ;AAElB,KAAI,SAAS,WAAW,EAAG,QAAO,KAAA;AAElC,QAAO,QAAQ,IAAI,SAAS;;AAG9B,SAAgB,eACd,OACA,uBAAkD,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,MAAa,iBAA4C;CACvD;CACA;CACA;CACA;CACD"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const require_utils = require("./utils.cjs");
|
|
2
2
|
const require_invariant = require("./invariant.cjs");
|
|
3
3
|
const require_lru_cache = require("./lru-cache.cjs");
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const SEGMENT_TYPE_INDEX = 4;
|
|
5
|
+
const SEGMENT_TYPE_PATHLESS = 5;
|
|
6
6
|
function getOpenAndCloseBraces(part) {
|
|
7
7
|
const openBrace = part.indexOf("{");
|
|
8
8
|
if (openBrace === -1) return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"new-process-route-tree.cjs","names":[],"sources":["../../src/new-process-route-tree.ts"],"sourcesContent":["import { invariant } from './invariant'\nimport { createLRUCache } from './lru-cache'\nimport { last } from './utils'\nimport type { LRUCache } from './lru-cache'\n\nexport const SEGMENT_TYPE_PATHNAME = 0\nexport const SEGMENT_TYPE_PARAM = 1\nexport const SEGMENT_TYPE_WILDCARD = 2\nexport const SEGMENT_TYPE_OPTIONAL_PARAM = 3\nconst SEGMENT_TYPE_INDEX = 4\nconst SEGMENT_TYPE_PATHLESS = 5 // only used in matching to represent pathless routes that need to carry more information\n\n/**\n * All the kinds of segments that can be present in a route path.\n */\nexport type SegmentKind =\n | typeof SEGMENT_TYPE_PATHNAME\n | typeof SEGMENT_TYPE_PARAM\n | typeof SEGMENT_TYPE_WILDCARD\n | typeof SEGMENT_TYPE_OPTIONAL_PARAM\n\n/**\n * All the kinds of segments that can be present in the segment tree.\n */\ntype ExtendedSegmentKind =\n | SegmentKind\n | typeof SEGMENT_TYPE_INDEX\n | typeof SEGMENT_TYPE_PATHLESS\n\nfunction getOpenAndCloseBraces(\n part: string,\n): [openBrace: number, closeBrace: number] | null {\n const openBrace = part.indexOf('{')\n if (openBrace === -1) return null\n const closeBrace = part.indexOf('}', openBrace)\n if (closeBrace === -1) return null\n const afterOpen = openBrace + 1\n if (afterOpen >= part.length) return null\n return [openBrace, closeBrace]\n}\n\ntype ParsedSegment = Uint16Array & {\n /** segment type (0 = pathname, 1 = param, 2 = wildcard, 3 = optional param) */\n 0: SegmentKind\n /** index of the end of the prefix */\n 1: number\n /** index of the start of the value */\n 2: number\n /** index of the end of the value */\n 3: number\n /** index of the start of the suffix */\n 4: number\n /** index of the end of the segment */\n 5: number\n}\n\n/**\n * Populates the `output` array with the parsed representation of the given `segment` string.\n *\n * Usage:\n * ```ts\n * let output\n * let cursor = 0\n * while (cursor < path.length) {\n * output = parseSegment(path, cursor, output)\n * const end = output[5]\n * cursor = end + 1\n * ```\n *\n * `output` is stored outside to avoid allocations during repeated calls. It doesn't need to be typed\n * or initialized, it will be done automatically.\n */\nexport function parseSegment(\n /** The full path string containing the segment. */\n path: string,\n /** The starting index of the segment within the path. */\n start: number,\n /** A Uint16Array (length: 6) to populate with the parsed segment data. */\n output: Uint16Array = new Uint16Array(6),\n): ParsedSegment {\n const next = path.indexOf('/', start)\n const end = next === -1 ? path.length : next\n const part = path.substring(start, end)\n\n if (!part || !part.includes('$')) {\n // early escape for static pathname\n output[0] = SEGMENT_TYPE_PATHNAME\n output[1] = start\n output[2] = start\n output[3] = end\n output[4] = end\n output[5] = end\n return output as ParsedSegment\n }\n\n // $ (wildcard)\n if (part === '$') {\n const total = path.length\n output[0] = SEGMENT_TYPE_WILDCARD\n output[1] = start\n output[2] = start\n output[3] = total\n output[4] = total\n output[5] = total\n return output as ParsedSegment\n }\n\n // $paramName\n if (part.charCodeAt(0) === 36) {\n output[0] = SEGMENT_TYPE_PARAM\n output[1] = start\n output[2] = start + 1 // skip '$'\n output[3] = end\n output[4] = end\n output[5] = end\n return output as ParsedSegment\n }\n\n const braces = getOpenAndCloseBraces(part)\n if (braces) {\n const [openBrace, closeBrace] = braces\n const firstChar = part.charCodeAt(openBrace + 1)\n\n // Check for {-$...} (optional param)\n // prefix{-$paramName}suffix\n // /^([^{]*)\\{-\\$([a-zA-Z_$][a-zA-Z0-9_$]*)\\}([^}]*)$/\n if (firstChar === 45) {\n // '-'\n if (\n openBrace + 2 < part.length &&\n part.charCodeAt(openBrace + 2) === 36 // '$'\n ) {\n const paramStart = openBrace + 3\n const paramEnd = closeBrace\n // Validate param name exists\n if (paramStart < paramEnd) {\n output[0] = SEGMENT_TYPE_OPTIONAL_PARAM\n output[1] = start + openBrace\n output[2] = start + paramStart\n output[3] = start + paramEnd\n output[4] = start + closeBrace + 1\n output[5] = end\n return output as ParsedSegment\n }\n }\n } else if (firstChar === 36) {\n // '$'\n const dollarPos = openBrace + 1\n const afterDollar = openBrace + 2\n // Check for {$} (wildcard)\n if (afterDollar === closeBrace) {\n // For wildcard, value should be '$' (from dollarPos to afterDollar)\n // prefix{$}suffix\n // /^([^{]*)\\{\\$\\}([^}]*)$/\n output[0] = SEGMENT_TYPE_WILDCARD\n output[1] = start + openBrace\n output[2] = start + dollarPos\n output[3] = start + afterDollar\n output[4] = start + closeBrace + 1\n output[5] = path.length\n return output as ParsedSegment\n }\n // Regular param {$paramName} - value is the param name (after $)\n // prefix{$paramName}suffix\n // /^([^{]*)\\{\\$([a-zA-Z_$][a-zA-Z0-9_$]*)\\}([^}]*)$/\n output[0] = SEGMENT_TYPE_PARAM\n output[1] = start + openBrace\n output[2] = start + afterDollar\n output[3] = start + closeBrace\n output[4] = start + closeBrace + 1\n output[5] = end\n return output as ParsedSegment\n }\n }\n\n // fallback to static pathname (should never happen)\n output[0] = SEGMENT_TYPE_PATHNAME\n output[1] = start\n output[2] = start\n output[3] = end\n output[4] = end\n output[5] = end\n return output as ParsedSegment\n}\n\n/**\n * Recursively parses the segments of the given route tree and populates a segment trie.\n *\n * @param data A reusable Uint16Array for parsing segments. (non important, we're just avoiding allocations)\n * @param route The current route to parse.\n * @param start The starting index for parsing within the route's full path.\n * @param node The current segment node in the trie to populate.\n * @param onRoute Callback invoked for each route processed.\n */\nfunction parseSegments<TRouteLike extends RouteLike>(\n defaultCaseSensitive: boolean,\n data: Uint16Array,\n route: TRouteLike,\n start: number,\n node: AnySegmentNode<TRouteLike>,\n depth: number,\n onRoute?: (route: TRouteLike) => void,\n) {\n onRoute?.(route)\n let cursor = start\n {\n const path = route.fullPath ?? route.from\n const length = path.length\n const caseSensitive = route.options?.caseSensitive ?? defaultCaseSensitive\n const skipOnParamError = !!(\n route.options?.params?.parse &&\n route.options?.skipRouteOnParseError?.params\n )\n while (cursor < length) {\n const segment = parseSegment(path, cursor, data)\n let nextNode: AnySegmentNode<TRouteLike>\n const start = cursor\n const end = segment[5]\n cursor = end + 1\n depth++\n const kind = segment[0]\n switch (kind) {\n case SEGMENT_TYPE_PATHNAME: {\n const value = path.substring(segment[2], segment[3])\n if (caseSensitive) {\n const existingNode = node.static?.get(value)\n if (existingNode) {\n nextNode = existingNode\n } else {\n node.static ??= new Map()\n const next = createStaticNode<TRouteLike>(\n route.fullPath ?? route.from,\n )\n next.parent = node\n next.depth = depth\n nextNode = next\n node.static.set(value, next)\n }\n } else {\n const name = value.toLowerCase()\n const existingNode = node.staticInsensitive?.get(name)\n if (existingNode) {\n nextNode = existingNode\n } else {\n node.staticInsensitive ??= new Map()\n const next = createStaticNode<TRouteLike>(\n route.fullPath ?? route.from,\n )\n next.parent = node\n next.depth = depth\n nextNode = next\n node.staticInsensitive.set(name, next)\n }\n }\n break\n }\n case SEGMENT_TYPE_PARAM: {\n const prefix_raw = path.substring(start, segment[1])\n const suffix_raw = path.substring(segment[4], end)\n const actuallyCaseSensitive =\n caseSensitive && !!(prefix_raw || suffix_raw)\n const prefix = !prefix_raw\n ? undefined\n : actuallyCaseSensitive\n ? prefix_raw\n : prefix_raw.toLowerCase()\n const suffix = !suffix_raw\n ? undefined\n : actuallyCaseSensitive\n ? suffix_raw\n : suffix_raw.toLowerCase()\n const existingNode =\n !skipOnParamError &&\n node.dynamic?.find(\n (s) =>\n !s.skipOnParamError &&\n s.caseSensitive === actuallyCaseSensitive &&\n s.prefix === prefix &&\n s.suffix === suffix,\n )\n if (existingNode) {\n nextNode = existingNode\n } else {\n const next = createDynamicNode<TRouteLike>(\n SEGMENT_TYPE_PARAM,\n route.fullPath ?? route.from,\n actuallyCaseSensitive,\n prefix,\n suffix,\n )\n nextNode = next\n next.depth = depth\n next.parent = node\n node.dynamic ??= []\n node.dynamic.push(next)\n }\n break\n }\n case SEGMENT_TYPE_OPTIONAL_PARAM: {\n const prefix_raw = path.substring(start, segment[1])\n const suffix_raw = path.substring(segment[4], end)\n const actuallyCaseSensitive =\n caseSensitive && !!(prefix_raw || suffix_raw)\n const prefix = !prefix_raw\n ? undefined\n : actuallyCaseSensitive\n ? prefix_raw\n : prefix_raw.toLowerCase()\n const suffix = !suffix_raw\n ? undefined\n : actuallyCaseSensitive\n ? suffix_raw\n : suffix_raw.toLowerCase()\n const existingNode =\n !skipOnParamError &&\n node.optional?.find(\n (s) =>\n !s.skipOnParamError &&\n s.caseSensitive === actuallyCaseSensitive &&\n s.prefix === prefix &&\n s.suffix === suffix,\n )\n if (existingNode) {\n nextNode = existingNode\n } else {\n const next = createDynamicNode<TRouteLike>(\n SEGMENT_TYPE_OPTIONAL_PARAM,\n route.fullPath ?? route.from,\n actuallyCaseSensitive,\n prefix,\n suffix,\n )\n nextNode = next\n next.parent = node\n next.depth = depth\n node.optional ??= []\n node.optional.push(next)\n }\n break\n }\n case SEGMENT_TYPE_WILDCARD: {\n const prefix_raw = path.substring(start, segment[1])\n const suffix_raw = path.substring(segment[4], end)\n const actuallyCaseSensitive =\n caseSensitive && !!(prefix_raw || suffix_raw)\n const prefix = !prefix_raw\n ? undefined\n : actuallyCaseSensitive\n ? prefix_raw\n : prefix_raw.toLowerCase()\n const suffix = !suffix_raw\n ? undefined\n : actuallyCaseSensitive\n ? suffix_raw\n : suffix_raw.toLowerCase()\n const next = createDynamicNode<TRouteLike>(\n SEGMENT_TYPE_WILDCARD,\n route.fullPath ?? route.from,\n actuallyCaseSensitive,\n prefix,\n suffix,\n )\n nextNode = next\n next.parent = node\n next.depth = depth\n node.wildcard ??= []\n node.wildcard.push(next)\n }\n }\n node = nextNode\n }\n\n // create pathless node\n if (\n skipOnParamError &&\n route.children &&\n !route.isRoot &&\n route.id &&\n route.id.charCodeAt(route.id.lastIndexOf('/') + 1) === 95 /* '_' */\n ) {\n const pathlessNode = createStaticNode<TRouteLike>(\n route.fullPath ?? route.from,\n )\n pathlessNode.kind = SEGMENT_TYPE_PATHLESS\n pathlessNode.parent = node\n depth++\n pathlessNode.depth = depth\n node.pathless ??= []\n node.pathless.push(pathlessNode)\n node = pathlessNode\n }\n\n const isLeaf = (route.path || !route.children) && !route.isRoot\n // create index node\n if (isLeaf && path.endsWith('/')) {\n const indexNode = createStaticNode<TRouteLike>(\n route.fullPath ?? route.from,\n )\n indexNode.kind = SEGMENT_TYPE_INDEX\n indexNode.parent = node\n depth++\n indexNode.depth = depth\n node.index = indexNode\n node = indexNode\n }\n\n node.parse = route.options?.params?.parse ?? null\n node.skipOnParamError = skipOnParamError\n node.parsingPriority = route.options?.skipRouteOnParseError?.priority ?? 0\n\n // make node \"matchable\"\n if (isLeaf && !node.route) {\n node.route = route\n node.fullPath = route.fullPath ?? route.from\n }\n }\n if (route.children)\n for (const child of route.children) {\n parseSegments(\n defaultCaseSensitive,\n data,\n child as TRouteLike,\n cursor,\n node,\n depth,\n onRoute,\n )\n }\n}\n\nfunction sortDynamic(\n a: {\n prefix?: string\n suffix?: string\n caseSensitive: boolean\n skipOnParamError: boolean\n parsingPriority: number\n },\n b: {\n prefix?: string\n suffix?: string\n caseSensitive: boolean\n skipOnParamError: boolean\n parsingPriority: number\n },\n) {\n if (a.skipOnParamError && !b.skipOnParamError) return -1\n if (!a.skipOnParamError && b.skipOnParamError) return 1\n if (\n a.skipOnParamError &&\n b.skipOnParamError &&\n (a.parsingPriority || b.parsingPriority)\n )\n return b.parsingPriority - a.parsingPriority\n if (a.prefix && b.prefix && a.prefix !== b.prefix) {\n if (a.prefix.startsWith(b.prefix)) return -1\n if (b.prefix.startsWith(a.prefix)) return 1\n }\n if (a.suffix && b.suffix && a.suffix !== b.suffix) {\n if (a.suffix.endsWith(b.suffix)) return -1\n if (b.suffix.endsWith(a.suffix)) return 1\n }\n if (a.prefix && !b.prefix) return -1\n if (!a.prefix && b.prefix) return 1\n if (a.suffix && !b.suffix) return -1\n if (!a.suffix && b.suffix) return 1\n if (a.caseSensitive && !b.caseSensitive) return -1\n if (!a.caseSensitive && b.caseSensitive) return 1\n\n // we don't need a tiebreaker here\n // at this point the 2 nodes cannot conflict during matching\n return 0\n}\n\nfunction sortTreeNodes(node: SegmentNode<RouteLike>) {\n if (node.pathless) {\n for (const child of node.pathless) {\n sortTreeNodes(child)\n }\n }\n if (node.static) {\n for (const child of node.static.values()) {\n sortTreeNodes(child)\n }\n }\n if (node.staticInsensitive) {\n for (const child of node.staticInsensitive.values()) {\n sortTreeNodes(child)\n }\n }\n if (node.dynamic?.length) {\n node.dynamic.sort(sortDynamic)\n for (const child of node.dynamic) {\n sortTreeNodes(child)\n }\n }\n if (node.optional?.length) {\n node.optional.sort(sortDynamic)\n for (const child of node.optional) {\n sortTreeNodes(child)\n }\n }\n if (node.wildcard?.length) {\n node.wildcard.sort(sortDynamic)\n for (const child of node.wildcard) {\n sortTreeNodes(child)\n }\n }\n}\n\nfunction createStaticNode<T extends RouteLike>(\n fullPath: string,\n): StaticSegmentNode<T> {\n return {\n kind: SEGMENT_TYPE_PATHNAME,\n depth: 0,\n pathless: null,\n index: null,\n static: null,\n staticInsensitive: null,\n dynamic: null,\n optional: null,\n wildcard: null,\n route: null,\n fullPath,\n parent: null,\n parse: null,\n skipOnParamError: false,\n parsingPriority: 0,\n }\n}\n\n/**\n * Keys must be declared in the same order as in `SegmentNode` type,\n * to ensure they are represented as the same object class in the engine.\n */\nfunction createDynamicNode<T extends RouteLike>(\n kind:\n | typeof SEGMENT_TYPE_PARAM\n | typeof SEGMENT_TYPE_WILDCARD\n | typeof SEGMENT_TYPE_OPTIONAL_PARAM,\n fullPath: string,\n caseSensitive: boolean,\n prefix?: string,\n suffix?: string,\n): DynamicSegmentNode<T> {\n return {\n kind,\n depth: 0,\n pathless: null,\n index: null,\n static: null,\n staticInsensitive: null,\n dynamic: null,\n optional: null,\n wildcard: null,\n route: null,\n fullPath,\n parent: null,\n parse: null,\n skipOnParamError: false,\n parsingPriority: 0,\n caseSensitive,\n prefix,\n suffix,\n }\n}\n\ntype StaticSegmentNode<T extends RouteLike> = SegmentNode<T> & {\n kind:\n | typeof SEGMENT_TYPE_PATHNAME\n | typeof SEGMENT_TYPE_PATHLESS\n | typeof SEGMENT_TYPE_INDEX\n}\n\ntype DynamicSegmentNode<T extends RouteLike> = SegmentNode<T> & {\n kind:\n | typeof SEGMENT_TYPE_PARAM\n | typeof SEGMENT_TYPE_WILDCARD\n | typeof SEGMENT_TYPE_OPTIONAL_PARAM\n prefix?: string\n suffix?: string\n caseSensitive: boolean\n}\n\ntype AnySegmentNode<T extends RouteLike> =\n | StaticSegmentNode<T>\n | DynamicSegmentNode<T>\n\ntype SegmentNode<T extends RouteLike> = {\n kind: ExtendedSegmentKind\n\n pathless: Array<StaticSegmentNode<T>> | null\n\n /** Exact index segment (highest priority) */\n index: StaticSegmentNode<T> | null\n\n /** Static segments (2nd priority) */\n static: Map<string, StaticSegmentNode<T>> | null\n\n /** Case insensitive static segments (3rd highest priority) */\n staticInsensitive: Map<string, StaticSegmentNode<T>> | null\n\n /** Dynamic segments ($param) */\n dynamic: Array<DynamicSegmentNode<T>> | null\n\n /** Optional dynamic segments ({-$param}) */\n optional: Array<DynamicSegmentNode<T>> | null\n\n /** Wildcard segments ($ - lowest priority) */\n wildcard: Array<DynamicSegmentNode<T>> | null\n\n /** Terminal route (if this path can end here) */\n route: T | null\n\n /** The full path for this segment node (will only be valid on leaf nodes) */\n fullPath: string\n\n parent: AnySegmentNode<T> | null\n\n depth: number\n\n /** route.options.params.parse function, set on the last node of the route */\n parse: null | ((params: Record<string, string>) => any)\n\n /** options.skipRouteOnParseError.params ?? false */\n skipOnParamError: boolean\n\n /** options.skipRouteOnParseError.priority ?? 0 */\n parsingPriority: number\n}\n\ntype RouteLike = {\n id?: string\n path?: string // relative path from the parent,\n children?: Array<RouteLike> // child routes,\n parentRoute?: RouteLike // parent route,\n isRoot?: boolean\n options?: {\n skipRouteOnParseError?: {\n params?: boolean\n priority?: number\n }\n caseSensitive?: boolean\n params?: {\n parse?: (params: Record<string, string>) => any\n }\n }\n} &\n // router tree\n (| { fullPath: string; from?: never } // full path from the root\n // flat route masks list\n | { fullPath?: never; from: string } // full path from the root\n )\n\nexport type ProcessedTree<\n TTree extends Extract<RouteLike, { fullPath: string }>,\n TFlat extends Extract<RouteLike, { from: string }>,\n TSingle extends Extract<RouteLike, { from: string }>,\n> = {\n /** a representation of the `routeTree` as a segment tree */\n segmentTree: AnySegmentNode<TTree>\n /** a mini route tree generated from the flat `routeMasks` list */\n masksTree: AnySegmentNode<TFlat> | null\n /** @deprecated keep until v2 so that `router.matchRoute` can keep not caring about the actual route tree */\n singleCache: LRUCache<string, AnySegmentNode<TSingle>>\n /** a cache of route matches from the `segmentTree` */\n matchCache: LRUCache<string, RouteMatch<TTree> | null>\n /** a cache of route matches from the `masksTree` */\n flatCache: LRUCache<string, ReturnType<typeof findMatch<TFlat>>> | null\n}\n\nexport function processRouteMasks<\n TRouteLike extends Extract<RouteLike, { from: string }>,\n>(\n routeList: Array<TRouteLike>,\n processedTree: ProcessedTree<any, TRouteLike, any>,\n) {\n const segmentTree = createStaticNode<TRouteLike>('/')\n const data = new Uint16Array(6)\n for (const route of routeList) {\n parseSegments(false, data, route, 1, segmentTree, 0)\n }\n sortTreeNodes(segmentTree)\n processedTree.masksTree = segmentTree\n processedTree.flatCache = createLRUCache<\n string,\n ReturnType<typeof findMatch<TRouteLike>>\n >(1000)\n}\n\n/**\n * Take an arbitrary list of routes, create a tree from them (if it hasn't been created already), and match a path against it.\n */\nexport function findFlatMatch<T extends Extract<RouteLike, { from: string }>>(\n /** The path to match. */\n path: string,\n /** The `processedTree` returned by the initial `processRouteTree` call. */\n processedTree: ProcessedTree<any, T, any>,\n) {\n path ||= '/'\n const cached = processedTree.flatCache!.get(path)\n if (cached) return cached\n const result = findMatch(path, processedTree.masksTree!)\n processedTree.flatCache!.set(path, result)\n return result\n}\n\n/**\n * @deprecated keep until v2 so that `router.matchRoute` can keep not caring about the actual route tree\n */\nexport function findSingleMatch(\n from: string,\n caseSensitive: boolean,\n fuzzy: boolean,\n path: string,\n processedTree: ProcessedTree<any, any, { from: string }>,\n) {\n from ||= '/'\n path ||= '/'\n const key = caseSensitive ? `case\\0${from}` : from\n let tree = processedTree.singleCache.get(key)\n if (!tree) {\n // single flat routes (router.matchRoute) are not eagerly processed,\n // if we haven't seen this route before, process it now\n tree = createStaticNode<{ from: string }>('/')\n const data = new Uint16Array(6)\n parseSegments(caseSensitive, data, { from }, 1, tree, 0)\n processedTree.singleCache.set(key, tree)\n }\n return findMatch(path, tree, fuzzy)\n}\n\ntype RouteMatch<T extends Extract<RouteLike, { fullPath: string }>> = {\n route: T\n rawParams: Record<string, string>\n parsedParams?: Record<string, unknown>\n branch: ReadonlyArray<T>\n}\n\nexport function findRouteMatch<\n T extends Extract<RouteLike, { fullPath: string }>,\n>(\n /** The path to match against the route tree. */\n path: string,\n /** The `processedTree` returned by the initial `processRouteTree` call. */\n processedTree: ProcessedTree<T, any, any>,\n /** If `true`, allows fuzzy matching (partial matches), i.e. which node in the tree would have been an exact match if the `path` had been shorter? */\n fuzzy = false,\n): RouteMatch<T> | null {\n const key = fuzzy ? path : `nofuzz\\0${path}` // the main use for `findRouteMatch` is fuzzy:true, so we optimize for that case\n const cached = processedTree.matchCache.get(key)\n if (cached !== undefined) return cached\n path ||= '/'\n let result: RouteMatch<T> | null\n\n try {\n result = findMatch(\n path,\n processedTree.segmentTree,\n fuzzy,\n ) as RouteMatch<T> | null\n } catch (err) {\n if (err instanceof URIError) {\n result = null\n } else {\n throw err\n }\n }\n\n if (result) result.branch = buildRouteBranch(result.route)\n processedTree.matchCache.set(key, result)\n return result\n}\n\n/** Trim trailing slashes (except preserving root '/'). */\nexport function trimPathRight(path: string) {\n return path === '/' ? path : path.replace(/\\/{1,}$/, '')\n}\n\nexport interface ProcessRouteTreeResult<\n TRouteLike extends Extract<RouteLike, { fullPath: string }> & { id: string },\n> {\n /** Should be considered a black box, needs to be provided to all matching functions in this module. */\n processedTree: ProcessedTree<TRouteLike, any, any>\n /** A lookup map of routes by their unique IDs. */\n routesById: Record<string, TRouteLike>\n /** A lookup map of routes by their trimmed full paths. */\n routesByPath: Record<string, TRouteLike>\n}\n\n/**\n * Processes a route tree into a segment trie for efficient path matching.\n * Also builds lookup maps for routes by ID and by trimmed full path.\n */\nexport function processRouteTree<\n TRouteLike extends Extract<RouteLike, { fullPath: string }> & { id: string },\n>(\n /** The root of the route tree to process. */\n routeTree: TRouteLike,\n /** Whether matching should be case sensitive by default (overridden by individual route options). */\n caseSensitive: boolean = false,\n /** Optional callback invoked for each route during processing. */\n initRoute?: (route: TRouteLike, index: number) => void,\n): ProcessRouteTreeResult<TRouteLike> {\n const segmentTree = createStaticNode<TRouteLike>(routeTree.fullPath)\n const data = new Uint16Array(6)\n const routesById = {} as Record<string, TRouteLike>\n const routesByPath = {} as Record<string, TRouteLike>\n let index = 0\n parseSegments(caseSensitive, data, routeTree, 1, segmentTree, 0, (route) => {\n initRoute?.(route, index)\n\n if (route.id in routesById) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `Invariant failed: Duplicate routes found with id: ${String(route.id)}`,\n )\n }\n\n invariant()\n }\n\n routesById[route.id] = route\n\n if (index !== 0 && route.path) {\n const trimmedFullPath = trimPathRight(route.fullPath)\n if (!routesByPath[trimmedFullPath] || route.fullPath.endsWith('/')) {\n routesByPath[trimmedFullPath] = route\n }\n }\n\n index++\n })\n sortTreeNodes(segmentTree)\n const processedTree: ProcessedTree<TRouteLike, any, any> = {\n segmentTree,\n singleCache: createLRUCache<string, AnySegmentNode<any>>(1000),\n matchCache: createLRUCache<string, RouteMatch<TRouteLike> | null>(1000),\n flatCache: null,\n masksTree: null,\n }\n return {\n processedTree,\n routesById,\n routesByPath,\n }\n}\n\nfunction findMatch<T extends RouteLike>(\n path: string,\n segmentTree: AnySegmentNode<T>,\n fuzzy = false,\n): {\n route: T\n /**\n * The raw (unparsed) params extracted from the path.\n * This will be the exhaustive list of all params defined in the route's path.\n */\n rawParams: Record<string, string>\n /**\n * The accumlulated parsed params of each route in the branch that had `skipRouteOnParseError` enabled.\n * Will not contain all params defined in the route's path. Those w/ a `params.parse` but no `skipRouteOnParseError` will need to be parsed separately.\n */\n parsedParams?: Record<string, unknown>\n} | null {\n const parts = path.split('/')\n const leaf = getNodeMatch(path, parts, segmentTree, fuzzy)\n if (!leaf) return null\n const [rawParams] = extractParams(path, parts, leaf)\n return {\n route: leaf.node.route!,\n rawParams,\n parsedParams: leaf.parsedParams,\n }\n}\n\ntype ParamExtractionState = {\n part: number\n node: number\n path: number\n segment: number\n}\n\n/**\n * This function is \"resumable\":\n * - the `leaf` input can contain `extract` and `rawParams` properties from a previous `extractParams` call\n * - the returned `state` can be passed back as `extract` in a future call to continue extracting params from where we left off\n *\n * Inputs are *not* mutated.\n */\nfunction extractParams<T extends RouteLike>(\n path: string,\n parts: Array<string>,\n leaf: {\n node: AnySegmentNode<T>\n skipped: number\n extract?: ParamExtractionState\n rawParams?: Record<string, string>\n },\n): [rawParams: Record<string, string>, state: ParamExtractionState] {\n const list = buildBranch(leaf.node)\n let nodeParts: Array<string> | null = null\n const rawParams: Record<string, string> = Object.create(null)\n /** which segment of the path we're currently processing */\n let partIndex = leaf.extract?.part ?? 0\n /** which node of the route tree branch we're currently processing */\n let nodeIndex = leaf.extract?.node ?? 0\n /** index of the 1st character of the segment we're processing in the path string */\n let pathIndex = leaf.extract?.path ?? 0\n /** which fullPath segment we're currently processing */\n let segmentCount = leaf.extract?.segment ?? 0\n for (\n ;\n nodeIndex < list.length;\n partIndex++, nodeIndex++, pathIndex++, segmentCount++\n ) {\n const node = list[nodeIndex]!\n // index nodes are terminating nodes, nothing to extract, just leave\n if (node.kind === SEGMENT_TYPE_INDEX) break\n // pathless nodes do not consume a path segment\n if (node.kind === SEGMENT_TYPE_PATHLESS) {\n segmentCount--\n partIndex--\n pathIndex--\n continue\n }\n const part = parts[partIndex]\n const currentPathIndex = pathIndex\n if (part) pathIndex += part.length\n if (node.kind === SEGMENT_TYPE_PARAM) {\n nodeParts ??= leaf.node.fullPath.split('/')\n const nodePart = nodeParts[segmentCount]!\n const preLength = node.prefix?.length ?? 0\n // we can't rely on the presence of prefix/suffix to know whether it's curly-braced or not, because `/{$param}/` is valid, but has no prefix/suffix\n const isCurlyBraced = nodePart.charCodeAt(preLength) === 123 // '{'\n // param name is extracted at match-time so that tree nodes that are identical except for param name can share the same node\n if (isCurlyBraced) {\n const sufLength = node.suffix?.length ?? 0\n const name = nodePart.substring(\n preLength + 2,\n nodePart.length - sufLength - 1,\n )\n const value = part!.substring(preLength, part!.length - sufLength)\n rawParams[name] = decodeURIComponent(value)\n } else {\n const name = nodePart.substring(1)\n rawParams[name] = decodeURIComponent(part!)\n }\n } else if (node.kind === SEGMENT_TYPE_OPTIONAL_PARAM) {\n if (leaf.skipped & (1 << nodeIndex)) {\n partIndex-- // stay on the same part\n pathIndex = currentPathIndex - 1 // undo pathIndex advancement; -1 to account for loop increment\n continue\n }\n nodeParts ??= leaf.node.fullPath.split('/')\n const nodePart = nodeParts[segmentCount]!\n const preLength = node.prefix?.length ?? 0\n const sufLength = node.suffix?.length ?? 0\n const name = nodePart.substring(\n preLength + 3,\n nodePart.length - sufLength - 1,\n )\n const value =\n node.suffix || node.prefix\n ? part!.substring(preLength, part!.length - sufLength)\n : part\n if (value) rawParams[name] = decodeURIComponent(value)\n } else if (node.kind === SEGMENT_TYPE_WILDCARD) {\n const n = node\n const value = path.substring(\n currentPathIndex + (n.prefix?.length ?? 0),\n path.length - (n.suffix?.length ?? 0),\n )\n const splat = decodeURIComponent(value)\n // TODO: Deprecate *\n rawParams['*'] = splat\n rawParams._splat = splat\n break\n }\n }\n if (leaf.rawParams) Object.assign(rawParams, leaf.rawParams)\n return [\n rawParams,\n {\n part: partIndex,\n node: nodeIndex,\n path: pathIndex,\n segment: segmentCount,\n },\n ]\n}\n\nfunction buildRouteBranch<T extends RouteLike>(route: T) {\n const list = [route]\n while (route.parentRoute) {\n route = route.parentRoute as T\n list.push(route)\n }\n list.reverse()\n return list\n}\n\nfunction buildBranch<T extends RouteLike>(node: AnySegmentNode<T>) {\n const list: Array<AnySegmentNode<T>> = Array(node.depth + 1)\n do {\n list[node.depth] = node\n node = node.parent!\n } while (node)\n return list\n}\n\ntype MatchStackFrame<T extends RouteLike> = {\n node: AnySegmentNode<T>\n /** index of the segment of path */\n index: number\n /** how many nodes between `node` and the root of the segment tree */\n depth: number\n /**\n * Bitmask of skipped optional segments.\n *\n * This is a very performant way of storing an \"array of booleans\", but it means beyond 32 segments we can't track skipped optionals.\n * If we really really need to support more than 32 segments we can switch to using a `BigInt` here. It's about 2x slower in worst case scenarios.\n */\n skipped: number\n /** Positional bitmasks tracking which consumed URL segments matched each segment kind. */\n statics: number\n dynamics: number\n optionals: number\n /** intermediary state for param extraction */\n extract?: ParamExtractionState\n /** intermediary params from param extraction */\n rawParams?: Record<string, string>\n parsedParams?: Record<string, unknown>\n}\n\nfunction getNodeMatch<T extends RouteLike>(\n path: string,\n parts: Array<string>,\n segmentTree: AnySegmentNode<T>,\n fuzzy: boolean,\n) {\n // quick check for root index\n // this is an optimization, algorithm should work correctly without this block\n if (path === '/' && segmentTree.index)\n return { node: segmentTree.index, skipped: 0 } as Pick<\n Frame,\n 'node' | 'skipped' | 'parsedParams'\n >\n\n const trailingSlash = !last(parts)\n const pathIsIndex = trailingSlash && path !== '/'\n const partsLength = parts.length - (trailingSlash ? 1 : 0)\n\n type Frame = MatchStackFrame<T>\n\n // use a stack to explore all possible paths (params cause branching)\n // iterate \"backwards\" (low priority first) so that we can push() each candidate, and pop() the highest priority candidate first\n // - pros: it is depth-first, so we find full matches faster\n // - cons: we cannot short-circuit, because highest priority matches are at the end of the loop (for loop with i--) (but we have no good short-circuiting anyway)\n // other possible approaches:\n // - shift instead of pop (measure performance difference), this allows iterating \"forwards\" (effectively breadth-first)\n // - never remove from the stack, keep a cursor instead. Then we can push \"forwards\" and avoid reversing the order of candidates (effectively breadth-first)\n const stack: Array<Frame> = [\n {\n node: segmentTree,\n index: 1,\n skipped: 0,\n depth: 1,\n statics: 0,\n dynamics: 0,\n optionals: 0,\n },\n ]\n\n let bestFuzzy: Frame | null = null\n let bestMatch: Frame | null = null\n\n while (stack.length) {\n const frame = stack.pop()!\n const { node, index, skipped, depth, statics, dynamics, optionals } = frame\n let { extract, rawParams, parsedParams } = frame\n\n // Wildcard candidates are pushed speculatively as fallbacks in case a\n // higher-priority wildcard later fails params.parse. If a better wildcard\n // has already validated and become bestMatch, lower-priority wildcard\n // fallbacks cannot win anymore and should not run params.parse.\n if (\n node.kind === SEGMENT_TYPE_WILDCARD &&\n node.route &&\n !isFrameMoreSpecific(bestMatch, frame)\n ) {\n continue\n }\n\n if (node.skipOnParamError) {\n const result = validateMatchParams(path, parts, frame)\n if (!result) continue\n rawParams = frame.rawParams\n extract = frame.extract\n parsedParams = frame.parsedParams\n }\n\n // In fuzzy mode, track the best partial match we've found so far\n if (\n fuzzy &&\n node.route &&\n node.kind !== SEGMENT_TYPE_INDEX &&\n isFrameMoreSpecific(bestFuzzy, frame)\n ) {\n bestFuzzy = frame\n }\n\n const isBeyondPath = index === partsLength\n if (isBeyondPath) {\n if (\n node.route &&\n (!pathIsIndex ||\n node.kind === SEGMENT_TYPE_INDEX ||\n node.kind === SEGMENT_TYPE_WILDCARD) &&\n isFrameMoreSpecific(bestMatch, frame)\n ) {\n bestMatch = frame\n }\n // beyond the length of the path parts, only some segment types can match\n if (!node.optional && !node.wildcard && !node.index && !node.pathless)\n continue\n }\n\n const part = isBeyondPath ? undefined : parts[index]!\n let lowerPart: string\n\n // 0. Try index match\n if (isBeyondPath && node.index) {\n const indexFrame = {\n node: node.index,\n index,\n skipped,\n depth: depth + 1,\n statics,\n dynamics,\n optionals,\n extract,\n rawParams,\n parsedParams,\n }\n let indexValid = true\n if (node.index.skipOnParamError) {\n const result = validateMatchParams(path, parts, indexFrame)\n if (!result) indexValid = false\n }\n if (indexValid) {\n // perfect match, no need to continue\n // this is an optimization, algorithm should work correctly without this block\n if (\n !dynamics &&\n !optionals &&\n !skipped &&\n isPerfectStaticMatch(statics, partsLength)\n ) {\n return indexFrame\n }\n if (isFrameMoreSpecific(bestMatch, indexFrame)) {\n // index matches skip the stack because they cannot have children\n bestMatch = indexFrame\n }\n }\n }\n\n // 5. Try wildcard match\n if (node.wildcard) {\n for (let i = node.wildcard.length - 1; i >= 0; i--) {\n const segment = node.wildcard[i]!\n const { prefix, suffix } = segment\n if (prefix) {\n if (isBeyondPath) continue\n const casePart = segment.caseSensitive\n ? part\n : (lowerPart ??= part!.toLowerCase())\n if (!casePart!.startsWith(prefix)) continue\n }\n if (suffix) {\n if (isBeyondPath) continue\n const end = parts.slice(index).join('/').slice(-suffix.length)\n const casePart = segment.caseSensitive ? end : end.toLowerCase()\n if (casePart !== suffix) continue\n }\n // wildcard matches consume the rest of the URL and cannot have children\n stack.push({\n node: segment,\n index: partsLength,\n skipped,\n depth: depth + 1,\n statics,\n dynamics,\n optionals,\n extract,\n rawParams,\n parsedParams,\n })\n }\n }\n\n // 4. Try optional match\n if (node.optional) {\n const nextSkipped = skipped | (1 << depth)\n const nextDepth = depth + 1\n for (let i = node.optional.length - 1; i >= 0; i--) {\n const segment = node.optional[i]!\n // when skipping, node and depth advance by 1, but index doesn't\n stack.push({\n node: segment,\n index,\n skipped: nextSkipped,\n depth: nextDepth,\n statics,\n dynamics,\n optionals,\n extract,\n rawParams,\n parsedParams,\n }) // enqueue skipping the optional\n }\n if (!isBeyondPath) {\n for (let i = node.optional.length - 1; i >= 0; i--) {\n const segment = node.optional[i]!\n const { prefix, suffix } = segment\n if (prefix || suffix) {\n const casePart = segment.caseSensitive\n ? part!\n : (lowerPart ??= part!.toLowerCase())\n if (prefix && !casePart.startsWith(prefix)) continue\n if (suffix && !casePart.endsWith(suffix)) continue\n }\n stack.push({\n node: segment,\n index: index + 1,\n skipped,\n depth: nextDepth,\n statics,\n dynamics,\n optionals: optionals + segmentScore(partsLength, index),\n extract,\n rawParams,\n parsedParams,\n })\n }\n }\n }\n\n // 3. Try dynamic match\n if (!isBeyondPath && node.dynamic && part) {\n for (let i = node.dynamic.length - 1; i >= 0; i--) {\n const segment = node.dynamic[i]!\n const { prefix, suffix } = segment\n if (prefix || suffix) {\n const casePart = segment.caseSensitive\n ? part\n : (lowerPart ??= part.toLowerCase())\n if (prefix && !casePart.startsWith(prefix)) continue\n if (suffix && !casePart.endsWith(suffix)) continue\n }\n stack.push({\n node: segment,\n index: index + 1,\n skipped,\n depth: depth + 1,\n statics,\n dynamics: dynamics + segmentScore(partsLength, index),\n optionals,\n extract,\n rawParams,\n parsedParams,\n })\n }\n }\n\n // 2. Try case insensitive static match\n if (!isBeyondPath && node.staticInsensitive) {\n const match = node.staticInsensitive.get(\n (lowerPart ??= part!.toLowerCase()),\n )\n if (match) {\n stack.push({\n node: match,\n index: index + 1,\n skipped,\n depth: depth + 1,\n statics: statics + segmentScore(partsLength, index),\n dynamics,\n optionals,\n extract,\n rawParams,\n parsedParams,\n })\n }\n }\n\n // 1. Try static match\n if (!isBeyondPath && node.static) {\n const match = node.static.get(part!)\n if (match) {\n stack.push({\n node: match,\n index: index + 1,\n skipped,\n depth: depth + 1,\n statics: statics + segmentScore(partsLength, index),\n dynamics,\n optionals,\n extract,\n rawParams,\n parsedParams,\n })\n }\n }\n\n // 0. Try pathless match\n if (node.pathless) {\n const nextDepth = depth + 1\n for (let i = node.pathless.length - 1; i >= 0; i--) {\n const segment = node.pathless[i]!\n stack.push({\n node: segment,\n index,\n skipped,\n depth: nextDepth,\n statics,\n dynamics,\n optionals,\n extract,\n rawParams,\n parsedParams,\n })\n }\n }\n }\n\n if (bestMatch) return bestMatch\n\n if (fuzzy && bestFuzzy) {\n let sliceIndex = bestFuzzy.index\n for (let i = 0; i < bestFuzzy.index; i++) {\n sliceIndex += parts[i]!.length\n }\n const splat = sliceIndex === path.length ? '/' : path.slice(sliceIndex)\n bestFuzzy.rawParams ??= Object.create(null)\n bestFuzzy.rawParams!['**'] = decodeURIComponent(splat)\n return bestFuzzy\n }\n\n return null\n}\n\nfunction segmentScore(partsLength: number, index: number): number {\n // The specificity scores are bitmasks over consumed URL segments. Earlier\n // URL segments should dominate later ones when comparing scores, so the\n // first real segment gets the highest bit and the last gets bit 0. Since\n // `parts[0]` is the empty string before the leading slash, real URL segments\n // are [1, partsLength), making this segment's bit `partsLength - index - 1`.\n return 2 ** (partsLength - index - 1)\n}\n\nfunction isPerfectStaticMatch(statics: number, partsLength: number): boolean {\n return statics === 2 ** (partsLength - 1) - 1\n}\n\nfunction validateMatchParams<T extends RouteLike>(\n path: string,\n parts: Array<string>,\n frame: MatchStackFrame<T>,\n) {\n try {\n const [rawParams, state] = extractParams(path, parts, frame)\n frame.rawParams = rawParams\n frame.extract = state\n const parsed = frame.node.parse!(rawParams)\n frame.parsedParams = Object.assign(\n Object.create(null),\n frame.parsedParams,\n parsed,\n )\n return true\n } catch {\n return null\n }\n}\n\nfunction isFrameMoreSpecific(\n // the stack frame previously saved as \"best match\"\n prev: MatchStackFrame<any> | null,\n // the candidate stack frame\n next: MatchStackFrame<any>,\n): boolean {\n if (!prev) return true\n return (\n next.statics > prev.statics ||\n (next.statics === prev.statics &&\n (next.dynamics > prev.dynamics ||\n (next.dynamics === prev.dynamics &&\n (next.optionals > prev.optionals ||\n (next.optionals === prev.optionals &&\n ((next.node.kind === SEGMENT_TYPE_INDEX) >\n (prev.node.kind === SEGMENT_TYPE_INDEX) ||\n ((next.node.kind === SEGMENT_TYPE_INDEX) ===\n (prev.node.kind === SEGMENT_TYPE_INDEX) &&\n next.depth > prev.depth)))))))\n )\n}\n"],"mappings":";;;AASA,IAAM,qBAAqB;AAC3B,IAAM,wBAAwB;AAmB9B,SAAS,sBACP,MACgD;CAChD,MAAM,YAAY,KAAK,QAAQ,IAAI;AACnC,KAAI,cAAc,GAAI,QAAO;CAC7B,MAAM,aAAa,KAAK,QAAQ,KAAK,UAAU;AAC/C,KAAI,eAAe,GAAI,QAAO;A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W,QAAQ,mBAAmB,MAAM;AACtD,SAAO;;AAGT,QAAO;;AAGT,SAAS,aAAa,aAAqB,OAAuB;AAMhE,QAAO,MAAM,cAAc,QAAQ;;AAGrC,SAAS,qBAAqB,SAAiB,aAA8B;AAC3E,QAAO,YAAY,MAAM,cAAc,KAAK;;AAG9C,SAAS,oBACP,MACA,OACA,OACA;AACA,KAAI;EACF,MAAM,CAAC,WAAW,SAAS,cAAc,MAAM,OAAO,MAAM;AAC5D,QAAM,YAAY;AAClB,QAAM,UAAU;EAChB,MAAM,SAAS,MAAM,KAAK,MAAO,UAAU;AAC3C,QAAM,eAAe,OAAO,OAC1B,OAAO,OAAO,KAAK,EACnB,MAAM,cACN,OACD;AACD,SAAO;SACD;AACN,SAAO;;;AAIX,SAAS,oBAEP,MAEA,MACS;AACT,KAAI,CAAC,KAAM,QAAO;AAClB,QACE,KAAK,UAAU,KAAK,WACnB,KAAK,YAAY,KAAK,YACpB,KAAK,WAAW,KAAK,YACnB,KAAK,aAAa,KAAK,aACrB,KAAK,YAAY,KAAK,aACpB,KAAK,cAAc,KAAK,eACrB,KAAK,KAAK,SAAS,uBAClB,KAAK,KAAK,SAAS,uBAClB,KAAK,KAAK,SAAS,wBAClB,KAAK,KAAK,SAAS,uBACpB,KAAK,QAAQ,KAAK"}
|
|
1
|
+
{"version":3,"file":"new-process-route-tree.cjs","names":[],"sources":["../../src/new-process-route-tree.ts"],"sourcesContent":["import { invariant } from './invariant'\nimport { createLRUCache } from './lru-cache'\nimport { last } from './utils'\nimport type { LRUCache } from './lru-cache'\n\nexport const SEGMENT_TYPE_PATHNAME = 0\nexport const SEGMENT_TYPE_PARAM = 1\nexport const SEGMENT_TYPE_WILDCARD = 2\nexport const SEGMENT_TYPE_OPTIONAL_PARAM = 3\nconst SEGMENT_TYPE_INDEX = 4\nconst SEGMENT_TYPE_PATHLESS = 5 // only used in matching to represent pathless routes that need to carry more information\n\n/**\n * All the kinds of segments that can be present in a route path.\n */\nexport type SegmentKind =\n | typeof SEGMENT_TYPE_PATHNAME\n | typeof SEGMENT_TYPE_PARAM\n | typeof SEGMENT_TYPE_WILDCARD\n | typeof SEGMENT_TYPE_OPTIONAL_PARAM\n\n/**\n * All the kinds of segments that can be present in the segment tree.\n */\ntype ExtendedSegmentKind =\n | SegmentKind\n | typeof SEGMENT_TYPE_INDEX\n | typeof SEGMENT_TYPE_PATHLESS\n\nfunction getOpenAndCloseBraces(\n part: string,\n): [openBrace: number, closeBrace: number] | null {\n const openBrace = part.indexOf('{')\n if (openBrace === -1) return null\n const closeBrace = part.indexOf('}', openBrace)\n if (closeBrace === -1) return null\n const afterOpen = openBrace + 1\n if (afterOpen >= part.length) return null\n return [openBrace, closeBrace]\n}\n\ntype ParsedSegment = Uint16Array & {\n /** segment type (0 = pathname, 1 = param, 2 = wildcard, 3 = optional param) */\n 0: SegmentKind\n /** index of the end of the prefix */\n 1: number\n /** index of the start of the value */\n 2: number\n /** index of the end of the value */\n 3: number\n /** index of the start of the suffix */\n 4: number\n /** index of the end of the segment */\n 5: number\n}\n\n/**\n * Populates the `output` array with the parsed representation of the given `segment` string.\n *\n * Usage:\n * ```ts\n * let output\n * let cursor = 0\n * while (cursor < path.length) {\n * output = parseSegment(path, cursor, output)\n * const end = output[5]\n * cursor = end + 1\n * ```\n *\n * `output` is stored outside to avoid allocations during repeated calls. It doesn't need to be typed\n * or initialized, it will be done automatically.\n */\nexport function parseSegment(\n /** The full path string containing the segment. */\n path: string,\n /** The starting index of the segment within the path. */\n start: number,\n /** A Uint16Array (length: 6) to populate with the parsed segment data. */\n output: Uint16Array = new Uint16Array(6),\n): ParsedSegment {\n const next = path.indexOf('/', start)\n const end = next === -1 ? path.length : next\n const part = path.substring(start, end)\n\n if (!part || !part.includes('$')) {\n // early escape for static pathname\n output[0] = SEGMENT_TYPE_PATHNAME\n output[1] = start\n output[2] = start\n output[3] = end\n output[4] = end\n output[5] = end\n return output as ParsedSegment\n }\n\n // $ (wildcard)\n if (part === '$') {\n const total = path.length\n output[0] = SEGMENT_TYPE_WILDCARD\n output[1] = start\n output[2] = start\n output[3] = total\n output[4] = total\n output[5] = total\n return output as ParsedSegment\n }\n\n // $paramName\n if (part.charCodeAt(0) === 36) {\n output[0] = SEGMENT_TYPE_PARAM\n output[1] = start\n output[2] = start + 1 // skip '$'\n output[3] = end\n output[4] = end\n output[5] = end\n return output as ParsedSegment\n }\n\n const braces = getOpenAndCloseBraces(part)\n if (braces) {\n const [openBrace, closeBrace] = braces\n const firstChar = part.charCodeAt(openBrace + 1)\n\n // Check for {-$...} (optional param)\n // prefix{-$paramName}suffix\n // /^([^{]*)\\{-\\$([a-zA-Z_$][a-zA-Z0-9_$]*)\\}([^}]*)$/\n if (firstChar === 45) {\n // '-'\n if (\n openBrace + 2 < part.length &&\n part.charCodeAt(openBrace + 2) === 36 // '$'\n ) {\n const paramStart = openBrace + 3\n const paramEnd = closeBrace\n // Validate param name exists\n if (paramStart < paramEnd) {\n output[0] = SEGMENT_TYPE_OPTIONAL_PARAM\n output[1] = start + openBrace\n output[2] = start + paramStart\n output[3] = start + paramEnd\n output[4] = start + closeBrace + 1\n output[5] = end\n return output as ParsedSegment\n }\n }\n } else if (firstChar === 36) {\n // '$'\n const dollarPos = openBrace + 1\n const afterDollar = openBrace + 2\n // Check for {$} (wildcard)\n if (afterDollar === closeBrace) {\n // For wildcard, value should be '$' (from dollarPos to afterDollar)\n // prefix{$}suffix\n // /^([^{]*)\\{\\$\\}([^}]*)$/\n output[0] = SEGMENT_TYPE_WILDCARD\n output[1] = start + openBrace\n output[2] = start + dollarPos\n output[3] = start + afterDollar\n output[4] = start + closeBrace + 1\n output[5] = path.length\n return output as ParsedSegment\n }\n // Regular param {$paramName} - value is the param name (after $)\n // prefix{$paramName}suffix\n // /^([^{]*)\\{\\$([a-zA-Z_$][a-zA-Z0-9_$]*)\\}([^}]*)$/\n output[0] = SEGMENT_TYPE_PARAM\n output[1] = start + openBrace\n output[2] = start + afterDollar\n output[3] = start + closeBrace\n output[4] = start + closeBrace + 1\n output[5] = end\n return output as ParsedSegment\n }\n }\n\n // fallback to static pathname (should never happen)\n output[0] = SEGMENT_TYPE_PATHNAME\n output[1] = start\n output[2] = start\n output[3] = end\n output[4] = end\n output[5] = end\n return output as ParsedSegment\n}\n\n/**\n * Recursively parses the segments of the given route tree and populates a segment trie.\n *\n * @param data A reusable Uint16Array for parsing segments. (non important, we're just avoiding allocations)\n * @param route The current route to parse.\n * @param start The starting index for parsing within the route's full path.\n * @param node The current segment node in the trie to populate.\n * @param onRoute Callback invoked for each route processed.\n */\nfunction parseSegments<TRouteLike extends RouteLike>(\n defaultCaseSensitive: boolean,\n data: Uint16Array,\n route: TRouteLike,\n start: number,\n node: AnySegmentNode<TRouteLike>,\n depth: number,\n onRoute?: (route: TRouteLike) => void,\n) {\n onRoute?.(route)\n let cursor = start\n {\n const path = route.fullPath ?? route.from\n const length = path.length\n const caseSensitive = route.options?.caseSensitive ?? defaultCaseSensitive\n const skipOnParamError = !!(\n route.options?.params?.parse &&\n route.options?.skipRouteOnParseError?.params\n )\n while (cursor < length) {\n const segment = parseSegment(path, cursor, data)\n let nextNode: AnySegmentNode<TRouteLike>\n const start = cursor\n const end = segment[5]\n cursor = end + 1\n depth++\n const kind = segment[0]\n switch (kind) {\n case SEGMENT_TYPE_PATHNAME: {\n const value = path.substring(segment[2], segment[3])\n if (caseSensitive) {\n const existingNode = node.static?.get(value)\n if (existingNode) {\n nextNode = existingNode\n } else {\n node.static ??= new Map()\n const next = createStaticNode<TRouteLike>(\n route.fullPath ?? route.from,\n )\n next.parent = node\n next.depth = depth\n nextNode = next\n node.static.set(value, next)\n }\n } else {\n const name = value.toLowerCase()\n const existingNode = node.staticInsensitive?.get(name)\n if (existingNode) {\n nextNode = existingNode\n } else {\n node.staticInsensitive ??= new Map()\n const next = createStaticNode<TRouteLike>(\n route.fullPath ?? route.from,\n )\n next.parent = node\n next.depth = depth\n nextNode = next\n node.staticInsensitive.set(name, next)\n }\n }\n break\n }\n case SEGMENT_TYPE_PARAM: {\n const prefix_raw = path.substring(start, segment[1])\n const suffix_raw = path.substring(segment[4], end)\n const actuallyCaseSensitive =\n caseSensitive && !!(prefix_raw || suffix_raw)\n const prefix = !prefix_raw\n ? undefined\n : actuallyCaseSensitive\n ? prefix_raw\n : prefix_raw.toLowerCase()\n const suffix = !suffix_raw\n ? undefined\n : actuallyCaseSensitive\n ? suffix_raw\n : suffix_raw.toLowerCase()\n const existingNode =\n !skipOnParamError &&\n node.dynamic?.find(\n (s) =>\n !s.skipOnParamError &&\n s.caseSensitive === actuallyCaseSensitive &&\n s.prefix === prefix &&\n s.suffix === suffix,\n )\n if (existingNode) {\n nextNode = existingNode\n } else {\n const next = createDynamicNode<TRouteLike>(\n SEGMENT_TYPE_PARAM,\n route.fullPath ?? route.from,\n actuallyCaseSensitive,\n prefix,\n suffix,\n )\n nextNode = next\n next.depth = depth\n next.parent = node\n node.dynamic ??= []\n node.dynamic.push(next)\n }\n break\n }\n case SEGMENT_TYPE_OPTIONAL_PARAM: {\n const prefix_raw = path.substring(start, segment[1])\n const suffix_raw = path.substring(segment[4], end)\n const actuallyCaseSensitive =\n caseSensitive && !!(prefix_raw || suffix_raw)\n const prefix = !prefix_raw\n ? undefined\n : actuallyCaseSensitive\n ? prefix_raw\n : prefix_raw.toLowerCase()\n const suffix = !suffix_raw\n ? undefined\n : actuallyCaseSensitive\n ? suffix_raw\n : suffix_raw.toLowerCase()\n const existingNode =\n !skipOnParamError &&\n node.optional?.find(\n (s) =>\n !s.skipOnParamError &&\n s.caseSensitive === actuallyCaseSensitive &&\n s.prefix === prefix &&\n s.suffix === suffix,\n )\n if (existingNode) {\n nextNode = existingNode\n } else {\n const next = createDynamicNode<TRouteLike>(\n SEGMENT_TYPE_OPTIONAL_PARAM,\n route.fullPath ?? route.from,\n actuallyCaseSensitive,\n prefix,\n suffix,\n )\n nextNode = next\n next.parent = node\n next.depth = depth\n node.optional ??= []\n node.optional.push(next)\n }\n break\n }\n case SEGMENT_TYPE_WILDCARD: {\n const prefix_raw = path.substring(start, segment[1])\n const suffix_raw = path.substring(segment[4], end)\n const actuallyCaseSensitive =\n caseSensitive && !!(prefix_raw || suffix_raw)\n const prefix = !prefix_raw\n ? undefined\n : actuallyCaseSensitive\n ? prefix_raw\n : prefix_raw.toLowerCase()\n const suffix = !suffix_raw\n ? undefined\n : actuallyCaseSensitive\n ? suffix_raw\n : suffix_raw.toLowerCase()\n const next = createDynamicNode<TRouteLike>(\n SEGMENT_TYPE_WILDCARD,\n route.fullPath ?? route.from,\n actuallyCaseSensitive,\n prefix,\n suffix,\n )\n nextNode = next\n next.parent = node\n next.depth = depth\n node.wildcard ??= []\n node.wildcard.push(next)\n }\n }\n node = nextNode\n }\n\n // create pathless node\n if (\n skipOnParamError &&\n route.children &&\n !route.isRoot &&\n route.id &&\n route.id.charCodeAt(route.id.lastIndexOf('/') + 1) === 95 /* '_' */\n ) {\n const pathlessNode = createStaticNode<TRouteLike>(\n route.fullPath ?? route.from,\n )\n pathlessNode.kind = SEGMENT_TYPE_PATHLESS\n pathlessNode.parent = node\n depth++\n pathlessNode.depth = depth\n node.pathless ??= []\n node.pathless.push(pathlessNode)\n node = pathlessNode\n }\n\n const isLeaf = (route.path || !route.children) && !route.isRoot\n // create index node\n if (isLeaf && path.endsWith('/')) {\n const indexNode = createStaticNode<TRouteLike>(\n route.fullPath ?? route.from,\n )\n indexNode.kind = SEGMENT_TYPE_INDEX\n indexNode.parent = node\n depth++\n indexNode.depth = depth\n node.index = indexNode\n node = indexNode\n }\n\n node.parse = route.options?.params?.parse ?? null\n node.skipOnParamError = skipOnParamError\n node.parsingPriority = route.options?.skipRouteOnParseError?.priority ?? 0\n\n // make node \"matchable\"\n if (isLeaf && !node.route) {\n node.route = route\n node.fullPath = route.fullPath ?? route.from\n }\n }\n if (route.children)\n for (const child of route.children) {\n parseSegments(\n defaultCaseSensitive,\n data,\n child as TRouteLike,\n cursor,\n node,\n depth,\n onRoute,\n )\n }\n}\n\nfunction sortDynamic(\n a: {\n prefix?: string\n suffix?: string\n caseSensitive: boolean\n skipOnParamError: boolean\n parsingPriority: number\n },\n b: {\n prefix?: string\n suffix?: string\n caseSensitive: boolean\n skipOnParamError: boolean\n parsingPriority: number\n },\n) {\n if (a.skipOnParamError && !b.skipOnParamError) return -1\n if (!a.skipOnParamError && b.skipOnParamError) return 1\n if (\n a.skipOnParamError &&\n b.skipOnParamError &&\n (a.parsingPriority || b.parsingPriority)\n )\n return b.parsingPriority - a.parsingPriority\n if (a.prefix && b.prefix && a.prefix !== b.prefix) {\n if (a.prefix.startsWith(b.prefix)) return -1\n if (b.prefix.startsWith(a.prefix)) return 1\n }\n if (a.suffix && b.suffix && a.suffix !== b.suffix) {\n if (a.suffix.endsWith(b.suffix)) return -1\n if (b.suffix.endsWith(a.suffix)) return 1\n }\n if (a.prefix && !b.prefix) return -1\n if (!a.prefix && b.prefix) return 1\n if (a.suffix && !b.suffix) return -1\n if (!a.suffix && b.suffix) return 1\n if (a.caseSensitive && !b.caseSensitive) return -1\n if (!a.caseSensitive && b.caseSensitive) return 1\n\n // we don't need a tiebreaker here\n // at this point the 2 nodes cannot conflict during matching\n return 0\n}\n\nfunction sortTreeNodes(node: SegmentNode<RouteLike>) {\n if (node.pathless) {\n for (const child of node.pathless) {\n sortTreeNodes(child)\n }\n }\n if (node.static) {\n for (const child of node.static.values()) {\n sortTreeNodes(child)\n }\n }\n if (node.staticInsensitive) {\n for (const child of node.staticInsensitive.values()) {\n sortTreeNodes(child)\n }\n }\n if (node.dynamic?.length) {\n node.dynamic.sort(sortDynamic)\n for (const child of node.dynamic) {\n sortTreeNodes(child)\n }\n }\n if (node.optional?.length) {\n node.optional.sort(sortDynamic)\n for (const child of node.optional) {\n sortTreeNodes(child)\n }\n }\n if (node.wildcard?.length) {\n node.wildcard.sort(sortDynamic)\n for (const child of node.wildcard) {\n sortTreeNodes(child)\n }\n }\n}\n\nfunction createStaticNode<T extends RouteLike>(\n fullPath: string,\n): StaticSegmentNode<T> {\n return {\n kind: SEGMENT_TYPE_PATHNAME,\n depth: 0,\n pathless: null,\n index: null,\n static: null,\n staticInsensitive: null,\n dynamic: null,\n optional: null,\n wildcard: null,\n route: null,\n fullPath,\n parent: null,\n parse: null,\n skipOnParamError: false,\n parsingPriority: 0,\n }\n}\n\n/**\n * Keys must be declared in the same order as in `SegmentNode` type,\n * to ensure they are represented as the same object class in the engine.\n */\nfunction createDynamicNode<T extends RouteLike>(\n kind:\n | typeof SEGMENT_TYPE_PARAM\n | typeof SEGMENT_TYPE_WILDCARD\n | typeof SEGMENT_TYPE_OPTIONAL_PARAM,\n fullPath: string,\n caseSensitive: boolean,\n prefix?: string,\n suffix?: string,\n): DynamicSegmentNode<T> {\n return {\n kind,\n depth: 0,\n pathless: null,\n index: null,\n static: null,\n staticInsensitive: null,\n dynamic: null,\n optional: null,\n wildcard: null,\n route: null,\n fullPath,\n parent: null,\n parse: null,\n skipOnParamError: false,\n parsingPriority: 0,\n caseSensitive,\n prefix,\n suffix,\n }\n}\n\ntype StaticSegmentNode<T extends RouteLike> = SegmentNode<T> & {\n kind:\n | typeof SEGMENT_TYPE_PATHNAME\n | typeof SEGMENT_TYPE_PATHLESS\n | typeof SEGMENT_TYPE_INDEX\n}\n\ntype DynamicSegmentNode<T extends RouteLike> = SegmentNode<T> & {\n kind:\n | typeof SEGMENT_TYPE_PARAM\n | typeof SEGMENT_TYPE_WILDCARD\n | typeof SEGMENT_TYPE_OPTIONAL_PARAM\n prefix?: string\n suffix?: string\n caseSensitive: boolean\n}\n\ntype AnySegmentNode<T extends RouteLike> =\n | StaticSegmentNode<T>\n | DynamicSegmentNode<T>\n\ntype SegmentNode<T extends RouteLike> = {\n kind: ExtendedSegmentKind\n\n pathless: Array<StaticSegmentNode<T>> | null\n\n /** Exact index segment (highest priority) */\n index: StaticSegmentNode<T> | null\n\n /** Static segments (2nd priority) */\n static: Map<string, StaticSegmentNode<T>> | null\n\n /** Case insensitive static segments (3rd highest priority) */\n staticInsensitive: Map<string, StaticSegmentNode<T>> | null\n\n /** Dynamic segments ($param) */\n dynamic: Array<DynamicSegmentNode<T>> | null\n\n /** Optional dynamic segments ({-$param}) */\n optional: Array<DynamicSegmentNode<T>> | null\n\n /** Wildcard segments ($ - lowest priority) */\n wildcard: Array<DynamicSegmentNode<T>> | null\n\n /** Terminal route (if this path can end here) */\n route: T | null\n\n /** The full path for this segment node (will only be valid on leaf nodes) */\n fullPath: string\n\n parent: AnySegmentNode<T> | null\n\n depth: number\n\n /** route.options.params.parse function, set on the last node of the route */\n parse: null | ((params: Record<string, string>) => any)\n\n /** options.skipRouteOnParseError.params ?? false */\n skipOnParamError: boolean\n\n /** options.skipRouteOnParseError.priority ?? 0 */\n parsingPriority: number\n}\n\ntype RouteLike = {\n id?: string\n path?: string // relative path from the parent,\n children?: Array<RouteLike> // child routes,\n parentRoute?: RouteLike // parent route,\n isRoot?: boolean\n options?: {\n skipRouteOnParseError?: {\n params?: boolean\n priority?: number\n }\n caseSensitive?: boolean\n params?: {\n parse?: (params: Record<string, string>) => any\n }\n }\n} &\n // router tree\n (| { fullPath: string; from?: never } // full path from the root\n // flat route masks list\n | { fullPath?: never; from: string } // full path from the root\n )\n\nexport type ProcessedTree<\n TTree extends Extract<RouteLike, { fullPath: string }>,\n TFlat extends Extract<RouteLike, { from: string }>,\n TSingle extends Extract<RouteLike, { from: string }>,\n> = {\n /** a representation of the `routeTree` as a segment tree */\n segmentTree: AnySegmentNode<TTree>\n /** a mini route tree generated from the flat `routeMasks` list */\n masksTree: AnySegmentNode<TFlat> | null\n /** @deprecated keep until v2 so that `router.matchRoute` can keep not caring about the actual route tree */\n singleCache: LRUCache<string, AnySegmentNode<TSingle>>\n /** a cache of route matches from the `segmentTree` */\n matchCache: LRUCache<string, RouteMatch<TTree> | null>\n /** a cache of route matches from the `masksTree` */\n flatCache: LRUCache<string, ReturnType<typeof findMatch<TFlat>>> | null\n}\n\nexport function processRouteMasks<\n TRouteLike extends Extract<RouteLike, { from: string }>,\n>(\n routeList: Array<TRouteLike>,\n processedTree: ProcessedTree<any, TRouteLike, any>,\n) {\n const segmentTree = createStaticNode<TRouteLike>('/')\n const data = new Uint16Array(6)\n for (const route of routeList) {\n parseSegments(false, data, route, 1, segmentTree, 0)\n }\n sortTreeNodes(segmentTree)\n processedTree.masksTree = segmentTree\n processedTree.flatCache = createLRUCache<\n string,\n ReturnType<typeof findMatch<TRouteLike>>\n >(1000)\n}\n\n/**\n * Take an arbitrary list of routes, create a tree from them (if it hasn't been created already), and match a path against it.\n */\nexport function findFlatMatch<T extends Extract<RouteLike, { from: string }>>(\n /** The path to match. */\n path: string,\n /** The `processedTree` returned by the initial `processRouteTree` call. */\n processedTree: ProcessedTree<any, T, any>,\n) {\n path ||= '/'\n const cached = processedTree.flatCache!.get(path)\n if (cached) return cached\n const result = findMatch(path, processedTree.masksTree!)\n processedTree.flatCache!.set(path, result)\n return result\n}\n\n/**\n * @deprecated keep until v2 so that `router.matchRoute` can keep not caring about the actual route tree\n */\nexport function findSingleMatch(\n from: string,\n caseSensitive: boolean,\n fuzzy: boolean,\n path: string,\n processedTree: ProcessedTree<any, any, { from: string }>,\n) {\n from ||= '/'\n path ||= '/'\n const key = caseSensitive ? `case\\0${from}` : from\n let tree = processedTree.singleCache.get(key)\n if (!tree) {\n // single flat routes (router.matchRoute) are not eagerly processed,\n // if we haven't seen this route before, process it now\n tree = createStaticNode<{ from: string }>('/')\n const data = new Uint16Array(6)\n parseSegments(caseSensitive, data, { from }, 1, tree, 0)\n processedTree.singleCache.set(key, tree)\n }\n return findMatch(path, tree, fuzzy)\n}\n\ntype RouteMatch<T extends Extract<RouteLike, { fullPath: string }>> = {\n route: T\n rawParams: Record<string, string>\n parsedParams?: Record<string, unknown>\n branch: ReadonlyArray<T>\n}\n\nexport function findRouteMatch<\n T extends Extract<RouteLike, { fullPath: string }>,\n>(\n /** The path to match against the route tree. */\n path: string,\n /** The `processedTree` returned by the initial `processRouteTree` call. */\n processedTree: ProcessedTree<T, any, any>,\n /** If `true`, allows fuzzy matching (partial matches), i.e. which node in the tree would have been an exact match if the `path` had been shorter? */\n fuzzy = false,\n): RouteMatch<T> | null {\n const key = fuzzy ? path : `nofuzz\\0${path}` // the main use for `findRouteMatch` is fuzzy:true, so we optimize for that case\n const cached = processedTree.matchCache.get(key)\n if (cached !== undefined) return cached\n path ||= '/'\n let result: RouteMatch<T> | null\n\n try {\n result = findMatch(\n path,\n processedTree.segmentTree,\n fuzzy,\n ) as RouteMatch<T> | null\n } catch (err) {\n if (err instanceof URIError) {\n result = null\n } else {\n throw err\n }\n }\n\n if (result) result.branch = buildRouteBranch(result.route)\n processedTree.matchCache.set(key, result)\n return result\n}\n\n/** Trim trailing slashes (except preserving root '/'). */\nexport function trimPathRight(path: string) {\n return path === '/' ? path : path.replace(/\\/{1,}$/, '')\n}\n\nexport interface ProcessRouteTreeResult<\n TRouteLike extends Extract<RouteLike, { fullPath: string }> & { id: string },\n> {\n /** Should be considered a black box, needs to be provided to all matching functions in this module. */\n processedTree: ProcessedTree<TRouteLike, any, any>\n /** A lookup map of routes by their unique IDs. */\n routesById: Record<string, TRouteLike>\n /** A lookup map of routes by their trimmed full paths. */\n routesByPath: Record<string, TRouteLike>\n}\n\n/**\n * Processes a route tree into a segment trie for efficient path matching.\n * Also builds lookup maps for routes by ID and by trimmed full path.\n */\nexport function processRouteTree<\n TRouteLike extends Extract<RouteLike, { fullPath: string }> & { id: string },\n>(\n /** The root of the route tree to process. */\n routeTree: TRouteLike,\n /** Whether matching should be case sensitive by default (overridden by individual route options). */\n caseSensitive: boolean = false,\n /** Optional callback invoked for each route during processing. */\n initRoute?: (route: TRouteLike, index: number) => void,\n): ProcessRouteTreeResult<TRouteLike> {\n const segmentTree = createStaticNode<TRouteLike>(routeTree.fullPath)\n const data = new Uint16Array(6)\n const routesById = {} as Record<string, TRouteLike>\n const routesByPath = {} as Record<string, TRouteLike>\n let index = 0\n parseSegments(caseSensitive, data, routeTree, 1, segmentTree, 0, (route) => {\n initRoute?.(route, index)\n\n if (route.id in routesById) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `Invariant failed: Duplicate routes found with id: ${String(route.id)}`,\n )\n }\n\n invariant()\n }\n\n routesById[route.id] = route\n\n if (index !== 0 && route.path) {\n const trimmedFullPath = trimPathRight(route.fullPath)\n if (!routesByPath[trimmedFullPath] || route.fullPath.endsWith('/')) {\n routesByPath[trimmedFullPath] = route\n }\n }\n\n index++\n })\n sortTreeNodes(segmentTree)\n const processedTree: ProcessedTree<TRouteLike, any, any> = {\n segmentTree,\n singleCache: createLRUCache<string, AnySegmentNode<any>>(1000),\n matchCache: createLRUCache<string, RouteMatch<TRouteLike> | null>(1000),\n flatCache: null,\n masksTree: null,\n }\n return {\n processedTree,\n routesById,\n routesByPath,\n }\n}\n\nfunction findMatch<T extends RouteLike>(\n path: string,\n segmentTree: AnySegmentNode<T>,\n fuzzy = false,\n): {\n route: T\n /**\n * The raw (unparsed) params extracted from the path.\n * This will be the exhaustive list of all params defined in the route's path.\n */\n rawParams: Record<string, string>\n /**\n * The accumlulated parsed params of each route in the branch that had `skipRouteOnParseError` enabled.\n * Will not contain all params defined in the route's path. Those w/ a `params.parse` but no `skipRouteOnParseError` will need to be parsed separately.\n */\n parsedParams?: Record<string, unknown>\n} | null {\n const parts = path.split('/')\n const leaf = getNodeMatch(path, parts, segmentTree, fuzzy)\n if (!leaf) return null\n const [rawParams] = extractParams(path, parts, leaf)\n return {\n route: leaf.node.route!,\n rawParams,\n parsedParams: leaf.parsedParams,\n }\n}\n\ntype ParamExtractionState = {\n part: number\n node: number\n path: number\n segment: number\n}\n\n/**\n * This function is \"resumable\":\n * - the `leaf` input can contain `extract` and `rawParams` properties from a previous `extractParams` call\n * - the returned `state` can be passed back as `extract` in a future call to continue extracting params from where we left off\n *\n * Inputs are *not* mutated.\n */\nfunction extractParams<T extends RouteLike>(\n path: string,\n parts: Array<string>,\n leaf: {\n node: AnySegmentNode<T>\n skipped: number\n extract?: ParamExtractionState\n rawParams?: Record<string, string>\n },\n): [rawParams: Record<string, string>, state: ParamExtractionState] {\n const list = buildBranch(leaf.node)\n let nodeParts: Array<string> | null = null\n const rawParams: Record<string, string> = Object.create(null)\n /** which segment of the path we're currently processing */\n let partIndex = leaf.extract?.part ?? 0\n /** which node of the route tree branch we're currently processing */\n let nodeIndex = leaf.extract?.node ?? 0\n /** index of the 1st character of the segment we're processing in the path string */\n let pathIndex = leaf.extract?.path ?? 0\n /** which fullPath segment we're currently processing */\n let segmentCount = leaf.extract?.segment ?? 0\n for (\n ;\n nodeIndex < list.length;\n partIndex++, nodeIndex++, pathIndex++, segmentCount++\n ) {\n const node = list[nodeIndex]!\n // index nodes are terminating nodes, nothing to extract, just leave\n if (node.kind === SEGMENT_TYPE_INDEX) break\n // pathless nodes do not consume a path segment\n if (node.kind === SEGMENT_TYPE_PATHLESS) {\n segmentCount--\n partIndex--\n pathIndex--\n continue\n }\n const part = parts[partIndex]\n const currentPathIndex = pathIndex\n if (part) pathIndex += part.length\n if (node.kind === SEGMENT_TYPE_PARAM) {\n nodeParts ??= leaf.node.fullPath.split('/')\n const nodePart = nodeParts[segmentCount]!\n const preLength = node.prefix?.length ?? 0\n // we can't rely on the presence of prefix/suffix to know whether it's curly-braced or not, because `/{$param}/` is valid, but has no prefix/suffix\n const isCurlyBraced = nodePart.charCodeAt(preLength) === 123 // '{'\n // param name is extracted at match-time so that tree nodes that are identical except for param name can share the same node\n if (isCurlyBraced) {\n const sufLength = node.suffix?.length ?? 0\n const name = nodePart.substring(\n preLength + 2,\n nodePart.length - sufLength - 1,\n )\n const value = part!.substring(preLength, part!.length - sufLength)\n rawParams[name] = decodeURIComponent(value)\n } else {\n const name = nodePart.substring(1)\n rawParams[name] = decodeURIComponent(part!)\n }\n } else if (node.kind === SEGMENT_TYPE_OPTIONAL_PARAM) {\n if (leaf.skipped & (1 << nodeIndex)) {\n partIndex-- // stay on the same part\n pathIndex = currentPathIndex - 1 // undo pathIndex advancement; -1 to account for loop increment\n continue\n }\n nodeParts ??= leaf.node.fullPath.split('/')\n const nodePart = nodeParts[segmentCount]!\n const preLength = node.prefix?.length ?? 0\n const sufLength = node.suffix?.length ?? 0\n const name = nodePart.substring(\n preLength + 3,\n nodePart.length - sufLength - 1,\n )\n const value =\n node.suffix || node.prefix\n ? part!.substring(preLength, part!.length - sufLength)\n : part\n if (value) rawParams[name] = decodeURIComponent(value)\n } else if (node.kind === SEGMENT_TYPE_WILDCARD) {\n const n = node\n const value = path.substring(\n currentPathIndex + (n.prefix?.length ?? 0),\n path.length - (n.suffix?.length ?? 0),\n )\n const splat = decodeURIComponent(value)\n // TODO: Deprecate *\n rawParams['*'] = splat\n rawParams._splat = splat\n break\n }\n }\n if (leaf.rawParams) Object.assign(rawParams, leaf.rawParams)\n return [\n rawParams,\n {\n part: partIndex,\n node: nodeIndex,\n path: pathIndex,\n segment: segmentCount,\n },\n ]\n}\n\nfunction buildRouteBranch<T extends RouteLike>(route: T) {\n const list = [route]\n while (route.parentRoute) {\n route = route.parentRoute as T\n list.push(route)\n }\n list.reverse()\n return list\n}\n\nfunction buildBranch<T extends RouteLike>(node: AnySegmentNode<T>) {\n const list: Array<AnySegmentNode<T>> = Array(node.depth + 1)\n do {\n list[node.depth] = node\n node = node.parent!\n } while (node)\n return list\n}\n\ntype MatchStackFrame<T extends RouteLike> = {\n node: AnySegmentNode<T>\n /** index of the segment of path */\n index: number\n /** how many nodes between `node` and the root of the segment tree */\n depth: number\n /**\n * Bitmask of skipped optional segments.\n *\n * This is a very performant way of storing an \"array of booleans\", but it means beyond 32 segments we can't track skipped optionals.\n * If we really really need to support more than 32 segments we can switch to using a `BigInt` here. It's about 2x slower in worst case scenarios.\n */\n skipped: number\n /** Positional bitmasks tracking which consumed URL segments matched each segment kind. */\n statics: number\n dynamics: number\n optionals: number\n /** intermediary state for param extraction */\n extract?: ParamExtractionState\n /** intermediary params from param extraction */\n rawParams?: Record<string, string>\n parsedParams?: Record<string, unknown>\n}\n\nfunction getNodeMatch<T extends RouteLike>(\n path: string,\n parts: Array<string>,\n segmentTree: AnySegmentNode<T>,\n fuzzy: boolean,\n) {\n // quick check for root index\n // this is an optimization, algorithm should work correctly without this block\n if (path === '/' && segmentTree.index)\n return { node: segmentTree.index, skipped: 0 } as Pick<\n Frame,\n 'node' | 'skipped' | 'parsedParams'\n >\n\n const trailingSlash = !last(parts)\n const pathIsIndex = trailingSlash && path !== '/'\n const partsLength = parts.length - (trailingSlash ? 1 : 0)\n\n type Frame = MatchStackFrame<T>\n\n // use a stack to explore all possible paths (params cause branching)\n // iterate \"backwards\" (low priority first) so that we can push() each candidate, and pop() the highest priority candidate first\n // - pros: it is depth-first, so we find full matches faster\n // - cons: we cannot short-circuit, because highest priority matches are at the end of the loop (for loop with i--) (but we have no good short-circuiting anyway)\n // other possible approaches:\n // - shift instead of pop (measure performance difference), this allows iterating \"forwards\" (effectively breadth-first)\n // - never remove from the stack, keep a cursor instead. Then we can push \"forwards\" and avoid reversing the order of candidates (effectively breadth-first)\n const stack: Array<Frame> = [\n {\n node: segmentTree,\n index: 1,\n skipped: 0,\n depth: 1,\n statics: 0,\n dynamics: 0,\n optionals: 0,\n },\n ]\n\n let bestFuzzy: Frame | null = null\n let bestMatch: Frame | null = null\n\n while (stack.length) {\n const frame = stack.pop()!\n const { node, index, skipped, depth, statics, dynamics, optionals } = frame\n let { extract, rawParams, parsedParams } = frame\n\n // Wildcard candidates are pushed speculatively as fallbacks in case a\n // higher-priority wildcard later fails params.parse. If a better wildcard\n // has already validated and become bestMatch, lower-priority wildcard\n // fallbacks cannot win anymore and should not run params.parse.\n if (\n node.kind === SEGMENT_TYPE_WILDCARD &&\n node.route &&\n !isFrameMoreSpecific(bestMatch, frame)\n ) {\n continue\n }\n\n if (node.skipOnParamError) {\n const result = validateMatchParams(path, parts, frame)\n if (!result) continue\n rawParams = frame.rawParams\n extract = frame.extract\n parsedParams = frame.parsedParams\n }\n\n // In fuzzy mode, track the best partial match we've found so far\n if (\n fuzzy &&\n node.route &&\n node.kind !== SEGMENT_TYPE_INDEX &&\n isFrameMoreSpecific(bestFuzzy, frame)\n ) {\n bestFuzzy = frame\n }\n\n const isBeyondPath = index === partsLength\n if (isBeyondPath) {\n if (\n node.route &&\n (!pathIsIndex ||\n node.kind === SEGMENT_TYPE_INDEX ||\n node.kind === SEGMENT_TYPE_WILDCARD) &&\n isFrameMoreSpecific(bestMatch, frame)\n ) {\n bestMatch = frame\n }\n // beyond the length of the path parts, only some segment types can match\n if (!node.optional && !node.wildcard && !node.index && !node.pathless)\n continue\n }\n\n const part = isBeyondPath ? undefined : parts[index]!\n let lowerPart: string\n\n // 0. Try index match\n if (isBeyondPath && node.index) {\n const indexFrame = {\n node: node.index,\n index,\n skipped,\n depth: depth + 1,\n statics,\n dynamics,\n optionals,\n extract,\n rawParams,\n parsedParams,\n }\n let indexValid = true\n if (node.index.skipOnParamError) {\n const result = validateMatchParams(path, parts, indexFrame)\n if (!result) indexValid = false\n }\n if (indexValid) {\n // perfect match, no need to continue\n // this is an optimization, algorithm should work correctly without this block\n if (\n !dynamics &&\n !optionals &&\n !skipped &&\n isPerfectStaticMatch(statics, partsLength)\n ) {\n return indexFrame\n }\n if (isFrameMoreSpecific(bestMatch, indexFrame)) {\n // index matches skip the stack because they cannot have children\n bestMatch = indexFrame\n }\n }\n }\n\n // 5. Try wildcard match\n if (node.wildcard) {\n for (let i = node.wildcard.length - 1; i >= 0; i--) {\n const segment = node.wildcard[i]!\n const { prefix, suffix } = segment\n if (prefix) {\n if (isBeyondPath) continue\n const casePart = segment.caseSensitive\n ? part\n : (lowerPart ??= part!.toLowerCase())\n if (!casePart!.startsWith(prefix)) continue\n }\n if (suffix) {\n if (isBeyondPath) continue\n const end = parts.slice(index).join('/').slice(-suffix.length)\n const casePart = segment.caseSensitive ? end : end.toLowerCase()\n if (casePart !== suffix) continue\n }\n // wildcard matches consume the rest of the URL and cannot have children\n stack.push({\n node: segment,\n index: partsLength,\n skipped,\n depth: depth + 1,\n statics,\n dynamics,\n optionals,\n extract,\n rawParams,\n parsedParams,\n })\n }\n }\n\n // 4. Try optional match\n if (node.optional) {\n const nextSkipped = skipped | (1 << depth)\n const nextDepth = depth + 1\n for (let i = node.optional.length - 1; i >= 0; i--) {\n const segment = node.optional[i]!\n // when skipping, node and depth advance by 1, but index doesn't\n stack.push({\n node: segment,\n index,\n skipped: nextSkipped,\n depth: nextDepth,\n statics,\n dynamics,\n optionals,\n extract,\n rawParams,\n parsedParams,\n }) // enqueue skipping the optional\n }\n if (!isBeyondPath) {\n for (let i = node.optional.length - 1; i >= 0; i--) {\n const segment = node.optional[i]!\n const { prefix, suffix } = segment\n if (prefix || suffix) {\n const casePart = segment.caseSensitive\n ? part!\n : (lowerPart ??= part!.toLowerCase())\n if (prefix && !casePart.startsWith(prefix)) continue\n if (suffix && !casePart.endsWith(suffix)) continue\n }\n stack.push({\n node: segment,\n index: index + 1,\n skipped,\n depth: nextDepth,\n statics,\n dynamics,\n optionals: optionals + segmentScore(partsLength, index),\n extract,\n rawParams,\n parsedParams,\n })\n }\n }\n }\n\n // 3. Try dynamic match\n if (!isBeyondPath && node.dynamic && part) {\n for (let i = node.dynamic.length - 1; i >= 0; i--) {\n const segment = node.dynamic[i]!\n const { prefix, suffix } = segment\n if (prefix || suffix) {\n const casePart = segment.caseSensitive\n ? part\n : (lowerPart ??= part.toLowerCase())\n if (prefix && !casePart.startsWith(prefix)) continue\n if (suffix && !casePart.endsWith(suffix)) continue\n }\n stack.push({\n node: segment,\n index: index + 1,\n skipped,\n depth: depth + 1,\n statics,\n dynamics: dynamics + segmentScore(partsLength, index),\n optionals,\n extract,\n rawParams,\n parsedParams,\n })\n }\n }\n\n // 2. Try case insensitive static match\n if (!isBeyondPath && node.staticInsensitive) {\n const match = node.staticInsensitive.get(\n (lowerPart ??= part!.toLowerCase()),\n )\n if (match) {\n stack.push({\n node: match,\n index: index + 1,\n skipped,\n depth: depth + 1,\n statics: statics + segmentScore(partsLength, index),\n dynamics,\n optionals,\n extract,\n rawParams,\n parsedParams,\n })\n }\n }\n\n // 1. Try static match\n if (!isBeyondPath && node.static) {\n const match = node.static.get(part!)\n if (match) {\n stack.push({\n node: match,\n index: index + 1,\n skipped,\n depth: depth + 1,\n statics: statics + segmentScore(partsLength, index),\n dynamics,\n optionals,\n extract,\n rawParams,\n parsedParams,\n })\n }\n }\n\n // 0. Try pathless match\n if (node.pathless) {\n const nextDepth = depth + 1\n for (let i = node.pathless.length - 1; i >= 0; i--) {\n const segment = node.pathless[i]!\n stack.push({\n node: segment,\n index,\n skipped,\n depth: nextDepth,\n statics,\n dynamics,\n optionals,\n extract,\n rawParams,\n parsedParams,\n })\n }\n }\n }\n\n if (bestMatch) return bestMatch\n\n if (fuzzy && bestFuzzy) {\n let sliceIndex = bestFuzzy.index\n for (let i = 0; i < bestFuzzy.index; i++) {\n sliceIndex += parts[i]!.length\n }\n const splat = sliceIndex === path.length ? '/' : path.slice(sliceIndex)\n bestFuzzy.rawParams ??= Object.create(null)\n bestFuzzy.rawParams!['**'] = decodeURIComponent(splat)\n return bestFuzzy\n }\n\n return null\n}\n\nfunction segmentScore(partsLength: number, index: number): number {\n // The specificity scores are bitmasks over consumed URL segments. Earlier\n // URL segments should dominate later ones when comparing scores, so the\n // first real segment gets the highest bit and the last gets bit 0. Since\n // `parts[0]` is the empty string before the leading slash, real URL segments\n // are [1, partsLength), making this segment's bit `partsLength - index - 1`.\n return 2 ** (partsLength - index - 1)\n}\n\nfunction isPerfectStaticMatch(statics: number, partsLength: number): boolean {\n return statics === 2 ** (partsLength - 1) - 1\n}\n\nfunction validateMatchParams<T extends RouteLike>(\n path: string,\n parts: Array<string>,\n frame: MatchStackFrame<T>,\n) {\n try {\n const [rawParams, state] = extractParams(path, parts, frame)\n frame.rawParams = rawParams\n frame.extract = state\n const parsed = frame.node.parse!(rawParams)\n frame.parsedParams = Object.assign(\n Object.create(null),\n frame.parsedParams,\n parsed,\n )\n return true\n } catch {\n return null\n }\n}\n\nfunction isFrameMoreSpecific(\n // the stack frame previously saved as \"best match\"\n prev: MatchStackFrame<any> | null,\n // the candidate stack frame\n next: MatchStackFrame<any>,\n): boolean {\n if (!prev) return true\n return (\n next.statics > prev.statics ||\n (next.statics === prev.statics &&\n (next.dynamics > prev.dynamics ||\n (next.dynamics === prev.dynamics &&\n (next.optionals > prev.optionals ||\n (next.optionals === prev.optionals &&\n ((next.node.kind === SEGMENT_TYPE_INDEX) >\n (prev.node.kind === SEGMENT_TYPE_INDEX) ||\n ((next.node.kind === SEGMENT_TYPE_INDEX) ===\n (prev.node.kind === SEGMENT_TYPE_INDEX) &&\n next.depth > prev.depth)))))))\n )\n}\n"],"mappings":";;;AASA,MAAM,qBAAqB;AAC3B,MAAM,wBAAwB;AAmB9B,SAAS,sBACP,MACgD;CAChD,MAAM,YAAY,KAAK,QAAQ,IAAI;AACnC,KAAI,cAAc,GAAI,QAAO;CAC7B,MAAM,aAAa,KAAK,QAAQ,KAAK,UAAU;AAC/C,KAAI,eAAe,GAAI,QAAO;AAE9B,KADkB,YAAY,KACb,KAAK,OAAQ,QAAO;AACrC,QAAO,CAAC,WAAW,WAAW;;;;;;;;;;;;;;;;;;AAkChC,SAAgB,aAEd,MAEA,OAEA,SAAsB,IAAI,YAAY,EAAE,EACzB;CACf,MAAM,OAAO,KAAK,QAAQ,KAAK,MAAM;CACrC,MAAM,MAAM,SAAS,KAAK,KAAK,SAAS;CACxC,MAAM,OAAO,KAAK,UAAU,OAAO,IAAI;AAEvC,KAAI,CAAC,QAAQ,CAAC,KAAK,SAAS,IAAI,EAAE;AAEhC,SAAO,KAAA;AACP,SAAO,KAAK;AACZ,SAAO,KAAK;AACZ,SAAO,KAAK;AACZ,SAAO,KAAK;AACZ,SAAO,KAAK;AACZ,SAAO;;AAIT,KAAI,SAAS,KAAK;EAChB,MAAM,QAAQ,KAAK;AACnB,SAAO,KAAA;AACP,SAAO,KAAK;AACZ,SAAO,KAAK;AACZ,SAAO,KAAK;AACZ,SAAO,KAAK;AACZ,S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ACnB,KAAK,aAAa,KAAK,aACrB,KAAK,YAAY,KAAK,aACpB,KAAK,cAAc,KAAK,eACrB,KAAK,KAAK,SAAS,uBAClB,KAAK,KAAK,SAAS,uBAClB,KAAK,KAAK,SAAS,wBAClB,KAAK,KAAK,SAAS,uBACpB,KAAK,QAAQ,KAAK"}
|
package/dist/cjs/root.cjs
CHANGED
package/dist/cjs/root.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"root.cjs","names":[],"sources":["../../src/root.ts"],"sourcesContent":["/** Stable identifier used for the root route in a route tree. */\nexport const rootRouteId = '__root__'\nexport type RootRouteId = typeof rootRouteId\n"],"mappings":";;AACA,
|
|
1
|
+
{"version":3,"file":"root.cjs","names":[],"sources":["../../src/root.ts"],"sourcesContent":["/** Stable identifier used for the root route in a route tree. */\nexport const rootRouteId = '__root__'\nexport type RootRouteId = typeof rootRouteId\n"],"mappings":";;AACA,MAAa,cAAc"}
|