@tanstack/router-core 1.166.6 → 1.167.0

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.
Files changed (43) hide show
  1. package/dist/cjs/index.d.cts +1 -1
  2. package/dist/cjs/load-matches.cjs +10 -6
  3. package/dist/cjs/load-matches.cjs.map +1 -1
  4. package/dist/cjs/new-process-route-tree.cjs +7 -3
  5. package/dist/cjs/new-process-route-tree.cjs.map +1 -1
  6. package/dist/cjs/path.cjs +1 -1
  7. package/dist/cjs/path.cjs.map +1 -1
  8. package/dist/cjs/qss.cjs +1 -1
  9. package/dist/cjs/qss.cjs.map +1 -1
  10. package/dist/cjs/route.cjs.map +1 -1
  11. package/dist/cjs/route.d.cts +11 -2
  12. package/dist/cjs/router.cjs +22 -13
  13. package/dist/cjs/router.cjs.map +1 -1
  14. package/dist/cjs/router.d.cts +10 -1
  15. package/dist/cjs/utils.cjs +6 -3
  16. package/dist/cjs/utils.cjs.map +1 -1
  17. package/dist/cjs/utils.d.cts +2 -1
  18. package/dist/esm/index.d.ts +1 -1
  19. package/dist/esm/load-matches.js +10 -6
  20. package/dist/esm/load-matches.js.map +1 -1
  21. package/dist/esm/new-process-route-tree.js +7 -3
  22. package/dist/esm/new-process-route-tree.js.map +1 -1
  23. package/dist/esm/path.js +1 -1
  24. package/dist/esm/path.js.map +1 -1
  25. package/dist/esm/qss.js +1 -1
  26. package/dist/esm/qss.js.map +1 -1
  27. package/dist/esm/route.d.ts +11 -2
  28. package/dist/esm/route.js.map +1 -1
  29. package/dist/esm/router.d.ts +10 -1
  30. package/dist/esm/router.js +23 -14
  31. package/dist/esm/router.js.map +1 -1
  32. package/dist/esm/utils.d.ts +2 -1
  33. package/dist/esm/utils.js +6 -3
  34. package/dist/esm/utils.js.map +1 -1
  35. package/package.json +1 -1
  36. package/src/index.ts +2 -0
  37. package/src/load-matches.ts +24 -7
  38. package/src/new-process-route-tree.ts +8 -4
  39. package/src/path.ts +1 -1
  40. package/src/qss.ts +1 -1
  41. package/src/route.ts +88 -11
  42. package/src/router.ts +34 -14
  43. package/src/utils.ts +12 -3
@@ -7,7 +7,7 @@ import { AnyRedirect, ResolvedRedirect } from './redirect.cjs';
7
7
  import { HistoryLocation, HistoryState, ParsedHistoryState, RouterHistory } from '@tanstack/history';
8
8
  import { Awaitable, Constrain, ControlledPromise, NoInfer, NonNullableUpdater, PickAsRequired, Updater } from './utils.cjs';
9
9
  import { ParsedLocation } from './location.cjs';
10
- import { AnyContext, AnyRoute, AnyRouteWithContext, MakeRemountDepsOptionsUnion, RouteLike, RouteMask } from './route.cjs';
10
+ import { AnyContext, AnyRoute, AnyRouteWithContext, LoaderStaleReloadMode, MakeRemountDepsOptionsUnion, RouteLike, RouteMask } from './route.cjs';
11
11
  import { FullSearchSchema, RouteById, RoutePaths, RoutesById, RoutesByPath } from './routeInfo.cjs';
12
12
  import { AnyRouteMatch, MakeRouteMatchUnion, MatchRouteOptions } from './Matches.cjs';
13
13
  import { BuildLocationFn, CommitLocationOptions, NavigateFn } from './RouterProvider.cjs';
@@ -117,6 +117,15 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TTrailingSlashOption
117
117
  * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#key-options)
118
118
  */
119
119
  defaultStaleTime?: number;
120
+ /**
121
+ * The default stale reload mode a route loader should use if no `loader.staleReloadMode` is provided.
122
+ *
123
+ * `'background'` preserves the current stale-while-revalidate behavior.
124
+ * `'blocking'` waits for stale loader reloads to complete before resolving navigation.
125
+ *
126
+ * @default 'background'
127
+ */
128
+ defaultStaleReloadMode?: LoaderStaleReloadMode;
120
129
  /**
121
130
  * The default `preloadStaleTime` a route should use if no preloadStaleTime is provided.
122
131
  *
@@ -15,7 +15,9 @@ function functionalUpdate(updater, previous) {
15
15
  }
16
16
  const hasOwn = Object.prototype.hasOwnProperty;
17
17
  const isEnumerable = Object.prototype.propertyIsEnumerable;
18
- function replaceEqualDeep(prev, _next, _depth = 0) {
18
+ const createNull = () => /* @__PURE__ */ Object.create(null);
19
+ const nullReplaceEqualDeep = (prev, next) => replaceEqualDeep(prev, next, createNull);
20
+ function replaceEqualDeep(prev, _next, _makeObj = () => ({}), _depth = 0) {
19
21
  if (isServer.isServer) {
20
22
  return _next;
21
23
  }
@@ -32,7 +34,7 @@ function replaceEqualDeep(prev, _next, _depth = 0) {
32
34
  if (!nextItems) return next;
33
35
  const prevSize = prevItems.length;
34
36
  const nextSize = nextItems.length;
35
- const copy = array ? new Array(nextSize) : {};
37
+ const copy = array ? new Array(nextSize) : _makeObj();
36
38
  let equalItems = 0;
37
39
  for (let i = 0; i < nextSize; i++) {
38
40
  const key = array ? i : nextItems[i];
@@ -47,7 +49,7 @@ function replaceEqualDeep(prev, _next, _depth = 0) {
47
49
  copy[key] = n;
48
50
  continue;
49
51
  }
50
- const v = replaceEqualDeep(p, n, _depth + 1);
52
+ const v = replaceEqualDeep(p, n, _makeObj, _depth + 1);
51
53
  copy[key] = v;
52
54
  if (v === p) equalItems++;
53
55
  }
@@ -260,5 +262,6 @@ exports.isPlainArray = isPlainArray;
260
262
  exports.isPlainObject = isPlainObject;
261
263
  exports.isPromise = isPromise;
262
264
  exports.last = last;
265
+ exports.nullReplaceEqualDeep = nullReplaceEqualDeep;
263
266
  exports.replaceEqualDeep = replaceEqualDeep;
264
267
  //# sourceMappingURL=utils.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs","sources":["../../src/utils.ts"],"sourcesContent":["import { isServer } from '@tanstack/router-core/isServer'\nimport type { RouteIds } from './routeInfo'\nimport type { AnyRouter } from './router'\n\nexport type Awaitable<T> = T | Promise<T>\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\nexport type IsAny<TValue, TYesResult, TNoResult = TValue> = 1 extends 0 & TValue\n ? TYesResult\n : TNoResult\n\nexport type PickAsRequired<TValue, TKey extends keyof TValue> = Omit<\n TValue,\n TKey\n> &\n Required<Pick<TValue, TKey>>\n\nexport type PickRequired<T> = {\n [K in keyof T as undefined extends T[K] ? never : K]: T[K]\n}\n\nexport type PickOptional<T> = {\n [K in keyof T as undefined extends T[K] ? K : never]: T[K]\n}\n\n// from https://stackoverflow.com/a/76458160\nexport type WithoutEmpty<T> = T extends any ? ({} extends T ? never : T) : never\n\nexport type Expand<T> = T extends object\n ? T extends infer O\n ? O extends Function\n ? O\n : { [K in keyof O]: O[K] }\n : never\n : T\n\nexport type DeepPartial<T> = T extends object\n ? {\n [P in keyof T]?: DeepPartial<T[P]>\n }\n : T\n\nexport type MakeDifferenceOptional<TLeft, TRight> = keyof TLeft &\n keyof TRight extends never\n ? TRight\n : Omit<TRight, keyof TLeft & keyof TRight> & {\n [K in keyof TLeft & keyof TRight]?: TRight[K]\n }\n\n// from https://stackoverflow.com/a/53955431\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport type IsUnion<T, U extends T = T> = (\n T extends any ? (U extends T ? false : true) : never\n) extends false\n ? false\n : true\n\nexport type IsNonEmptyObject<T> = T extends object\n ? keyof T extends never\n ? false\n : true\n : false\n\nexport type Assign<TLeft, TRight> = TLeft extends any\n ? TRight extends any\n ? IsNonEmptyObject<TLeft> extends false\n ? TRight\n : IsNonEmptyObject<TRight> extends false\n ? TLeft\n : keyof TLeft & keyof TRight extends never\n ? TLeft & TRight\n : Omit<TLeft, keyof TRight> & TRight\n : never\n : never\n\nexport type IntersectAssign<TLeft, TRight> = TLeft extends any\n ? TRight extends any\n ? IsNonEmptyObject<TLeft> extends false\n ? TRight\n : IsNonEmptyObject<TRight> extends false\n ? TLeft\n : TRight & TLeft\n : never\n : never\n\nexport type Timeout = ReturnType<typeof setTimeout>\n\nexport type Updater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev?: TPrevious) => TResult)\n\nexport type NonNullableUpdater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev: TPrevious) => TResult)\n\nexport type ExtractObjects<TUnion> = TUnion extends MergeAllPrimitive\n ? never\n : TUnion\n\nexport type PartialMergeAllObject<TUnion> =\n ExtractObjects<TUnion> extends infer TObj\n ? [TObj] extends [never]\n ? never\n : {\n [TKey in TObj extends any ? keyof TObj : never]?: TObj extends any\n ? TKey extends keyof TObj\n ? TObj[TKey]\n : never\n : never\n }\n : never\n\nexport type MergeAllPrimitive =\n | ReadonlyArray<any>\n | number\n | string\n | bigint\n | boolean\n | symbol\n | undefined\n | null\n\nexport type ExtractPrimitives<TUnion> = TUnion extends MergeAllPrimitive\n ? TUnion\n : TUnion extends object\n ? never\n : TUnion\n\nexport type PartialMergeAll<TUnion> =\n | ExtractPrimitives<TUnion>\n | PartialMergeAllObject<TUnion>\n\nexport type Constrain<T, TConstraint, TDefault = TConstraint> =\n | (T extends TConstraint ? T : never)\n | TDefault\n\nexport type ConstrainLiteral<T, TConstraint, TDefault = TConstraint> =\n | (T & TConstraint)\n | TDefault\n\n/**\n * To be added to router types\n */\nexport type UnionToIntersection<T> = (\n T extends any ? (arg: T) => any : never\n) extends (arg: infer T) => any\n ? T\n : never\n\n/**\n * Merges everything in a union into one object.\n * This mapped type is homomorphic which means it preserves stuff! :)\n */\nexport type MergeAllObjects<\n TUnion,\n TIntersected = UnionToIntersection<ExtractObjects<TUnion>>,\n> = [keyof TIntersected] extends [never]\n ? never\n : {\n [TKey in keyof TIntersected]: TUnion extends any\n ? TUnion[TKey & keyof TUnion]\n : never\n }\n\nexport type MergeAll<TUnion> =\n | MergeAllObjects<TUnion>\n | ExtractPrimitives<TUnion>\n\nexport type ValidateJSON<T> = ((...args: Array<any>) => any) extends T\n ? unknown extends T\n ? never\n : 'Function is not serializable'\n : { [K in keyof T]: ValidateJSON<T[K]> }\n\nexport type LooseReturnType<T> = T extends (\n ...args: Array<any>\n) => infer TReturn\n ? TReturn\n : never\n\nexport type LooseAsyncReturnType<T> = T extends (\n ...args: Array<any>\n) => infer TReturn\n ? TReturn extends Promise<infer TReturn>\n ? TReturn\n : TReturn\n : never\n\n/**\n * Return the last element of an array.\n * Intended for non-empty arrays used within router internals.\n */\nexport function last<T>(arr: ReadonlyArray<T>) {\n return arr[arr.length - 1]\n}\n\nfunction isFunction(d: any): d is Function {\n return typeof d === 'function'\n}\n\n/**\n * Apply a value-or-updater to a previous value.\n * Accepts either a literal value or a function of the previous value.\n */\nexport function functionalUpdate<TPrevious, TResult = TPrevious>(\n updater: Updater<TPrevious, TResult> | NonNullableUpdater<TPrevious, TResult>,\n previous: TPrevious,\n): TResult {\n if (isFunction(updater)) {\n return updater(previous)\n }\n\n return updater\n}\n\nconst hasOwn = Object.prototype.hasOwnProperty\nconst isEnumerable = Object.prototype.propertyIsEnumerable\n\n/**\n * This function returns `prev` if `_next` is deeply equal.\n * If not, it will replace any deeply equal children of `b` with those of `a`.\n * This can be used for structural sharing between immutable JSON values for example.\n * Do not use this with signals\n */\nexport function replaceEqualDeep<T>(prev: any, _next: T, _depth = 0): T {\n if (isServer) {\n return _next\n }\n if (prev === _next) {\n return prev\n }\n\n if (_depth > 500) return _next\n\n const next = _next as any\n\n const array = isPlainArray(prev) && isPlainArray(next)\n\n if (!array && !(isPlainObject(prev) && isPlainObject(next))) return next\n\n const prevItems = array ? prev : getEnumerableOwnKeys(prev)\n if (!prevItems) return next\n const nextItems = array ? next : getEnumerableOwnKeys(next)\n if (!nextItems) return next\n const prevSize = prevItems.length\n const nextSize = nextItems.length\n const copy: any = array ? new Array(nextSize) : {}\n\n let equalItems = 0\n\n for (let i = 0; i < nextSize; i++) {\n const key = array ? i : (nextItems[i] as any)\n const p = prev[key]\n const n = next[key]\n\n if (p === n) {\n copy[key] = p\n if (array ? i < prevSize : hasOwn.call(prev, key)) equalItems++\n continue\n }\n\n if (\n p === null ||\n n === null ||\n typeof p !== 'object' ||\n typeof n !== 'object'\n ) {\n copy[key] = n\n continue\n }\n\n const v = replaceEqualDeep(p, n, _depth + 1)\n copy[key] = v\n if (v === p) equalItems++\n }\n\n return prevSize === nextSize && equalItems === prevSize ? prev : copy\n}\n\n/**\n * Equivalent to `Reflect.ownKeys`, but ensures that objects are \"clone-friendly\":\n * will return false if object has any non-enumerable properties.\n *\n * Optimized for the common case where objects have no symbol properties.\n */\nfunction getEnumerableOwnKeys(o: object) {\n const names = Object.getOwnPropertyNames(o)\n\n // Fast path: check all string property names are enumerable\n for (const name of names) {\n if (!isEnumerable.call(o, name)) return false\n }\n\n // Only check symbols if the object has any (most plain objects don't)\n const symbols = Object.getOwnPropertySymbols(o)\n\n // Fast path: no symbols, return names directly (avoids array allocation/concat)\n if (symbols.length === 0) return names\n\n // Slow path: has symbols, need to check and merge\n const keys: Array<string | symbol> = names\n for (const symbol of symbols) {\n if (!isEnumerable.call(o, symbol)) return false\n keys.push(symbol)\n }\n return keys\n}\n\n// Copied from: https://github.com/jonschlinkert/is-plain-object\nexport function isPlainObject(o: any) {\n if (!hasObjectPrototype(o)) {\n return false\n }\n\n // If has modified constructor\n const ctor = o.constructor\n if (typeof ctor === 'undefined') {\n return true\n }\n\n // If has modified prototype\n const prot = ctor.prototype\n if (!hasObjectPrototype(prot)) {\n return false\n }\n\n // If constructor does not have an Object-specific method\n if (!prot.hasOwnProperty('isPrototypeOf')) {\n return false\n }\n\n // Most likely a plain Object\n return true\n}\n\nfunction hasObjectPrototype(o: any) {\n return Object.prototype.toString.call(o) === '[object Object]'\n}\n\n/**\n * Check if a value is a \"plain\" array (no extra enumerable keys).\n */\nexport function isPlainArray(value: unknown): value is Array<unknown> {\n return Array.isArray(value) && value.length === Object.keys(value).length\n}\n\n/**\n * Perform a deep equality check with options for partial comparison and\n * ignoring `undefined` values. Optimized for router state comparisons.\n */\nexport function deepEqual(\n a: any,\n b: any,\n opts?: { partial?: boolean; ignoreUndefined?: boolean },\n): boolean {\n if (a === b) {\n return true\n }\n\n if (typeof a !== typeof b) {\n return false\n }\n\n if (Array.isArray(a) && Array.isArray(b)) {\n if (a.length !== b.length) return false\n for (let i = 0, l = a.length; i < l; i++) {\n if (!deepEqual(a[i], b[i], opts)) return false\n }\n return true\n }\n\n if (isPlainObject(a) && isPlainObject(b)) {\n const ignoreUndefined = opts?.ignoreUndefined ?? true\n\n if (opts?.partial) {\n for (const k in b) {\n if (!ignoreUndefined || b[k] !== undefined) {\n if (!deepEqual(a[k], b[k], opts)) return false\n }\n }\n return true\n }\n\n let aCount = 0\n if (!ignoreUndefined) {\n aCount = Object.keys(a).length\n } else {\n for (const k in a) {\n if (a[k] !== undefined) aCount++\n }\n }\n\n let bCount = 0\n for (const k in b) {\n if (!ignoreUndefined || b[k] !== undefined) {\n bCount++\n if (bCount > aCount || !deepEqual(a[k], b[k], opts)) return false\n }\n }\n\n return aCount === bCount\n }\n\n return false\n}\n\nexport type StringLiteral<T> = T extends string\n ? string extends T\n ? string\n : T\n : never\n\nexport type ThrowOrOptional<T, TThrow extends boolean> = TThrow extends true\n ? T\n : T | undefined\n\nexport type StrictOrFrom<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean = true,\n> = TStrict extends false\n ? {\n from?: never\n strict: TStrict\n }\n : {\n from: ConstrainLiteral<TFrom, RouteIds<TRouter['routeTree']>>\n strict?: TStrict\n }\n\nexport type ThrowConstraint<\n TStrict extends boolean,\n TThrow extends boolean,\n> = TStrict extends false ? (TThrow extends true ? never : TThrow) : TThrow\n\nexport type ControlledPromise<T> = Promise<T> & {\n resolve: (value: T) => void\n reject: (value: any) => void\n status: 'pending' | 'resolved' | 'rejected'\n value?: T\n}\n\n/**\n * Create a promise with exposed resolve/reject and status fields.\n * Useful for coordinating async router lifecycle operations.\n */\nexport function createControlledPromise<T>(onResolve?: (value: T) => void) {\n let resolveLoadPromise!: (value: T) => void\n let rejectLoadPromise!: (value: any) => void\n\n const controlledPromise = new Promise<T>((resolve, reject) => {\n resolveLoadPromise = resolve\n rejectLoadPromise = reject\n }) as ControlledPromise<T>\n\n controlledPromise.status = 'pending'\n\n controlledPromise.resolve = (value: T) => {\n controlledPromise.status = 'resolved'\n controlledPromise.value = value\n resolveLoadPromise(value)\n onResolve?.(value)\n }\n\n controlledPromise.reject = (e) => {\n controlledPromise.status = 'rejected'\n rejectLoadPromise(e)\n }\n\n return controlledPromise\n}\n\n/**\n * Heuristically detect dynamic import \"module not found\" errors\n * across major browsers for lazy route component handling.\n */\nexport function isModuleNotFoundError(error: any): boolean {\n // chrome: \"Failed to fetch dynamically imported module: http://localhost:5173/src/routes/posts.index.tsx?tsr-split\"\n // firefox: \"error loading dynamically imported module: http://localhost:5173/src/routes/posts.index.tsx?tsr-split\"\n // safari: \"Importing a module script failed.\"\n if (typeof error?.message !== 'string') return false\n return (\n error.message.startsWith('Failed to fetch dynamically imported module') ||\n error.message.startsWith('error loading dynamically imported module') ||\n error.message.startsWith('Importing a module script failed')\n )\n}\n\nexport function isPromise<T>(\n value: Promise<Awaited<T>> | T,\n): value is Promise<Awaited<T>> {\n return Boolean(\n value &&\n typeof value === 'object' &&\n typeof (value as Promise<T>).then === 'function',\n )\n}\n\nexport function findLast<T>(\n array: ReadonlyArray<T>,\n predicate: (item: T) => boolean,\n): T | undefined {\n for (let i = array.length - 1; i >= 0; i--) {\n const item = array[i]!\n if (predicate(item)) return item\n }\n return undefined\n}\n\n/**\n * Remove control characters that can cause open redirect vulnerabilities.\n * Characters like \\r (CR) and \\n (LF) can trick URL parsers into interpreting\n * paths like \"/\\r/evil.com\" as \"http://evil.com\".\n */\nfunction sanitizePathSegment(segment: string): string {\n // Remove ASCII control characters (0x00-0x1F) and DEL (0x7F)\n // These include CR (\\r = 0x0D), LF (\\n = 0x0A), and other potentially dangerous characters\n // eslint-disable-next-line no-control-regex\n return segment.replace(/[\\x00-\\x1f\\x7f]/g, '')\n}\n\nfunction decodeSegment(segment: string): string {\n let decoded: string\n try {\n decoded = decodeURI(segment)\n } catch {\n // if the decoding fails, try to decode the various parts leaving the malformed tags in place\n decoded = segment.replaceAll(/%[0-9A-F]{2}/gi, (match) => {\n try {\n return decodeURI(match)\n } catch {\n return match\n }\n })\n }\n return sanitizePathSegment(decoded)\n}\n\n/**\n * Default list of URL protocols to allow in links, redirects, and navigation.\n * Any absolute URL protocol not in this list is treated as dangerous by default.\n */\nexport const DEFAULT_PROTOCOL_ALLOWLIST = [\n // Standard web navigation\n 'http:',\n 'https:',\n\n // Common browser-safe actions\n 'mailto:',\n 'tel:',\n]\n\n/**\n * Check if a URL string uses a protocol that is not in the allowlist.\n * Returns true for blocked protocols like javascript:, blob:, data:, etc.\n *\n * The URL constructor correctly normalizes:\n * - Mixed case (JavaScript: → javascript:)\n * - Whitespace/control characters (java\\nscript: → javascript:)\n * - Leading whitespace\n *\n * For relative URLs (no protocol), returns false (safe).\n *\n * @param url - The URL string to check\n * @param allowlist - Set of protocols to allow\n * @returns true if the URL uses a protocol that is not allowed\n */\nexport function isDangerousProtocol(\n url: string,\n allowlist: Set<string>,\n): boolean {\n if (!url) return false\n\n try {\n // Use the URL constructor - it correctly normalizes protocols\n // per WHATWG URL spec, handling all bypass attempts automatically\n const parsed = new URL(url)\n return !allowlist.has(parsed.protocol)\n } catch {\n // URL constructor throws for relative URLs (no protocol)\n // These are safe - they can't execute scripts\n return false\n }\n}\n\n// This utility is based on https://github.com/zertosh/htmlescape\n// License: https://github.com/zertosh/htmlescape/blob/0527ca7156a524d256101bb310a9f970f63078ad/LICENSE\nconst HTML_ESCAPE_LOOKUP: { [match: string]: string } = {\n '&': '\\\\u0026',\n '>': '\\\\u003e',\n '<': '\\\\u003c',\n '\\u2028': '\\\\u2028',\n '\\u2029': '\\\\u2029',\n}\n\nconst HTML_ESCAPE_REGEX = /[&><\\u2028\\u2029]/g\n\n/**\n * Escape HTML special characters in a string to prevent XSS attacks\n * when embedding strings in script tags during SSR.\n *\n * This is essential for preventing XSS vulnerabilities when user-controlled\n * content is embedded in inline scripts.\n */\nexport function escapeHtml(str: string): string {\n return str.replace(HTML_ESCAPE_REGEX, (match) => HTML_ESCAPE_LOOKUP[match]!)\n}\n\nexport function decodePath(path: string) {\n if (!path) return { path, handledProtocolRelativeURL: false }\n\n // Fast path: most paths are already decoded and safe.\n // Only fall back to the slower scan/regex path when we see a '%' (encoded),\n // a backslash (explicitly handled), a control character, or a protocol-relative\n // prefix which needs collapsing.\n // eslint-disable-next-line no-control-regex\n if (!/[%\\\\\\x00-\\x1f\\x7f]/.test(path) && !path.startsWith('//')) {\n return { path, handledProtocolRelativeURL: false }\n }\n\n const re = /%25|%5C/gi\n let cursor = 0\n let result = ''\n let match\n while (null !== (match = re.exec(path))) {\n result += decodeSegment(path.slice(cursor, match.index)) + match[0]\n cursor = re.lastIndex\n }\n result = result + decodeSegment(cursor ? path.slice(cursor) : path)\n\n // Prevent open redirect via protocol-relative URLs (e.g. \"//evil.com\")\n // After sanitizing control characters, paths like \"/\\r/evil.com\" become \"//evil.com\"\n // Collapse leading double slashes to a single slash\n let handledProtocolRelativeURL = false\n if (result.startsWith('//')) {\n handledProtocolRelativeURL = true\n result = '/' + result.replace(/^\\/+/, '')\n }\n\n return { path: result, handledProtocolRelativeURL }\n}\n\n/**\n * Encodes a path the same way `new URL()` would, but without the overhead of full URL parsing.\n *\n * This function encodes:\n * - Whitespace characters (spaces → %20, tabs → %09, etc.)\n * - Non-ASCII/Unicode characters (emojis, accented characters, etc.)\n *\n * It preserves:\n * - Already percent-encoded sequences (won't double-encode %2F, %25, etc.)\n * - ASCII special characters valid in URL paths (@, $, &, +, etc.)\n * - Forward slashes as path separators\n *\n * Used to generate proper href values for SSR without constructing URL objects.\n *\n * @example\n * encodePathLikeUrl('/path/file name.pdf') // '/path/file%20name.pdf'\n * encodePathLikeUrl('/path/日本語') // '/path/%E6%97%A5%E6%9C%AC%E8%AA%9E'\n * encodePathLikeUrl('/path/already%20encoded') // '/path/already%20encoded' (preserved)\n */\nexport function encodePathLikeUrl(path: string): string {\n // Encode whitespace and non-ASCII characters that browsers encode in URLs\n\n // biome-ignore lint/suspicious/noControlCharactersInRegex: intentional ASCII range check\n // eslint-disable-next-line no-control-regex\n if (!/\\s|[^\\u0000-\\u007F]/.test(path)) return path\n // biome-ignore lint/suspicious/noControlCharactersInRegex: intentional ASCII range check\n // eslint-disable-next-line no-control-regex\n return path.replace(/\\s|[^\\u0000-\\u007F]/gu, encodeURIComponent)\n}\n\n/**\n * Builds the dev-mode CSS styles URL for route-scoped CSS collection.\n * Used by HeadContent components in all framework implementations to construct\n * the URL for the `/@tanstack-start/styles.css` endpoint.\n *\n * @param basepath - The router's basepath (may or may not have leading slash)\n * @param routeIds - Array of matched route IDs to include in the CSS collection\n * @returns The full URL path for the dev styles CSS endpoint\n */\nexport function buildDevStylesUrl(\n basepath: string,\n routeIds: Array<string>,\n): string {\n // Trim all leading and trailing slashes from basepath\n const trimmedBasepath = basepath.replace(/^\\/+|\\/+$/g, '')\n // Build normalized basepath: empty string for root, or '/path' for non-root\n const normalizedBasepath = trimmedBasepath === '' ? '' : `/${trimmedBasepath}`\n return `${normalizedBasepath}/@tanstack-start/styles.css?routes=${encodeURIComponent(routeIds.join(','))}`\n}\n"],"names":["isServer"],"mappings":";;;AA+LO,SAAS,KAAQ,KAAuB;AAC7C,SAAO,IAAI,IAAI,SAAS,CAAC;AAC3B;AAEA,SAAS,WAAW,GAAuB;AACzC,SAAO,OAAO,MAAM;AACtB;AAMO,SAAS,iBACd,SACA,UACS;AACT,MAAI,WAAW,OAAO,GAAG;AACvB,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAEA,SAAO;AACT;AAEA,MAAM,SAAS,OAAO,UAAU;AAChC,MAAM,eAAe,OAAO,UAAU;AAQ/B,SAAS,iBAAoB,MAAW,OAAU,SAAS,GAAM;AACtE,MAAIA,mBAAU;AACZ,WAAO;AAAA,EACT;AACA,MAAI,SAAS,OAAO;AAClB,WAAO;AAAA,EACT;AAEA,MAAI,SAAS,IAAK,QAAO;AAEzB,QAAM,OAAO;AAEb,QAAM,QAAQ,aAAa,IAAI,KAAK,aAAa,IAAI;AAErD,MAAI,CAAC,SAAS,EAAE,cAAc,IAAI,KAAK,cAAc,IAAI,GAAI,QAAO;AAEpE,QAAM,YAAY,QAAQ,OAAO,qBAAqB,IAAI;AAC1D,MAAI,CAA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Q,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC;AAClE,aAAS,GAAG;AAAA,EACd;AACA,WAAS,SAAS,cAAc,SAAS,KAAK,MAAM,MAAM,IAAI,IAAI;AAKlE,MAAI,6BAA6B;AACjC,MAAI,OAAO,WAAW,IAAI,GAAG;AAC3B,iCAA6B;AAC7B,aAAS,MAAM,OAAO,QAAQ,QAAQ,EAAE;AAAA,EAC1C;AAEA,SAAO,EAAE,MAAM,QAAQ,2BAAA;AACzB;AAqBO,SAAS,kBAAkB,MAAsB;AAKtD,MAAI,CAAC,sBAAsB,KAAK,IAAI,EAAG,QAAO;AAG9C,SAAO,KAAK,QAAQ,yBAAyB,kBAAkB;AACjE;AAWO,SAAS,kBACd,UACA,UACQ;AAER,QAAM,kBAAkB,SAAS,QAAQ,cAAc,EAAE;AAEzD,QAAM,qBAAqB,oBAAoB,KAAK,KAAK,IAAI,eAAe;AAC5E,SAAO,GAAG,kBAAkB,sCAAsC,mBAAmB,SAAS,KAAK,GAAG,CAAC,CAAC;AAC1G;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"utils.cjs","sources":["../../src/utils.ts"],"sourcesContent":["import { isServer } from '@tanstack/router-core/isServer'\nimport type { RouteIds } from './routeInfo'\nimport type { AnyRouter } from './router'\n\nexport type Awaitable<T> = T | Promise<T>\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\nexport type IsAny<TValue, TYesResult, TNoResult = TValue> = 1 extends 0 & TValue\n ? TYesResult\n : TNoResult\n\nexport type PickAsRequired<TValue, TKey extends keyof TValue> = Omit<\n TValue,\n TKey\n> &\n Required<Pick<TValue, TKey>>\n\nexport type PickRequired<T> = {\n [K in keyof T as undefined extends T[K] ? never : K]: T[K]\n}\n\nexport type PickOptional<T> = {\n [K in keyof T as undefined extends T[K] ? K : never]: T[K]\n}\n\n// from https://stackoverflow.com/a/76458160\nexport type WithoutEmpty<T> = T extends any ? ({} extends T ? never : T) : never\n\nexport type Expand<T> = T extends object\n ? T extends infer O\n ? O extends Function\n ? O\n : { [K in keyof O]: O[K] }\n : never\n : T\n\nexport type DeepPartial<T> = T extends object\n ? {\n [P in keyof T]?: DeepPartial<T[P]>\n }\n : T\n\nexport type MakeDifferenceOptional<TLeft, TRight> = keyof TLeft &\n keyof TRight extends never\n ? TRight\n : Omit<TRight, keyof TLeft & keyof TRight> & {\n [K in keyof TLeft & keyof TRight]?: TRight[K]\n }\n\n// from https://stackoverflow.com/a/53955431\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport type IsUnion<T, U extends T = T> = (\n T extends any ? (U extends T ? false : true) : never\n) extends false\n ? false\n : true\n\nexport type IsNonEmptyObject<T> = T extends object\n ? keyof T extends never\n ? false\n : true\n : false\n\nexport type Assign<TLeft, TRight> = TLeft extends any\n ? TRight extends any\n ? IsNonEmptyObject<TLeft> extends false\n ? TRight\n : IsNonEmptyObject<TRight> extends false\n ? TLeft\n : keyof TLeft & keyof TRight extends never\n ? TLeft & TRight\n : Omit<TLeft, keyof TRight> & TRight\n : never\n : never\n\nexport type IntersectAssign<TLeft, TRight> = TLeft extends any\n ? TRight extends any\n ? IsNonEmptyObject<TLeft> extends false\n ? TRight\n : IsNonEmptyObject<TRight> extends false\n ? TLeft\n : TRight & TLeft\n : never\n : never\n\nexport type Timeout = ReturnType<typeof setTimeout>\n\nexport type Updater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev?: TPrevious) => TResult)\n\nexport type NonNullableUpdater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev: TPrevious) => TResult)\n\nexport type ExtractObjects<TUnion> = TUnion extends MergeAllPrimitive\n ? never\n : TUnion\n\nexport type PartialMergeAllObject<TUnion> =\n ExtractObjects<TUnion> extends infer TObj\n ? [TObj] extends [never]\n ? never\n : {\n [TKey in TObj extends any ? keyof TObj : never]?: TObj extends any\n ? TKey extends keyof TObj\n ? TObj[TKey]\n : never\n : never\n }\n : never\n\nexport type MergeAllPrimitive =\n | ReadonlyArray<any>\n | number\n | string\n | bigint\n | boolean\n | symbol\n | undefined\n | null\n\nexport type ExtractPrimitives<TUnion> = TUnion extends MergeAllPrimitive\n ? TUnion\n : TUnion extends object\n ? never\n : TUnion\n\nexport type PartialMergeAll<TUnion> =\n | ExtractPrimitives<TUnion>\n | PartialMergeAllObject<TUnion>\n\nexport type Constrain<T, TConstraint, TDefault = TConstraint> =\n | (T extends TConstraint ? T : never)\n | TDefault\n\nexport type ConstrainLiteral<T, TConstraint, TDefault = TConstraint> =\n | (T & TConstraint)\n | TDefault\n\n/**\n * To be added to router types\n */\nexport type UnionToIntersection<T> = (\n T extends any ? (arg: T) => any : never\n) extends (arg: infer T) => any\n ? T\n : never\n\n/**\n * Merges everything in a union into one object.\n * This mapped type is homomorphic which means it preserves stuff! :)\n */\nexport type MergeAllObjects<\n TUnion,\n TIntersected = UnionToIntersection<ExtractObjects<TUnion>>,\n> = [keyof TIntersected] extends [never]\n ? never\n : {\n [TKey in keyof TIntersected]: TUnion extends any\n ? TUnion[TKey & keyof TUnion]\n : never\n }\n\nexport type MergeAll<TUnion> =\n | MergeAllObjects<TUnion>\n | ExtractPrimitives<TUnion>\n\nexport type ValidateJSON<T> = ((...args: Array<any>) => any) extends T\n ? unknown extends T\n ? never\n : 'Function is not serializable'\n : { [K in keyof T]: ValidateJSON<T[K]> }\n\nexport type LooseReturnType<T> = T extends (\n ...args: Array<any>\n) => infer TReturn\n ? TReturn\n : never\n\nexport type LooseAsyncReturnType<T> = T extends (\n ...args: Array<any>\n) => infer TReturn\n ? TReturn extends Promise<infer TReturn>\n ? TReturn\n : TReturn\n : never\n\n/**\n * Return the last element of an array.\n * Intended for non-empty arrays used within router internals.\n */\nexport function last<T>(arr: ReadonlyArray<T>) {\n return arr[arr.length - 1]\n}\n\nfunction isFunction(d: any): d is Function {\n return typeof d === 'function'\n}\n\n/**\n * Apply a value-or-updater to a previous value.\n * Accepts either a literal value or a function of the previous value.\n */\nexport function functionalUpdate<TPrevious, TResult = TPrevious>(\n updater: Updater<TPrevious, TResult> | NonNullableUpdater<TPrevious, TResult>,\n previous: TPrevious,\n): TResult {\n if (isFunction(updater)) {\n return updater(previous)\n }\n\n return updater\n}\n\nconst hasOwn = Object.prototype.hasOwnProperty\nconst isEnumerable = Object.prototype.propertyIsEnumerable\n\nconst createNull = () => Object.create(null)\nexport const nullReplaceEqualDeep: typeof replaceEqualDeep = (prev, next) =>\n replaceEqualDeep(prev, next, createNull)\n\n/**\n * This function returns `prev` if `_next` is deeply equal.\n * If not, it will replace any deeply equal children of `b` with those of `a`.\n * This can be used for structural sharing between immutable JSON values for example.\n * Do not use this with signals\n */\nexport function replaceEqualDeep<T>(\n prev: any,\n _next: T,\n _makeObj = () => ({}),\n _depth = 0,\n): T {\n if (isServer) {\n return _next\n }\n if (prev === _next) {\n return prev\n }\n\n if (_depth > 500) return _next\n\n const next = _next as any\n\n const array = isPlainArray(prev) && isPlainArray(next)\n\n if (!array && !(isPlainObject(prev) && isPlainObject(next))) return next\n\n const prevItems = array ? prev : getEnumerableOwnKeys(prev)\n if (!prevItems) return next\n const nextItems = array ? next : getEnumerableOwnKeys(next)\n if (!nextItems) return next\n const prevSize = prevItems.length\n const nextSize = nextItems.length\n const copy: any = array ? new Array(nextSize) : _makeObj()\n\n let equalItems = 0\n\n for (let i = 0; i < nextSize; i++) {\n const key = array ? i : (nextItems[i] as any)\n const p = prev[key]\n const n = next[key]\n\n if (p === n) {\n copy[key] = p\n if (array ? i < prevSize : hasOwn.call(prev, key)) equalItems++\n continue\n }\n\n if (\n p === null ||\n n === null ||\n typeof p !== 'object' ||\n typeof n !== 'object'\n ) {\n copy[key] = n\n continue\n }\n\n const v = replaceEqualDeep(p, n, _makeObj, _depth + 1)\n copy[key] = v\n if (v === p) equalItems++\n }\n\n return prevSize === nextSize && equalItems === prevSize ? prev : copy\n}\n\n/**\n * Equivalent to `Reflect.ownKeys`, but ensures that objects are \"clone-friendly\":\n * will return false if object has any non-enumerable properties.\n *\n * Optimized for the common case where objects have no symbol properties.\n */\nfunction getEnumerableOwnKeys(o: object) {\n const names = Object.getOwnPropertyNames(o)\n\n // Fast path: check all string property names are enumerable\n for (const name of names) {\n if (!isEnumerable.call(o, name)) return false\n }\n\n // Only check symbols if the object has any (most plain objects don't)\n const symbols = Object.getOwnPropertySymbols(o)\n\n // Fast path: no symbols, return names directly (avoids array allocation/concat)\n if (symbols.length === 0) return names\n\n // Slow path: has symbols, need to check and merge\n const keys: Array<string | symbol> = names\n for (const symbol of symbols) {\n if (!isEnumerable.call(o, symbol)) return false\n keys.push(symbol)\n }\n return keys\n}\n\n// Copied from: https://github.com/jonschlinkert/is-plain-object\nexport function isPlainObject(o: any) {\n if (!hasObjectPrototype(o)) {\n return false\n }\n\n // If has modified constructor\n const ctor = o.constructor\n if (typeof ctor === 'undefined') {\n return true\n }\n\n // If has modified prototype\n const prot = ctor.prototype\n if (!hasObjectPrototype(prot)) {\n return false\n }\n\n // If constructor does not have an Object-specific method\n if (!prot.hasOwnProperty('isPrototypeOf')) {\n return false\n }\n\n // Most likely a plain Object\n return true\n}\n\nfunction hasObjectPrototype(o: any) {\n return Object.prototype.toString.call(o) === '[object Object]'\n}\n\n/**\n * Check if a value is a \"plain\" array (no extra enumerable keys).\n */\nexport function isPlainArray(value: unknown): value is Array<unknown> {\n return Array.isArray(value) && value.length === Object.keys(value).length\n}\n\n/**\n * Perform a deep equality check with options for partial comparison and\n * ignoring `undefined` values. Optimized for router state comparisons.\n */\nexport function deepEqual(\n a: any,\n b: any,\n opts?: { partial?: boolean; ignoreUndefined?: boolean },\n): boolean {\n if (a === b) {\n return true\n }\n\n if (typeof a !== typeof b) {\n return false\n }\n\n if (Array.isArray(a) && Array.isArray(b)) {\n if (a.length !== b.length) return false\n for (let i = 0, l = a.length; i < l; i++) {\n if (!deepEqual(a[i], b[i], opts)) return false\n }\n return true\n }\n\n if (isPlainObject(a) && isPlainObject(b)) {\n const ignoreUndefined = opts?.ignoreUndefined ?? true\n\n if (opts?.partial) {\n for (const k in b) {\n if (!ignoreUndefined || b[k] !== undefined) {\n if (!deepEqual(a[k], b[k], opts)) return false\n }\n }\n return true\n }\n\n let aCount = 0\n if (!ignoreUndefined) {\n aCount = Object.keys(a).length\n } else {\n for (const k in a) {\n if (a[k] !== undefined) aCount++\n }\n }\n\n let bCount = 0\n for (const k in b) {\n if (!ignoreUndefined || b[k] !== undefined) {\n bCount++\n if (bCount > aCount || !deepEqual(a[k], b[k], opts)) return false\n }\n }\n\n return aCount === bCount\n }\n\n return false\n}\n\nexport type StringLiteral<T> = T extends string\n ? string extends T\n ? string\n : T\n : never\n\nexport type ThrowOrOptional<T, TThrow extends boolean> = TThrow extends true\n ? T\n : T | undefined\n\nexport type StrictOrFrom<\n TRouter extends AnyRouter,\n TFrom,\n TStrict extends boolean = true,\n> = TStrict extends false\n ? {\n from?: never\n strict: TStrict\n }\n : {\n from: ConstrainLiteral<TFrom, RouteIds<TRouter['routeTree']>>\n strict?: TStrict\n }\n\nexport type ThrowConstraint<\n TStrict extends boolean,\n TThrow extends boolean,\n> = TStrict extends false ? (TThrow extends true ? never : TThrow) : TThrow\n\nexport type ControlledPromise<T> = Promise<T> & {\n resolve: (value: T) => void\n reject: (value: any) => void\n status: 'pending' | 'resolved' | 'rejected'\n value?: T\n}\n\n/**\n * Create a promise with exposed resolve/reject and status fields.\n * Useful for coordinating async router lifecycle operations.\n */\nexport function createControlledPromise<T>(onResolve?: (value: T) => void) {\n let resolveLoadPromise!: (value: T) => void\n let rejectLoadPromise!: (value: any) => void\n\n const controlledPromise = new Promise<T>((resolve, reject) => {\n resolveLoadPromise = resolve\n rejectLoadPromise = reject\n }) as ControlledPromise<T>\n\n controlledPromise.status = 'pending'\n\n controlledPromise.resolve = (value: T) => {\n controlledPromise.status = 'resolved'\n controlledPromise.value = value\n resolveLoadPromise(value)\n onResolve?.(value)\n }\n\n controlledPromise.reject = (e) => {\n controlledPromise.status = 'rejected'\n rejectLoadPromise(e)\n }\n\n return controlledPromise\n}\n\n/**\n * Heuristically detect dynamic import \"module not found\" errors\n * across major browsers for lazy route component handling.\n */\nexport function isModuleNotFoundError(error: any): boolean {\n // chrome: \"Failed to fetch dynamically imported module: http://localhost:5173/src/routes/posts.index.tsx?tsr-split\"\n // firefox: \"error loading dynamically imported module: http://localhost:5173/src/routes/posts.index.tsx?tsr-split\"\n // safari: \"Importing a module script failed.\"\n if (typeof error?.message !== 'string') return false\n return (\n error.message.startsWith('Failed to fetch dynamically imported module') ||\n error.message.startsWith('error loading dynamically imported module') ||\n error.message.startsWith('Importing a module script failed')\n )\n}\n\nexport function isPromise<T>(\n value: Promise<Awaited<T>> | T,\n): value is Promise<Awaited<T>> {\n return Boolean(\n value &&\n typeof value === 'object' &&\n typeof (value as Promise<T>).then === 'function',\n )\n}\n\nexport function findLast<T>(\n array: ReadonlyArray<T>,\n predicate: (item: T) => boolean,\n): T | undefined {\n for (let i = array.length - 1; i >= 0; i--) {\n const item = array[i]!\n if (predicate(item)) return item\n }\n return undefined\n}\n\n/**\n * Remove control characters that can cause open redirect vulnerabilities.\n * Characters like \\r (CR) and \\n (LF) can trick URL parsers into interpreting\n * paths like \"/\\r/evil.com\" as \"http://evil.com\".\n */\nfunction sanitizePathSegment(segment: string): string {\n // Remove ASCII control characters (0x00-0x1F) and DEL (0x7F)\n // These include CR (\\r = 0x0D), LF (\\n = 0x0A), and other potentially dangerous characters\n // eslint-disable-next-line no-control-regex\n return segment.replace(/[\\x00-\\x1f\\x7f]/g, '')\n}\n\nfunction decodeSegment(segment: string): string {\n let decoded: string\n try {\n decoded = decodeURI(segment)\n } catch {\n // if the decoding fails, try to decode the various parts leaving the malformed tags in place\n decoded = segment.replaceAll(/%[0-9A-F]{2}/gi, (match) => {\n try {\n return decodeURI(match)\n } catch {\n return match\n }\n })\n }\n return sanitizePathSegment(decoded)\n}\n\n/**\n * Default list of URL protocols to allow in links, redirects, and navigation.\n * Any absolute URL protocol not in this list is treated as dangerous by default.\n */\nexport const DEFAULT_PROTOCOL_ALLOWLIST = [\n // Standard web navigation\n 'http:',\n 'https:',\n\n // Common browser-safe actions\n 'mailto:',\n 'tel:',\n]\n\n/**\n * Check if a URL string uses a protocol that is not in the allowlist.\n * Returns true for blocked protocols like javascript:, blob:, data:, etc.\n *\n * The URL constructor correctly normalizes:\n * - Mixed case (JavaScript: → javascript:)\n * - Whitespace/control characters (java\\nscript: → javascript:)\n * - Leading whitespace\n *\n * For relative URLs (no protocol), returns false (safe).\n *\n * @param url - The URL string to check\n * @param allowlist - Set of protocols to allow\n * @returns true if the URL uses a protocol that is not allowed\n */\nexport function isDangerousProtocol(\n url: string,\n allowlist: Set<string>,\n): boolean {\n if (!url) return false\n\n try {\n // Use the URL constructor - it correctly normalizes protocols\n // per WHATWG URL spec, handling all bypass attempts automatically\n const parsed = new URL(url)\n return !allowlist.has(parsed.protocol)\n } catch {\n // URL constructor throws for relative URLs (no protocol)\n // These are safe - they can't execute scripts\n return false\n }\n}\n\n// This utility is based on https://github.com/zertosh/htmlescape\n// License: https://github.com/zertosh/htmlescape/blob/0527ca7156a524d256101bb310a9f970f63078ad/LICENSE\nconst HTML_ESCAPE_LOOKUP: { [match: string]: string } = {\n '&': '\\\\u0026',\n '>': '\\\\u003e',\n '<': '\\\\u003c',\n '\\u2028': '\\\\u2028',\n '\\u2029': '\\\\u2029',\n}\n\nconst HTML_ESCAPE_REGEX = /[&><\\u2028\\u2029]/g\n\n/**\n * Escape HTML special characters in a string to prevent XSS attacks\n * when embedding strings in script tags during SSR.\n *\n * This is essential for preventing XSS vulnerabilities when user-controlled\n * content is embedded in inline scripts.\n */\nexport function escapeHtml(str: string): string {\n return str.replace(HTML_ESCAPE_REGEX, (match) => HTML_ESCAPE_LOOKUP[match]!)\n}\n\nexport function decodePath(path: string) {\n if (!path) return { path, handledProtocolRelativeURL: false }\n\n // Fast path: most paths are already decoded and safe.\n // Only fall back to the slower scan/regex path when we see a '%' (encoded),\n // a backslash (explicitly handled), a control character, or a protocol-relative\n // prefix which needs collapsing.\n // eslint-disable-next-line no-control-regex\n if (!/[%\\\\\\x00-\\x1f\\x7f]/.test(path) && !path.startsWith('//')) {\n return { path, handledProtocolRelativeURL: false }\n }\n\n const re = /%25|%5C/gi\n let cursor = 0\n let result = ''\n let match\n while (null !== (match = re.exec(path))) {\n result += decodeSegment(path.slice(cursor, match.index)) + match[0]\n cursor = re.lastIndex\n }\n result = result + decodeSegment(cursor ? path.slice(cursor) : path)\n\n // Prevent open redirect via protocol-relative URLs (e.g. \"//evil.com\")\n // After sanitizing control characters, paths like \"/\\r/evil.com\" become \"//evil.com\"\n // Collapse leading double slashes to a single slash\n let handledProtocolRelativeURL = false\n if (result.startsWith('//')) {\n handledProtocolRelativeURL = true\n result = '/' + result.replace(/^\\/+/, '')\n }\n\n return { path: result, handledProtocolRelativeURL }\n}\n\n/**\n * Encodes a path the same way `new URL()` would, but without the overhead of full URL parsing.\n *\n * This function encodes:\n * - Whitespace characters (spaces → %20, tabs → %09, etc.)\n * - Non-ASCII/Unicode characters (emojis, accented characters, etc.)\n *\n * It preserves:\n * - Already percent-encoded sequences (won't double-encode %2F, %25, etc.)\n * - ASCII special characters valid in URL paths (@, $, &, +, etc.)\n * - Forward slashes as path separators\n *\n * Used to generate proper href values for SSR without constructing URL objects.\n *\n * @example\n * encodePathLikeUrl('/path/file name.pdf') // '/path/file%20name.pdf'\n * encodePathLikeUrl('/path/日本語') // '/path/%E6%97%A5%E6%9C%AC%E8%AA%9E'\n * encodePathLikeUrl('/path/already%20encoded') // '/path/already%20encoded' (preserved)\n */\nexport function encodePathLikeUrl(path: string): string {\n // Encode whitespace and non-ASCII characters that browsers encode in URLs\n\n // biome-ignore lint/suspicious/noControlCharactersInRegex: intentional ASCII range check\n // eslint-disable-next-line no-control-regex\n if (!/\\s|[^\\u0000-\\u007F]/.test(path)) return path\n // biome-ignore lint/suspicious/noControlCharactersInRegex: intentional ASCII range check\n // eslint-disable-next-line no-control-regex\n return path.replace(/\\s|[^\\u0000-\\u007F]/gu, encodeURIComponent)\n}\n\n/**\n * Builds the dev-mode CSS styles URL for route-scoped CSS collection.\n * Used by HeadContent components in all framework implementations to construct\n * the URL for the `/@tanstack-start/styles.css` endpoint.\n *\n * @param basepath - The router's basepath (may or may not have leading slash)\n * @param routeIds - Array of matched route IDs to include in the CSS collection\n * @returns The full URL path for the dev styles CSS endpoint\n */\nexport function buildDevStylesUrl(\n basepath: string,\n routeIds: Array<string>,\n): string {\n // Trim all leading and trailing slashes from basepath\n const trimmedBasepath = basepath.replace(/^\\/+|\\/+$/g, '')\n // Build normalized basepath: empty string for root, or '/path' for non-root\n const normalizedBasepath = trimmedBasepath === '' ? '' : `/${trimmedBasepath}`\n return `${normalizedBasepath}/@tanstack-start/styles.css?routes=${encodeURIComponent(routeIds.join(','))}`\n}\n"],"names":["isServer"],"mappings":";;;AA+LO,SAAS,KAAQ,KAAuB;AAC7C,SAAO,IAAI,IAAI,SAAS,CAAC;AAC3B;AAEA,SAAS,WAAW,GAAuB;AACzC,SAAO,OAAO,MAAM;AACtB;AAMO,SAAS,iBACd,SACA,UACS;AACT,MAAI,WAAW,OAAO,GAAG;AACvB,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAEA,SAAO;AACT;AAEA,MAAM,SAAS,OAAO,UAAU;AAChC,MAAM,eAAe,OAAO,UAAU;AAEtC,MAAM,aAAa,MAAM,uBAAO,OAAO,IAAI;AACpC,MAAM,uBAAgD,CAAC,MAAM,SAClE,iBAAiB,MAAM,MAAM,UAAU;AAQlC,SAAS,iBACd,MACA,OACA,WAAW,OAAO,KAClB,SAAS,GACN;AACH,MAAIA,mBAAU;AACZ,WAAO;AAAA,EACT;AACA,MAAI,SAAS,OAAO;AAClB,WAAO;AAAA,EACT;AAEA,MAAI,SAAS,IAAK,QAAO;AAEzB,QAAM,OAAO;AAEb,QAAM,QAAQ,aAAa,IAAI,KAAK,aAAa,IAAI;AAErD,MAAI,CAAC,SAAS,EAAE,cAAc,IAAI,KAAK,cAAc,IAAI,GAAI,QAAO;AAEpE,QAAM,YAA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KAAK,IAAI,IAAI;AACvC,cAAU,cAAc,KAAK,MAAM,QAAQ,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC;AAClE,aAAS,GAAG;AAAA,EACd;AACA,WAAS,SAAS,cAAc,SAAS,KAAK,MAAM,MAAM,IAAI,IAAI;AAKlE,MAAI,6BAA6B;AACjC,MAAI,OAAO,WAAW,IAAI,GAAG;AAC3B,iCAA6B;AAC7B,aAAS,MAAM,OAAO,QAAQ,QAAQ,EAAE;AAAA,EAC1C;AAEA,SAAO,EAAE,MAAM,QAAQ,2BAAA;AACzB;AAqBO,SAAS,kBAAkB,MAAsB;AAKtD,MAAI,CAAC,sBAAsB,KAAK,IAAI,EAAG,QAAO;AAG9C,SAAO,KAAK,QAAQ,yBAAyB,kBAAkB;AACjE;AAWO,SAAS,kBACd,UACA,UACQ;AAER,QAAM,kBAAkB,SAAS,QAAQ,cAAc,EAAE;AAEzD,QAAM,qBAAqB,oBAAoB,KAAK,KAAK,IAAI,eAAe;AAC5E,SAAO,GAAG,kBAAkB,sCAAsC,mBAAmB,SAAS,KAAK,GAAG,CAAC,CAAC;AAC1G;;;;;;;;;;;;;;;;;;"}
@@ -63,13 +63,14 @@ export declare function last<T>(arr: ReadonlyArray<T>): T | undefined;
63
63
  * Accepts either a literal value or a function of the previous value.
64
64
  */
65
65
  export declare function functionalUpdate<TPrevious, TResult = TPrevious>(updater: Updater<TPrevious, TResult> | NonNullableUpdater<TPrevious, TResult>, previous: TPrevious): TResult;
66
+ export declare const nullReplaceEqualDeep: typeof replaceEqualDeep;
66
67
  /**
67
68
  * This function returns `prev` if `_next` is deeply equal.
68
69
  * If not, it will replace any deeply equal children of `b` with those of `a`.
69
70
  * This can be used for structural sharing between immutable JSON values for example.
70
71
  * Do not use this with signals
71
72
  */
72
- export declare function replaceEqualDeep<T>(prev: any, _next: T, _depth?: number): T;
73
+ export declare function replaceEqualDeep<T>(prev: any, _next: T, _makeObj?: () => {}, _depth?: number): T;
73
74
  export declare function isPlainObject(o: any): boolean;
74
75
  /**
75
76
  * Check if a value is a "plain" array (no extra enumerable keys).
@@ -14,7 +14,7 @@ export { encode, decode } from './qss.js';
14
14
  export { rootRouteId } from './root.js';
15
15
  export type { RootRouteId } from './root.js';
16
16
  export { BaseRoute, BaseRouteApi, BaseRootRoute } from './route.js';
17
- export type { AnyPathParams, SearchSchemaInput, AnyContext, RouteContext, PreloadableObj, RoutePathOptions, StaticDataRouteOption, RoutePathOptionsIntersection, SearchFilter, SearchMiddlewareContext, SearchMiddleware, ResolveId, InferFullSearchSchema, InferFullSearchSchemaInput, InferAllParams, InferAllContext, MetaDescriptor, RouteLinkEntry, SearchValidator, AnySearchValidator, DefaultSearchValidator, ErrorRouteProps, ErrorComponentProps, NotFoundRouteProps, ResolveParams, ParseParamsFn, StringifyParamsFn, ParamsOptions, UpdatableStaticRouteOption, ContextReturnType, ContextAsyncReturnType, ResolveRouteContext, ResolveLoaderData, RoutePrefix, TrimPath, TrimPathLeft, TrimPathRight, ResolveSearchSchemaFnInput, ResolveSearchSchemaInput, ResolveSearchSchemaFn, ResolveSearchSchema, ResolveFullSearchSchema, ResolveFullSearchSchemaInput, ResolveAllContext, BeforeLoadContextParameter, RouteContextParameter, ResolveAllParamsFromParent, AnyRoute, Route, RouteTypes, FullSearchSchemaOption, RemountDepsOptions, MakeRemountDepsOptionsUnion, ResolveFullPath, AnyRouteWithContext, RouteOptions, FileBaseRouteOptions, BaseRouteOptions, UpdatableRouteOptions, RouteLoaderFn, LoaderFnContext, RouteContextFn, ContextOptions, RouteContextOptions, BeforeLoadContextOptions, RootRouteOptions, RootRouteOptionsExtensions, UpdatableRouteOptionsExtensions, RouteConstraints, RouteTypesById, RouteMask, RouteExtensions, RouteLazyFn, RouteAddChildrenFn, RouteAddFileChildrenFn, RouteAddFileTypesFn, ResolveOptionalParams, ResolveRequiredParams, RootRoute, FilebaseRouteOptionsInterface, } from './route.js';
17
+ export type { AnyPathParams, SearchSchemaInput, AnyContext, RouteContext, PreloadableObj, RoutePathOptions, StaticDataRouteOption, RoutePathOptionsIntersection, SearchFilter, SearchMiddlewareContext, SearchMiddleware, ResolveId, InferFullSearchSchema, InferFullSearchSchemaInput, InferAllParams, InferAllContext, MetaDescriptor, RouteLinkEntry, SearchValidator, AnySearchValidator, DefaultSearchValidator, ErrorRouteProps, ErrorComponentProps, NotFoundRouteProps, ResolveParams, ParseParamsFn, StringifyParamsFn, ParamsOptions, UpdatableStaticRouteOption, ContextReturnType, ContextAsyncReturnType, ResolveRouteContext, ResolveLoaderData, RoutePrefix, TrimPath, TrimPathLeft, TrimPathRight, ResolveSearchSchemaFnInput, ResolveSearchSchemaInput, ResolveSearchSchemaFn, ResolveSearchSchema, ResolveFullSearchSchema, ResolveFullSearchSchemaInput, ResolveAllContext, BeforeLoadContextParameter, RouteContextParameter, ResolveAllParamsFromParent, AnyRoute, Route, RouteTypes, FullSearchSchemaOption, RemountDepsOptions, MakeRemountDepsOptionsUnion, ResolveFullPath, AnyRouteWithContext, RouteOptions, FileBaseRouteOptions, BaseRouteOptions, UpdatableRouteOptions, LoaderStaleReloadMode, RouteLoaderFn, RouteLoaderEntry, LoaderFnContext, RouteContextFn, ContextOptions, RouteContextOptions, BeforeLoadContextOptions, RootRouteOptions, RootRouteOptionsExtensions, UpdatableRouteOptionsExtensions, RouteConstraints, RouteTypesById, RouteMask, RouteExtensions, RouteLazyFn, RouteAddChildrenFn, RouteAddFileChildrenFn, RouteAddFileTypesFn, ResolveOptionalParams, ResolveRequiredParams, RootRoute, FilebaseRouteOptionsInterface, } from './route.js';
18
18
  export { defaultSerializeError, getLocationChangeInfo, RouterCore, lazyFn, SearchParamError, PathParamError, getInitialRouterState, getMatchedRoutes, trailingSlashOptions, } from './router.js';
19
19
  export type { ViewTransitionOptions, TrailingSlashOption, Register, AnyRouter, AnyRouterWithContext, RegisteredRouter, RouterState, BuildNextOptions, RouterListener, RouterEvent, ListenerFn, RouterEvents, MatchRoutesOpts, RouterOptionsExtensions, DefaultRemountDepsFn, PreloadRouteFn, MatchRouteFn, RouterContextOptions, RouterOptions, RouterConstructorOptions, UpdateFn, ParseLocationFn, InvalidateFn, ControllablePromise, InjectedHtmlEntry, EmitFn, LoadFn, GetMatchFn, SubscribeFn, UpdateMatchFn, CommitLocationFn, GetMatchRoutesFn, MatchRoutesFn, StartTransitionFn, LoadRouteChunkFn, ClearCacheFn, CreateRouterFn, SSROption, } from './router.js';
20
20
  export * from './config.js';
@@ -398,10 +398,12 @@ const runLoader = async (inner, matchPromises, matchId, index, route) => {
398
398
  if (!(isServer ?? inner.router.isServer) || match.ssr === true) {
399
399
  loadRouteChunk(route);
400
400
  }
401
- const loaderResult = route.options.loader?.(
401
+ const routeLoader = route.options.loader;
402
+ const loader = typeof routeLoader === "function" ? routeLoader : routeLoader?.handler;
403
+ const loaderResult = loader?.(
402
404
  getLoaderContext(inner, matchPromises, matchId, index, route)
403
405
  );
404
- const loaderResultIsPromise = route.options.loader && isPromise(loaderResult);
406
+ const loaderResultIsPromise = !!loader && isPromise(loaderResult);
405
407
  const willLoadSomething = !!(loaderResultIsPromise || route._lazyPromise || route._componentsPromise || route.options.head || route.options.scripts || route.options.headers || match._nonReactive.minPendingPromise);
406
408
  if (willLoadSomething) {
407
409
  inner.updateMatch(matchId, (prev) => ({
@@ -409,7 +411,7 @@ const runLoader = async (inner, matchPromises, matchId, index, route) => {
409
411
  isFetching: "loader"
410
412
  }));
411
413
  }
412
- if (route.options.loader) {
414
+ if (loader) {
413
415
  const loaderData = loaderResultIsPromise ? await loaderResult : loaderResult;
414
416
  handleRedirectAndNotFound(
415
417
  inner,
@@ -498,7 +500,7 @@ const loadRouteMatch = async (inner, matchPromises, index) => {
498
500
  const staleMatchShouldReload = age > staleAge && (!!inner.forceStaleReload || match2.cause === "enter" || previousRouteMatchId !== void 0 && previousRouteMatchId !== match2.id);
499
501
  loaderShouldRunAsync = status === "success" && (invalid || (shouldReload ?? staleMatchShouldReload));
500
502
  if (preload && route2.options.preload === false) ;
501
- else if (loaderShouldRunAsync && !inner.sync) {
503
+ else if (loaderShouldRunAsync && !inner.sync && shouldReloadInBackground) {
502
504
  loaderIsRunningAsync = true;
503
505
  (async () => {
504
506
  try {
@@ -513,7 +515,7 @@ const loadRouteMatch = async (inner, matchPromises, index) => {
513
515
  }
514
516
  }
515
517
  })();
516
- } else if (status !== "success" || loaderShouldRunAsync && inner.sync) {
518
+ } else if (status !== "success" || loaderShouldRunAsync) {
517
519
  await runLoader(inner, matchPromises, matchId, index, route2);
518
520
  } else {
519
521
  syncMatchContext(inner, matchId, index);
@@ -523,6 +525,8 @@ const loadRouteMatch = async (inner, matchPromises, index) => {
523
525
  let loaderShouldRunAsync = false;
524
526
  let loaderIsRunningAsync = false;
525
527
  const route = inner.router.looseRoutesById[routeId];
528
+ const routeLoader = route.options.loader;
529
+ const shouldReloadInBackground = ((typeof routeLoader === "function" ? void 0 : routeLoader?.staleReloadMode) ?? inner.router.options.defaultStaleReloadMode) !== "blocking";
526
530
  if (shouldSkipLoader(inner, matchId)) {
527
531
  const match2 = inner.router.getMatch(matchId);
528
532
  if (!match2) {
@@ -537,7 +541,7 @@ const loadRouteMatch = async (inner, matchPromises, index) => {
537
541
  const previousRouteMatchId = inner.router.state.matches[index]?.routeId === routeId ? inner.router.state.matches[index].id : inner.router.state.matches.find((d) => d.routeId === routeId)?.id;
538
542
  const preload = resolvePreload(inner, matchId);
539
543
  if (prevMatch._nonReactive.loaderPromise) {
540
- if (prevMatch.status === "success" && !inner.sync && !prevMatch.preload) {
544
+ if (prevMatch.status === "success" && !inner.sync && !prevMatch.preload && shouldReloadInBackground) {
541
545
  return prevMatch;
542
546
  }
543
547
  await prevMatch._nonReactive.loaderPromise;
@@ -1 +1 @@
1
- {"version":3,"file":"load-matches.js","sources":["../../src/load-matches.ts"],"sourcesContent":["import invariant from 'tiny-invariant'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { batch } from './utils/batch'\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 resolvePreload = (inner: InnerLoadContext, matchId: string): boolean => {\n return !!(\n inner.preload && !inner.router.state.matches.some((d) => d.id === matchId)\n )\n}\n\n/**\n * Builds the accumulated context from router options and all matches up to (and optionally including) the given index.\n * Merges __routeContext and __beforeLoadContext from each match.\n */\nconst buildMatchContext = (\n inner: InnerLoadContext,\n index: number,\n includeCurrentMatch: boolean = true,\n): Record<string, unknown> => {\n const context: Record<string, unknown> = {\n ...(inner.router.options.context ?? {}),\n }\n const end = includeCurrentMatch ? index : index - 1\n for (let i = 0; i <= end; i++) {\n const innerMatch = inner.matches[i]\n if (!innerMatch) continue\n const m = inner.router.getMatch(innerMatch.id)\n if (!m) continue\n Object.assign(context, m.__routeContext, m.__beforeLoadContext)\n }\n return context\n}\n\nconst getNotFoundBoundaryIndex = (\n inner: InnerLoadContext,\n err: NotFoundError,\n): number | undefined => {\n if (!inner.matches.length) {\n return undefined\n }\n\n const requestedRouteId = err.routeId\n const matchedRootIndex = inner.matches.findIndex(\n (m) => m.routeId === inner.router.routeTree.id,\n )\n const rootIndex = matchedRootIndex >= 0 ? matchedRootIndex : 0\n\n let startIndex = requestedRouteId\n ? inner.matches.findIndex((match) => match.routeId === requestedRouteId)\n : (inner.firstBadMatchIndex ?? inner.matches.length - 1)\n\n if (startIndex < 0) {\n startIndex = rootIndex\n }\n\n for (let i = startIndex; i >= 0; i--) {\n const match = inner.matches[i]!\n const route = inner.router.looseRoutesById[match.routeId]!\n if (route.options.notFoundComponent) {\n return i\n }\n }\n\n // If no boundary component is found, preserve explicit routeId targeting behavior,\n // otherwise default to root for untargeted notFounds.\n return requestedRouteId ? startIndex : rootIndex\n}\n\nconst handleRedirectAndNotFound = (\n inner: InnerLoadContext,\n match: AnyRouteMatch | undefined,\n err: unknown,\n): void => {\n if (!isRedirect(err) && !isNotFound(err)) return\n\n if (isRedirect(err) && err.redirectHandled && !err.options.reloadDocument) {\n throw err\n }\n\n // in case of a redirecting match during preload, the match does not exist\n if (match) {\n match._nonReactive.beforeLoadPromise?.resolve()\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.beforeLoadPromise = undefined\n match._nonReactive.loaderPromise = undefined\n\n match._nonReactive.error = err\n\n inner.updateMatch(match.id, (prev) => ({\n ...prev,\n status: isRedirect(err)\n ? 'redirected'\n : prev.status === 'pending'\n ? 'success'\n : prev.status,\n context: buildMatchContext(inner, match.index),\n isFetching: false,\n error: err,\n }))\n\n if (isNotFound(err) && !err.routeId) {\n // Stamp the throwing match's routeId so that the finalization step in\n // loadMatches knows where the notFound originated. The actual boundary\n // resolution (walking up to the nearest notFoundComponent) is deferred to\n // the finalization step, where firstBadMatchIndex is stable and\n // headMaxIndex can be capped correctly.\n err.routeId = match.routeId\n }\n\n match._nonReactive.loadPromise?.resolve()\n }\n\n if (isRedirect(err)) {\n inner.rendered = true\n err.options._fromLocation = inner.location\n err.redirectHandled = true\n err = inner.router.resolveRedirect(err)\n }\n\n throw err\n}\n\nconst shouldSkipLoader = (\n inner: InnerLoadContext,\n matchId: string,\n): boolean => {\n const match = inner.router.getMatch(matchId)\n if (!match) {\n return true\n }\n // upon hydration, we skip the loader if the match has been dehydrated on the server\n if (!(isServer ?? inner.router.isServer) && match._nonReactive.dehydrated) {\n return true\n }\n\n if ((isServer ?? inner.router.isServer) && match.ssr === false) {\n return true\n }\n\n return false\n}\n\nconst syncMatchContext = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n): void => {\n const nextContext = buildMatchContext(inner, index)\n\n inner.updateMatch(matchId, (prev) => {\n return {\n ...prev,\n context: nextContext,\n }\n })\n}\n\nconst handleSerialError = (\n inner: InnerLoadContext,\n index: number,\n err: any,\n routerCode: string,\n): void => {\n const { id: matchId, routeId } = inner.matches[index]!\n const route = inner.router.looseRoutesById[routeId]!\n\n // Much like suspense, we use a promise here to know if\n // we've been outdated by a new loadMatches call and\n // should abort the current async operation\n if (err instanceof Promise) {\n throw err\n }\n\n err.routerCode = routerCode\n inner.firstBadMatchIndex ??= index\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), err)\n\n try {\n route.options.onError?.(err)\n } catch (errorHandlerErr) {\n err = errorHandlerErr\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), err)\n }\n\n inner.updateMatch(matchId, (prev) => {\n prev._nonReactive.beforeLoadPromise?.resolve()\n prev._nonReactive.beforeLoadPromise = undefined\n prev._nonReactive.loadPromise?.resolve()\n\n return {\n ...prev,\n error: err,\n status: 'error',\n isFetching: false,\n updatedAt: Date.now(),\n abortController: new AbortController(),\n }\n })\n\n if (!inner.preload && !isRedirect(err) && !isNotFound(err)) {\n inner.serialError ??= err\n }\n}\n\nconst isBeforeLoadSsr = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): void | Promise<void> => {\n const existingMatch = inner.router.getMatch(matchId)!\n const parentMatchId = inner.matches[index - 1]?.id\n const parentMatch = parentMatchId\n ? inner.router.getMatch(parentMatchId)!\n : undefined\n\n // in SPA mode, only SSR the root route\n if (inner.router.isShell()) {\n existingMatch.ssr = route.id === rootRouteId\n return\n }\n\n if (parentMatch?.ssr === false) {\n existingMatch.ssr = false\n return\n }\n\n const parentOverride = (tempSsr: SSROption) => {\n if (tempSsr === true && parentMatch?.ssr === 'data-only') {\n return 'data-only'\n }\n return tempSsr\n }\n\n const defaultSsr = inner.router.options.defaultSsr ?? true\n\n if (route.options.ssr === undefined) {\n existingMatch.ssr = parentOverride(defaultSsr)\n return\n }\n\n if (typeof route.options.ssr !== 'function') {\n existingMatch.ssr = parentOverride(route.options.ssr)\n return\n }\n const { search, params } = existingMatch\n\n const ssrFnContext: SsrContextOptions<any, any, any> = {\n search: makeMaybe(search, existingMatch.searchError),\n params: makeMaybe(params, existingMatch.paramsError),\n location: inner.location,\n matches: inner.matches.map((match) => ({\n index: match.index,\n pathname: match.pathname,\n fullPath: match.fullPath,\n staticData: match.staticData,\n id: match.id,\n routeId: match.routeId,\n search: makeMaybe(match.search, match.searchError),\n params: makeMaybe(match.params, match.paramsError),\n ssr: match.ssr,\n })),\n }\n\n const tempSsr = route.options.ssr(ssrFnContext)\n if (isPromise(tempSsr)) {\n return tempSsr.then((ssr) => {\n existingMatch.ssr = parentOverride(ssr ?? defaultSsr)\n })\n }\n\n existingMatch.ssr = parentOverride(tempSsr ?? defaultSsr)\n return\n}\n\nconst setupPendingTimeout = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n match: AnyRouteMatch,\n): void => {\n if (match._nonReactive.pendingTimeout !== undefined) return\n\n const pendingMs =\n route.options.pendingMs ?? inner.router.options.defaultPendingMs\n const shouldPending = !!(\n inner.onReady &&\n !(isServer ?? inner.router.isServer) &&\n !resolvePreload(inner, matchId) &&\n (route.options.loader ||\n route.options.beforeLoad ||\n routeNeedsPreload(route)) &&\n typeof pendingMs === 'number' &&\n pendingMs !== Infinity &&\n (route.options.pendingComponent ??\n (inner.router.options as any)?.defaultPendingComponent)\n )\n\n if (shouldPending) {\n const pendingTimeout = setTimeout(() => {\n // Update the match and prematurely resolve the loadMatches promise so that\n // the pending component can start rendering\n triggerOnReady(inner)\n }, pendingMs)\n match._nonReactive.pendingTimeout = pendingTimeout\n }\n}\n\nconst preBeforeLoadSetup = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n): void | Promise<void> => {\n const existingMatch = inner.router.getMatch(matchId)!\n\n // If we are in the middle of a load, either of these will be present\n // (not to be confused with `loadPromise`, which is always defined)\n if (\n !existingMatch._nonReactive.beforeLoadPromise &&\n !existingMatch._nonReactive.loaderPromise\n )\n return\n\n setupPendingTimeout(inner, matchId, route, existingMatch)\n\n const then = () => {\n const match = inner.router.getMatch(matchId)!\n if (\n match.preload &&\n (match.status === 'redirected' || match.status === 'notFound')\n ) {\n handleRedirectAndNotFound(inner, match, match.error)\n }\n }\n\n // Wait for the previous beforeLoad to resolve before we continue\n return existingMatch._nonReactive.beforeLoadPromise\n ? existingMatch._nonReactive.beforeLoadPromise.then(then)\n : then()\n}\n\nconst executeBeforeLoad = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): void | Promise<void> => {\n const match = inner.router.getMatch(matchId)!\n\n // explicitly capture the previous loadPromise\n const prevLoadPromise = match._nonReactive.loadPromise\n match._nonReactive.loadPromise = createControlledPromise<void>(() => {\n prevLoadPromise?.resolve()\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 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 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 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 loaderResult = route.options.loader?.(\n getLoaderContext(inner, matchPromises, matchId, index, route),\n )\n const loaderResultIsPromise =\n route.options.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 (route.options.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 (loaderShouldRunAsync && !inner.sync) {\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 } catch (err) {\n if (isRedirect(err)) {\n await inner.router.navigate(err.options)\n }\n }\n })()\n } else if (status !== 'success' || (loaderShouldRunAsync && inner.sync)) {\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\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 previousRouteMatchId =\n inner.router.state.matches[index]?.routeId === routeId\n ? inner.router.state.matches[index]!.id\n : inner.router.state.matches.find((d) => d.routeId === routeId)?.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 (prevMatch.status === 'success' && !inner.sync && !prevMatch.preload) {\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.state.matches.some((d) => d.id === 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 }\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 inner.router.state.matches.some((d) => d._forcePending)\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) {\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 = inner.serialError\n ? (inner.firstBadMatchIndex ?? 0)\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 invariant(\n renderedBoundaryIndex !== undefined,\n 'Could not find match for notFound boundary',\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"],"names":["tempSsr","beforeLoadContext","match","route"],"mappings":";;;;;;;AAwCA,MAAM,iBAAiB,CAAC,UAAkD;AACxE,MAAI,CAAC,MAAM,UAAU;AACnB,UAAM,WAAW;AACjB,WAAO,MAAM,UAAA;AAAA,EACf;AACF;AAEA,MAAM,iBAAiB,CAAC,OAAyB,YAA6B;AAC5E,SAAO,CAAC,EACN,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YAAM,eAAe,MAAM,OAAA,EAAS,KAAK,CAAC,cAAc;AAEtD,cAAM,EAAE,IAAI,KAAK,GAAG,QAAA,IAAY,UAAU;AAC1C,eAAO,OAAO,MAAM,SAAS,OAAO;AACpC,cAAM,cAAc;AACpB,cAAM,eAAe;AAAA,MACvB,CAAC;AAAA,IACH,OAAO;AACL,YAAM,cAAc;AAAA,IACtB;AAAA,EACF;AAEA,QAAM,eAAe,MACnB,MAAM,oBACF,SACA,yBAAyB,kBACtB,MAAM;AACL,QAAI,MAAM,uBAAuB,QAAW;AAC1C,YAAM,oBAAoB;AAAA,QACxB;AAAA,QACA;AAAA,MAAA;AAGF,UAAI,mBAAmB;AACrB,cAAM,qBAAqB,kBAAkB,KAAK,MAAM;AACtD,gBAAM,oBAAoB;AAC1B,gBAAM,qBAAqB;AAAA,QAC7B,CAAC;AAAA,MACH,OAAO;AACL,cAAM,oBAAoB;AAAA,MAC5B;AAAA,IACF;AAEA,WAAO,MAAM;AAAA,EACf,OACA,uBAAuB,OAAO,oBAAoB;AAE1D,SAAO,MAAM,eACT,MAAM,aAAa,KAAK,YAAY,IACpC,aAAA;AACN;AAEA,SAAS,UACP,OACA,OAC2E;AAC3E,MAAI,OAAO;AACT,WAAO,EAAE,QAAQ,SAAkB,MAAA;AAAA,EACrC;AACA,SAAO,EAAE,QAAQ,WAAoB,MAAA;AACvC;AAEO,SAAS,kBAAkB,OAAiB;AACjD,aAAW,iBAAiB,gBAAgB;AAC1C,QAAK,MAAM,QAAQ,aAAa,GAAW,SAAS;AAClD,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAEO,MAAM,iBAA4C;AAAA,EACvD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;"}
1
+ {"version":3,"file":"load-matches.js","sources":["../../src/load-matches.ts"],"sourcesContent":["import invariant from 'tiny-invariant'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { batch } from './utils/batch'\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 resolvePreload = (inner: InnerLoadContext, matchId: string): boolean => {\n return !!(\n inner.preload && !inner.router.state.matches.some((d) => d.id === matchId)\n )\n}\n\n/**\n * Builds the accumulated context from router options and all matches up to (and optionally including) the given index.\n * Merges __routeContext and __beforeLoadContext from each match.\n */\nconst buildMatchContext = (\n inner: InnerLoadContext,\n index: number,\n includeCurrentMatch: boolean = true,\n): Record<string, unknown> => {\n const context: Record<string, unknown> = {\n ...(inner.router.options.context ?? {}),\n }\n const end = includeCurrentMatch ? index : index - 1\n for (let i = 0; i <= end; i++) {\n const innerMatch = inner.matches[i]\n if (!innerMatch) continue\n const m = inner.router.getMatch(innerMatch.id)\n if (!m) continue\n Object.assign(context, m.__routeContext, m.__beforeLoadContext)\n }\n return context\n}\n\nconst getNotFoundBoundaryIndex = (\n inner: InnerLoadContext,\n err: NotFoundError,\n): number | undefined => {\n if (!inner.matches.length) {\n return undefined\n }\n\n const requestedRouteId = err.routeId\n const matchedRootIndex = inner.matches.findIndex(\n (m) => m.routeId === inner.router.routeTree.id,\n )\n const rootIndex = matchedRootIndex >= 0 ? matchedRootIndex : 0\n\n let startIndex = requestedRouteId\n ? inner.matches.findIndex((match) => match.routeId === requestedRouteId)\n : (inner.firstBadMatchIndex ?? inner.matches.length - 1)\n\n if (startIndex < 0) {\n startIndex = rootIndex\n }\n\n for (let i = startIndex; i >= 0; i--) {\n const match = inner.matches[i]!\n const route = inner.router.looseRoutesById[match.routeId]!\n if (route.options.notFoundComponent) {\n return i\n }\n }\n\n // If no boundary component is found, preserve explicit routeId targeting behavior,\n // otherwise default to root for untargeted notFounds.\n return requestedRouteId ? startIndex : rootIndex\n}\n\nconst handleRedirectAndNotFound = (\n inner: InnerLoadContext,\n match: AnyRouteMatch | undefined,\n err: unknown,\n): void => {\n if (!isRedirect(err) && !isNotFound(err)) return\n\n if (isRedirect(err) && err.redirectHandled && !err.options.reloadDocument) {\n throw err\n }\n\n // in case of a redirecting match during preload, the match does not exist\n if (match) {\n match._nonReactive.beforeLoadPromise?.resolve()\n match._nonReactive.loaderPromise?.resolve()\n match._nonReactive.beforeLoadPromise = undefined\n match._nonReactive.loaderPromise = undefined\n\n match._nonReactive.error = err\n\n inner.updateMatch(match.id, (prev) => ({\n ...prev,\n status: isRedirect(err)\n ? 'redirected'\n : prev.status === 'pending'\n ? 'success'\n : prev.status,\n context: buildMatchContext(inner, match.index),\n isFetching: false,\n error: err,\n }))\n\n if (isNotFound(err) && !err.routeId) {\n // Stamp the throwing match's routeId so that the finalization step in\n // loadMatches knows where the notFound originated. The actual boundary\n // resolution (walking up to the nearest notFoundComponent) is deferred to\n // the finalization step, where firstBadMatchIndex is stable and\n // headMaxIndex can be capped correctly.\n err.routeId = match.routeId\n }\n\n match._nonReactive.loadPromise?.resolve()\n }\n\n if (isRedirect(err)) {\n inner.rendered = true\n err.options._fromLocation = inner.location\n err.redirectHandled = true\n err = inner.router.resolveRedirect(err)\n }\n\n throw err\n}\n\nconst shouldSkipLoader = (\n inner: InnerLoadContext,\n matchId: string,\n): boolean => {\n const match = inner.router.getMatch(matchId)\n if (!match) {\n return true\n }\n // upon hydration, we skip the loader if the match has been dehydrated on the server\n if (!(isServer ?? inner.router.isServer) && match._nonReactive.dehydrated) {\n return true\n }\n\n if ((isServer ?? inner.router.isServer) && match.ssr === false) {\n return true\n }\n\n return false\n}\n\nconst syncMatchContext = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n): void => {\n const nextContext = buildMatchContext(inner, index)\n\n inner.updateMatch(matchId, (prev) => {\n return {\n ...prev,\n context: nextContext,\n }\n })\n}\n\nconst handleSerialError = (\n inner: InnerLoadContext,\n index: number,\n err: any,\n routerCode: string,\n): void => {\n const { id: matchId, routeId } = inner.matches[index]!\n const route = inner.router.looseRoutesById[routeId]!\n\n // Much like suspense, we use a promise here to know if\n // we've been outdated by a new loadMatches call and\n // should abort the current async operation\n if (err instanceof Promise) {\n throw err\n }\n\n err.routerCode = routerCode\n inner.firstBadMatchIndex ??= index\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), err)\n\n try {\n route.options.onError?.(err)\n } catch (errorHandlerErr) {\n err = errorHandlerErr\n handleRedirectAndNotFound(inner, inner.router.getMatch(matchId), err)\n }\n\n inner.updateMatch(matchId, (prev) => {\n prev._nonReactive.beforeLoadPromise?.resolve()\n prev._nonReactive.beforeLoadPromise = undefined\n prev._nonReactive.loadPromise?.resolve()\n\n return {\n ...prev,\n error: err,\n status: 'error',\n isFetching: false,\n updatedAt: Date.now(),\n abortController: new AbortController(),\n }\n })\n\n if (!inner.preload && !isRedirect(err) && !isNotFound(err)) {\n inner.serialError ??= err\n }\n}\n\nconst isBeforeLoadSsr = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): void | Promise<void> => {\n const existingMatch = inner.router.getMatch(matchId)!\n const parentMatchId = inner.matches[index - 1]?.id\n const parentMatch = parentMatchId\n ? inner.router.getMatch(parentMatchId)!\n : undefined\n\n // in SPA mode, only SSR the root route\n if (inner.router.isShell()) {\n existingMatch.ssr = route.id === rootRouteId\n return\n }\n\n if (parentMatch?.ssr === false) {\n existingMatch.ssr = false\n return\n }\n\n const parentOverride = (tempSsr: SSROption) => {\n if (tempSsr === true && parentMatch?.ssr === 'data-only') {\n return 'data-only'\n }\n return tempSsr\n }\n\n const defaultSsr = inner.router.options.defaultSsr ?? true\n\n if (route.options.ssr === undefined) {\n existingMatch.ssr = parentOverride(defaultSsr)\n return\n }\n\n if (typeof route.options.ssr !== 'function') {\n existingMatch.ssr = parentOverride(route.options.ssr)\n return\n }\n const { search, params } = existingMatch\n\n const ssrFnContext: SsrContextOptions<any, any, any> = {\n search: makeMaybe(search, existingMatch.searchError),\n params: makeMaybe(params, existingMatch.paramsError),\n location: inner.location,\n matches: inner.matches.map((match) => ({\n index: match.index,\n pathname: match.pathname,\n fullPath: match.fullPath,\n staticData: match.staticData,\n id: match.id,\n routeId: match.routeId,\n search: makeMaybe(match.search, match.searchError),\n params: makeMaybe(match.params, match.paramsError),\n ssr: match.ssr,\n })),\n }\n\n const tempSsr = route.options.ssr(ssrFnContext)\n if (isPromise(tempSsr)) {\n return tempSsr.then((ssr) => {\n existingMatch.ssr = parentOverride(ssr ?? defaultSsr)\n })\n }\n\n existingMatch.ssr = parentOverride(tempSsr ?? defaultSsr)\n return\n}\n\nconst setupPendingTimeout = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n match: AnyRouteMatch,\n): void => {\n if (match._nonReactive.pendingTimeout !== undefined) return\n\n const pendingMs =\n route.options.pendingMs ?? inner.router.options.defaultPendingMs\n const shouldPending = !!(\n inner.onReady &&\n !(isServer ?? inner.router.isServer) &&\n !resolvePreload(inner, matchId) &&\n (route.options.loader ||\n route.options.beforeLoad ||\n routeNeedsPreload(route)) &&\n typeof pendingMs === 'number' &&\n pendingMs !== Infinity &&\n (route.options.pendingComponent ??\n (inner.router.options as any)?.defaultPendingComponent)\n )\n\n if (shouldPending) {\n const pendingTimeout = setTimeout(() => {\n // Update the match and prematurely resolve the loadMatches promise so that\n // the pending component can start rendering\n triggerOnReady(inner)\n }, pendingMs)\n match._nonReactive.pendingTimeout = pendingTimeout\n }\n}\n\nconst preBeforeLoadSetup = (\n inner: InnerLoadContext,\n matchId: string,\n route: AnyRoute,\n): void | Promise<void> => {\n const existingMatch = inner.router.getMatch(matchId)!\n\n // If we are in the middle of a load, either of these will be present\n // (not to be confused with `loadPromise`, which is always defined)\n if (\n !existingMatch._nonReactive.beforeLoadPromise &&\n !existingMatch._nonReactive.loaderPromise\n )\n return\n\n setupPendingTimeout(inner, matchId, route, existingMatch)\n\n const then = () => {\n const match = inner.router.getMatch(matchId)!\n if (\n match.preload &&\n (match.status === 'redirected' || match.status === 'notFound')\n ) {\n handleRedirectAndNotFound(inner, match, match.error)\n }\n }\n\n // Wait for the previous beforeLoad to resolve before we continue\n return existingMatch._nonReactive.beforeLoadPromise\n ? existingMatch._nonReactive.beforeLoadPromise.then(then)\n : then()\n}\n\nconst executeBeforeLoad = (\n inner: InnerLoadContext,\n matchId: string,\n index: number,\n route: AnyRoute,\n): void | Promise<void> => {\n const match = inner.router.getMatch(matchId)!\n\n // explicitly capture the previous loadPromise\n const prevLoadPromise = match._nonReactive.loadPromise\n match._nonReactive.loadPromise = createControlledPromise<void>(() => {\n prevLoadPromise?.resolve()\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 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 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 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 } 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 previousRouteMatchId =\n inner.router.state.matches[index]?.routeId === routeId\n ? inner.router.state.matches[index]!.id\n : inner.router.state.matches.find((d) => d.routeId === routeId)?.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.state.matches.some((d) => d.id === 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 }\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 inner.router.state.matches.some((d) => d._forcePending)\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) {\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 = inner.serialError\n ? (inner.firstBadMatchIndex ?? 0)\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 invariant(\n renderedBoundaryIndex !== undefined,\n 'Could not find match for notFound boundary',\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"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;AACvC;AAEO,SAAS,kBAAkB,OAAiB;AACjD,aAAW,iBAAiB,gBAAgB;AAC1C,QAAK,MAAM,QAAQ,aAAa,GAAW,SAAS;AAClD,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAEO,MAAM,iBAA4C;AAAA,EACvD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;"}
@@ -470,7 +470,7 @@ function findMatch(path, segmentTree, fuzzy = false) {
470
470
  function extractParams(path, parts, leaf) {
471
471
  const list = buildBranch(leaf.node);
472
472
  let nodeParts = null;
473
- const rawParams = {};
473
+ const rawParams = /* @__PURE__ */ Object.create(null);
474
474
  let partIndex = leaf.extract?.part ?? 0;
475
475
  let nodeIndex = leaf.extract?.node ?? 0;
476
476
  let pathIndex = leaf.extract?.path ?? 0;
@@ -796,7 +796,7 @@ function getNodeMatch(path, parts, segmentTree, fuzzy) {
796
796
  sliceIndex += parts[i].length;
797
797
  }
798
798
  const splat = sliceIndex === path.length ? "/" : path.slice(sliceIndex);
799
- bestFuzzy.rawParams ??= {};
799
+ bestFuzzy.rawParams ??= /* @__PURE__ */ Object.create(null);
800
800
  bestFuzzy.rawParams["**"] = decodeURIComponent(splat);
801
801
  return bestFuzzy;
802
802
  }
@@ -808,7 +808,11 @@ function validateMatchParams(path, parts, frame) {
808
808
  frame.rawParams = rawParams;
809
809
  frame.extract = state;
810
810
  const parsed = frame.node.parse(rawParams);
811
- frame.parsedParams = Object.assign({}, frame.parsedParams, parsed);
811
+ frame.parsedParams = Object.assign(
812
+ /* @__PURE__ */ Object.create(null),
813
+ frame.parsedParams,
814
+ parsed
815
+ );
812
816
  return true;
813
817
  } catch {
814
818
  return null;