@tanstack/react-router 1.22.4 → 1.22.6

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 (161) hide show
  1. package/dist/cjs/CatchBoundary.cjs +1 -2
  2. package/dist/cjs/CatchBoundary.cjs.map +1 -1
  3. package/dist/cjs/Matches.cjs +15 -15
  4. package/dist/cjs/Matches.cjs.map +1 -1
  5. package/dist/cjs/Matches.d.cts +15 -15
  6. package/dist/cjs/RouterProvider.cjs +16 -15
  7. package/dist/cjs/RouterProvider.cjs.map +1 -1
  8. package/dist/cjs/RouterProvider.d.cts +6 -6
  9. package/dist/cjs/awaited.cjs +1 -1
  10. package/dist/cjs/awaited.cjs.map +1 -1
  11. package/dist/cjs/awaited.d.cts +1 -1
  12. package/dist/cjs/defer.cjs.map +1 -1
  13. package/dist/cjs/fileRoute.cjs +1 -1
  14. package/dist/cjs/fileRoute.cjs.map +1 -1
  15. package/dist/cjs/fileRoute.d.cts +17 -17
  16. package/dist/cjs/lazyRouteComponent.cjs.map +1 -1
  17. package/dist/cjs/lazyRouteComponent.d.cts +1 -1
  18. package/dist/cjs/link.cjs +10 -11
  19. package/dist/cjs/link.cjs.map +1 -1
  20. package/dist/cjs/link.d.cts +16 -13
  21. package/dist/cjs/location.d.cts +2 -2
  22. package/dist/cjs/not-found.cjs.map +1 -1
  23. package/dist/cjs/not-found.d.cts +2 -2
  24. package/dist/cjs/path.cjs +2 -2
  25. package/dist/cjs/path.cjs.map +1 -1
  26. package/dist/cjs/path.d.cts +4 -4
  27. package/dist/cjs/qss.cjs +4 -3
  28. package/dist/cjs/qss.cjs.map +1 -1
  29. package/dist/cjs/redirects.cjs.map +1 -1
  30. package/dist/cjs/redirects.d.cts +5 -5
  31. package/dist/cjs/route.cjs.map +1 -1
  32. package/dist/cjs/route.d.cts +34 -36
  33. package/dist/cjs/routeInfo.d.cts +5 -5
  34. package/dist/cjs/router.cjs +63 -66
  35. package/dist/cjs/router.cjs.map +1 -1
  36. package/dist/cjs/router.d.cts +28 -28
  37. package/dist/cjs/routerContext.cjs +1 -1
  38. package/dist/cjs/routerContext.cjs.map +1 -1
  39. package/dist/cjs/routerContext.d.cts +1 -1
  40. package/dist/cjs/scroll-restoration.cjs +7 -9
  41. package/dist/cjs/scroll-restoration.cjs.map +1 -1
  42. package/dist/cjs/scroll-restoration.d.cts +1 -1
  43. package/dist/cjs/searchParams.cjs +10 -12
  44. package/dist/cjs/searchParams.cjs.map +1 -1
  45. package/dist/cjs/searchParams.d.cts +1 -1
  46. package/dist/cjs/useBlocker.cjs.map +1 -1
  47. package/dist/cjs/useBlocker.d.cts +2 -2
  48. package/dist/cjs/useNavigate.cjs +1 -1
  49. package/dist/cjs/useNavigate.cjs.map +1 -1
  50. package/dist/cjs/useNavigate.d.cts +4 -4
  51. package/dist/cjs/useParams.cjs +1 -1
  52. package/dist/cjs/useParams.cjs.map +1 -1
  53. package/dist/cjs/useParams.d.cts +5 -5
  54. package/dist/cjs/useRouteContext.cjs +1 -1
  55. package/dist/cjs/useRouteContext.cjs.map +1 -1
  56. package/dist/cjs/useRouteContext.d.cts +4 -4
  57. package/dist/cjs/useRouter.cjs.map +1 -1
  58. package/dist/cjs/useRouter.d.cts +2 -2
  59. package/dist/cjs/useRouterState.cjs.map +1 -1
  60. package/dist/cjs/useRouterState.d.cts +2 -2
  61. package/dist/cjs/useSearch.cjs +1 -1
  62. package/dist/cjs/useSearch.cjs.map +1 -1
  63. package/dist/cjs/useSearch.d.cts +4 -4
  64. package/dist/cjs/utils.cjs +2 -2
  65. package/dist/cjs/utils.cjs.map +1 -1
  66. package/dist/cjs/utils.d.cts +13 -11
  67. package/dist/esm/CatchBoundary.js +1 -2
  68. package/dist/esm/CatchBoundary.js.map +1 -1
  69. package/dist/esm/Matches.d.ts +15 -15
  70. package/dist/esm/Matches.js +15 -15
  71. package/dist/esm/Matches.js.map +1 -1
  72. package/dist/esm/RouterProvider.d.ts +6 -6
  73. package/dist/esm/RouterProvider.js +16 -15
  74. package/dist/esm/RouterProvider.js.map +1 -1
  75. package/dist/esm/awaited.d.ts +1 -1
  76. package/dist/esm/awaited.js +1 -1
  77. package/dist/esm/awaited.js.map +1 -1
  78. package/dist/esm/defer.js.map +1 -1
  79. package/dist/esm/fileRoute.d.ts +17 -17
  80. package/dist/esm/fileRoute.js +1 -1
  81. package/dist/esm/fileRoute.js.map +1 -1
  82. package/dist/esm/lazyRouteComponent.d.ts +1 -1
  83. package/dist/esm/lazyRouteComponent.js.map +1 -1
  84. package/dist/esm/link.d.ts +16 -13
  85. package/dist/esm/link.js +10 -11
  86. package/dist/esm/link.js.map +1 -1
  87. package/dist/esm/location.d.ts +2 -2
  88. package/dist/esm/not-found.d.ts +2 -2
  89. package/dist/esm/not-found.js.map +1 -1
  90. package/dist/esm/path.d.ts +4 -4
  91. package/dist/esm/path.js +2 -2
  92. package/dist/esm/path.js.map +1 -1
  93. package/dist/esm/qss.js +4 -3
  94. package/dist/esm/qss.js.map +1 -1
  95. package/dist/esm/redirects.d.ts +5 -5
  96. package/dist/esm/redirects.js.map +1 -1
  97. package/dist/esm/route.d.ts +34 -36
  98. package/dist/esm/route.js.map +1 -1
  99. package/dist/esm/routeInfo.d.ts +5 -5
  100. package/dist/esm/router.d.ts +28 -28
  101. package/dist/esm/router.js +63 -66
  102. package/dist/esm/router.js.map +1 -1
  103. package/dist/esm/routerContext.d.ts +1 -1
  104. package/dist/esm/routerContext.js +1 -1
  105. package/dist/esm/routerContext.js.map +1 -1
  106. package/dist/esm/scroll-restoration.d.ts +1 -1
  107. package/dist/esm/scroll-restoration.js +7 -9
  108. package/dist/esm/scroll-restoration.js.map +1 -1
  109. package/dist/esm/searchParams.d.ts +1 -1
  110. package/dist/esm/searchParams.js +10 -12
  111. package/dist/esm/searchParams.js.map +1 -1
  112. package/dist/esm/useBlocker.d.ts +2 -2
  113. package/dist/esm/useBlocker.js.map +1 -1
  114. package/dist/esm/useNavigate.d.ts +4 -4
  115. package/dist/esm/useNavigate.js +1 -1
  116. package/dist/esm/useNavigate.js.map +1 -1
  117. package/dist/esm/useParams.d.ts +5 -5
  118. package/dist/esm/useParams.js +1 -1
  119. package/dist/esm/useParams.js.map +1 -1
  120. package/dist/esm/useRouteContext.d.ts +4 -4
  121. package/dist/esm/useRouteContext.js +1 -1
  122. package/dist/esm/useRouteContext.js.map +1 -1
  123. package/dist/esm/useRouter.d.ts +2 -2
  124. package/dist/esm/useRouter.js.map +1 -1
  125. package/dist/esm/useRouterState.d.ts +2 -2
  126. package/dist/esm/useRouterState.js.map +1 -1
  127. package/dist/esm/useSearch.d.ts +4 -4
  128. package/dist/esm/useSearch.js +1 -1
  129. package/dist/esm/useSearch.js.map +1 -1
  130. package/dist/esm/utils.d.ts +13 -11
  131. package/dist/esm/utils.js +2 -2
  132. package/dist/esm/utils.js.map +1 -1
  133. package/package.json +3 -2
  134. package/src/CatchBoundary.tsx +1 -1
  135. package/src/Matches.tsx +48 -47
  136. package/src/RouterProvider.tsx +22 -16
  137. package/src/awaited.tsx +3 -3
  138. package/src/defer.ts +1 -0
  139. package/src/fileRoute.ts +53 -53
  140. package/src/history.ts +1 -1
  141. package/src/lazyRouteComponent.tsx +2 -1
  142. package/src/link.tsx +50 -42
  143. package/src/location.ts +2 -2
  144. package/src/not-found.tsx +3 -2
  145. package/src/path.ts +8 -8
  146. package/src/qss.ts +4 -5
  147. package/src/redirects.ts +5 -5
  148. package/src/route.ts +73 -67
  149. package/src/routeInfo.ts +8 -6
  150. package/src/router.ts +150 -145
  151. package/src/routerContext.tsx +2 -2
  152. package/src/scroll-restoration.tsx +9 -12
  153. package/src/searchParams.ts +11 -13
  154. package/src/useBlocker.tsx +3 -3
  155. package/src/useNavigate.tsx +7 -5
  156. package/src/useParams.tsx +6 -6
  157. package/src/useRouteContext.ts +7 -8
  158. package/src/useRouter.tsx +2 -2
  159. package/src/useRouterState.tsx +2 -2
  160. package/src/useSearch.tsx +7 -6
  161. package/src/utils.ts +36 -24
@@ -1,19 +1,19 @@
1
- import * as React from 'react';
2
- import { HistoryState, RouterHistory } from '@tanstack/history';
3
1
  import { Store } from '@tanstack/react-store';
4
- import { AnySearchSchema, AnyRoute, AnyContext, RouteMask, NotFoundRouteComponent } from './route.js';
5
- import { FullSearchSchema, RouteById, RoutePaths, RoutesById, RoutesByPath } from './routeInfo.js';
6
- import { PickAsRequired, Updater, NonNullableUpdater, Timeout } from './utils.js';
7
- import { RouteComponent } from './route.js';
8
- import { AnyRouteMatch, MatchRouteOptions, RouteMatch } from './Matches.js';
9
- import { ParsedLocation } from './location.js';
10
- import { SearchSerializer, SearchParser } from './searchParams.js';
11
- import { BuildLocationFn, CommitLocationOptions, InjectedHtmlEntry, NavigateFn } from './RouterProvider.js';
12
- import { AnyRedirect, ResolvedRedirect } from './redirects.js';
13
- import { NotFoundError } from './not-found.js';
14
- import { NavigateOptions, ResolveRelativePath, ToOptions } from './link.js';
15
- import { NoInfer } from '@tanstack/react-store';
16
- import { DeferredPromiseState } from './defer.js';
2
+ import type * as React from 'react';
3
+ import type { HistoryState, RouterHistory } from '@tanstack/history';
4
+ import type { AnyContext, AnyRoute, AnySearchSchema, NotFoundRouteComponent, RouteMask } from './route.js';
5
+ import type { FullSearchSchema, RouteById, RoutePaths, RoutesById, RoutesByPath } from './routeInfo.js';
6
+ import type { NonNullableUpdater, PickAsRequired, Timeout, Updater } from './utils.js';
7
+ import type { RouteComponent } from './route.js';
8
+ import type { AnyRouteMatch, MatchRouteOptions, RouteMatch } from './Matches.js';
9
+ import type { ParsedLocation } from './location.js';
10
+ import type { SearchParser, SearchSerializer } from './searchParams.js';
11
+ import type { BuildLocationFn, CommitLocationOptions, InjectedHtmlEntry, NavigateFn } from './RouterProvider.js';
12
+ import type { AnyRedirect, ResolvedRedirect } from './redirects.js';
13
+ import type { NotFoundError } from './not-found.js';
14
+ import type { NavigateOptions, ResolveRelativePath, ToOptions } from './link.js';
15
+ import type { NoInfer } from '@tanstack/react-store';
16
+ import type { DeferredPromiseState } from './defer.js';
17
17
  declare global {
18
18
  interface Window {
19
19
  __TSR_DEHYDRATED__?: {
@@ -59,7 +59,7 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TDehydrated extends
59
59
  context?: TRouteTree['types']['routerContext'];
60
60
  dehydrate?: () => TDehydrated;
61
61
  hydrate?: (dehydrated: TDehydrated) => void;
62
- routeMasks?: RouteMask<TRouteTree>[];
62
+ routeMasks?: Array<RouteMask<TRouteTree>>;
63
63
  unmaskOnReload?: boolean;
64
64
  Wrap?: (props: {
65
65
  children: any;
@@ -89,9 +89,9 @@ export interface RouterState<TRouteTree extends AnyRoute = AnyRoute> {
89
89
  status: 'pending' | 'idle';
90
90
  isLoading: boolean;
91
91
  isTransitioning: boolean;
92
- matches: RouteMatch<TRouteTree>[];
93
- pendingMatches?: RouteMatch<TRouteTree>[];
94
- cachedMatches: RouteMatch<TRouteTree>[];
92
+ matches: Array<RouteMatch<TRouteTree>>;
93
+ pendingMatches?: Array<RouteMatch<TRouteTree>>;
94
+ cachedMatches: Array<RouteMatch<TRouteTree>>;
95
95
  location: ParsedLocation<FullSearchSchema<TRouteTree>>;
96
96
  resolvedLocation: ParsedLocation<FullSearchSchema<TRouteTree>>;
97
97
  lastUpdated: number;
@@ -116,7 +116,7 @@ export interface BuildNextOptions {
116
116
  from?: string;
117
117
  }
118
118
  export interface DehydratedRouterState {
119
- dehydratedMatches: DehydratedRouteMatch[];
119
+ dehydratedMatches: Array<DehydratedRouteMatch>;
120
120
  }
121
121
  export type DehydratedRouteMatch = Pick<RouteMatch, 'id' | 'status' | 'updatedAt' | 'loaderData'>;
122
122
  export interface DehydratedRouter {
@@ -156,7 +156,7 @@ export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated
156
156
  navigateTimeout: Timeout | null;
157
157
  latestLoadPromise: Promise<void>;
158
158
  subscribers: Set<RouterListener<RouterEvent>>;
159
- injectedHtml: InjectedHtmlEntry[];
159
+ injectedHtml: Array<InjectedHtmlEntry>;
160
160
  dehydratedData?: TDehydrated;
161
161
  __store: Store<RouterState<TRouteTree>>;
162
162
  options: PickAsRequired<Omit<RouterOptions<TRouteTree, TDehydrated, TSerializedError>, 'transformer'> & {
@@ -168,7 +168,7 @@ export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated
168
168
  routeTree: TRouteTree;
169
169
  routesById: RoutesById<TRouteTree>;
170
170
  routesByPath: RoutesByPath<TRouteTree>;
171
- flatRoutes: AnyRoute[];
171
+ flatRoutes: Array<AnyRoute>;
172
172
  /**
173
173
  * @deprecated Use the `createRouter` function instead
174
174
  */
@@ -197,14 +197,14 @@ export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated
197
197
  loadMatches: ({ checkLatest, location, matches, preload, }: {
198
198
  checkLatest: () => Promise<void> | undefined;
199
199
  location: ParsedLocation;
200
- matches: AnyRouteMatch[];
200
+ matches: Array<AnyRouteMatch>;
201
201
  preload?: boolean | undefined;
202
- }) => Promise<RouteMatch[]>;
202
+ }) => Promise<Array<RouteMatch>>;
203
203
  invalidate: () => void;
204
204
  load: () => Promise<void>;
205
205
  resolveRedirect: (err: AnyRedirect) => ResolvedRedirect;
206
206
  cleanCache: () => void;
207
- preloadRoute: <TFrom extends string | import("./routeInfo").ParseRoute<TRouteTree, TRouteTree>["fullPath"] = string, TTo extends string = "", TMaskFrom extends string | import("./routeInfo").ParseRoute<TRouteTree, TRouteTree>["fullPath"] = TFrom, TMaskTo extends string = "">(opts: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<AnyRouteMatch[] | undefined>;
207
+ preloadRoute: <TFrom extends string | import("./routeInfo").ParseRoute<TRouteTree, TRouteTree>["fullPath"] = string, TTo extends string = "", TMaskFrom extends string | import("./routeInfo").ParseRoute<TRouteTree, TRouteTree>["fullPath"] = TFrom, TMaskTo extends string = "">(opts: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<Array<AnyRouteMatch> | undefined>;
208
208
  matchRoute: <TFrom extends RoutePaths<TRouteTree> = "/", TTo extends string = "", TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>>(location: ToOptions<TRouteTree, TFrom, TTo>, opts?: MatchRouteOptions) => false | RouteById<TRouteTree, TResolved>["types"]["allParams"];
209
209
  injectHtml: (html: string | (() => Promise<string> | string)) => Promise<void>;
210
210
  registeredDeferredsIds: Map<string, {}>;
@@ -217,13 +217,13 @@ export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated
217
217
  /**
218
218
  * @deprecated Please extract your own data from scripts injected using the `injectHtml` method
219
219
  */
220
- hydrateData: <T extends unknown = unknown>(key: any) => T | undefined;
220
+ hydrateData: <T = unknown>(key: any) => T | undefined;
221
221
  dehydrate: () => DehydratedRouter;
222
222
  hydrate: (__do_not_use_server_ctx?: string) => Promise<void>;
223
- handleNotFound: (matches: AnyRouteMatch[], err: NotFoundError) => void;
223
+ handleNotFound: (matches: Array<AnyRouteMatch>, err: NotFoundError) => void;
224
224
  hasNotFoundMatch: () => boolean;
225
225
  }
226
- export declare function lazyFn<T extends Record<string, (...args: any[]) => any>, TKey extends keyof T = 'default'>(fn: () => Promise<T>, key?: TKey): (...args: Parameters<T[TKey]>) => Promise<Awaited<ReturnType<T[TKey]>>>;
226
+ export declare function lazyFn<T extends Record<string, (...args: Array<any>) => any>, TKey extends keyof T = 'default'>(fn: () => Promise<T>, key?: TKey): (...args: Parameters<T[TKey]>) => Promise<Awaited<ReturnType<T[TKey]>>>;
227
227
  export declare class SearchParamError extends Error {
228
228
  }
229
229
  export declare class PathParamError extends Error {
@@ -1,14 +1,14 @@
1
1
  import { createBrowserHistory, createMemoryHistory } from "@tanstack/history";
2
2
  import { Store } from "@tanstack/react-store";
3
+ import invariant from "tiny-invariant";
4
+ import warning from "tiny-warning";
3
5
  import { rootRouteId } from "./route.js";
4
6
  import { defaultStringifySearch, defaultParseSearch } from "./searchParams.js";
5
7
  import { replaceEqualDeep, pick, isServer, deepEqual, escapeJSON, last, functionalUpdate } from "./utils.js";
6
8
  import { getRouteMatch } from "./RouterProvider.js";
7
9
  import { trimPath, trimPathLeft, parsePathname, resolvePath, cleanPath, matchPathname, trimPathRight, interpolatePath, joinPaths } from "./path.js";
8
- import invariant from "tiny-invariant";
9
10
  import { isRedirect } from "./redirects.js";
10
11
  import { isNotFound } from "./not-found.js";
11
- import warning from "tiny-warning";
12
12
  const componentTypes = [
13
13
  "component",
14
14
  "errorComponent",
@@ -50,7 +50,10 @@ class Router {
50
50
  this.basepath = `/${trimPath(newOptions.basepath)}`;
51
51
  }
52
52
  }
53
- if (!this.history || this.options.history && this.options.history !== this.history) {
53
+ if (
54
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
55
+ !this.history || this.options.history && this.options.history !== this.history
56
+ ) {
54
57
  this.history = this.options.history ?? (typeof document !== "undefined" ? createBrowserHistory() : createMemoryHistory({
55
58
  initialEntries: [this.options.basepath || "/"]
56
59
  }));
@@ -105,7 +108,8 @@ class Router {
105
108
  };
106
109
  recurseRoutes([this.routeTree]);
107
110
  const scoredRoutes = [];
108
- Object.values(this.routesById).forEach((d, i) => {
111
+ const routes = Object.values(this.routesById);
112
+ routes.forEach((d, i) => {
109
113
  var _a;
110
114
  if (d.isRoot || !d.path) {
111
115
  return;
@@ -115,14 +119,14 @@ class Router {
115
119
  while (parsed.length > 1 && ((_a = parsed[0]) == null ? void 0 : _a.value) === "/") {
116
120
  parsed.shift();
117
121
  }
118
- const scores = parsed.map((d2) => {
119
- if (d2.value === "/") {
122
+ const scores = parsed.map((segment) => {
123
+ if (segment.value === "/") {
120
124
  return 0.75;
121
125
  }
122
- if (d2.type === "param") {
126
+ if (segment.type === "param") {
123
127
  return 0.5;
124
128
  }
125
- if (d2.type === "wildcard") {
129
+ if (segment.type === "wildcard") {
126
130
  return 0.25;
127
131
  }
128
132
  return 1;
@@ -189,7 +193,7 @@ class Router {
189
193
  };
190
194
  };
191
195
  const location = parse(this.history.location);
192
- let { __tempLocation, __tempKey } = location.state;
196
+ const { __tempLocation, __tempKey } = location.state;
193
197
  if (__tempLocation && (!__tempKey || __tempKey === this.tempLocationKey)) {
194
198
  const parsedTempLocation = parse(__tempLocation);
195
199
  parsedTempLocation.state.key = location.state.key;
@@ -206,7 +210,7 @@ class Router {
206
210
  };
207
211
  this.matchRoutes = (pathname, locationSearch, opts) => {
208
212
  let routeParams = {};
209
- let foundRoute = this.flatRoutes.find((route) => {
213
+ const foundRoute = this.flatRoutes.find((route) => {
210
214
  const matchedParams = matchPathname(
211
215
  this.basepath,
212
216
  trimPathRight(pathname),
@@ -223,7 +227,7 @@ class Router {
223
227
  return false;
224
228
  });
225
229
  let routeCursor = foundRoute || this.routesById[rootRouteId];
226
- let matchedRoutes = [routeCursor];
230
+ const matchedRoutes = [routeCursor];
227
231
  let isGlobalNotFound = false;
228
232
  if (
229
233
  // If we found a route, and it's not an index route and we have left over path
@@ -238,10 +242,9 @@ class Router {
238
242
  isGlobalNotFound = true;
239
243
  }
240
244
  }
241
- while (routeCursor == null ? void 0 : routeCursor.parentRoute) {
245
+ while (routeCursor.parentRoute) {
242
246
  routeCursor = routeCursor.parentRoute;
243
- if (routeCursor)
244
- matchedRoutes.unshift(routeCursor);
247
+ matchedRoutes.unshift(routeCursor);
245
248
  }
246
249
  const globalNotFoundRouteId = (() => {
247
250
  if (!isGlobalNotFound) {
@@ -283,7 +286,7 @@ class Router {
283
286
  const parentSearch = (parentMatch == null ? void 0 : parentMatch.search) ?? locationSearch;
284
287
  try {
285
288
  const validator = typeof route.options.validateSearch === "object" ? route.options.validateSearch.parse : route.options.validateSearch;
286
- let search = (validator == null ? void 0 : validator(parentSearch)) ?? {};
289
+ const search = (validator == null ? void 0 : validator(parentSearch)) ?? {};
287
290
  return [
288
291
  {
289
292
  ...parentSearch,
@@ -292,13 +295,13 @@ class Router {
292
295
  void 0
293
296
  ];
294
297
  } catch (err) {
295
- const searchError2 = new SearchParamError(err.message, {
298
+ const searchParamError = new SearchParamError(err.message, {
296
299
  cause: err
297
300
  });
298
301
  if (opts == null ? void 0 : opts.throwOnError) {
299
- throw searchError2;
302
+ throw searchParamError;
300
303
  }
301
- return [parentSearch, searchError2];
304
+ return [parentSearch, searchParamError];
302
305
  }
303
306
  })();
304
307
  const loaderDeps = ((_b = (_a = route.options).loaderDeps) == null ? void 0 : _b.call(_a, {
@@ -314,7 +317,7 @@ class Router {
314
317
  params: routeParams,
315
318
  leaveWildcards: true
316
319
  }) + loaderDepsHash;
317
- let existingMatch = getRouteMatch(this.state, matchId);
320
+ const existingMatch = getRouteMatch(this.state, matchId);
318
321
  const cause = this.state.matches.find((d) => d.id === matchId) ? "stay" : "enter";
319
322
  const match = existingMatch ? {
320
323
  ...existingMatch,
@@ -369,13 +372,16 @@ class Router {
369
372
  const build = (dest = {}, matches) => {
370
373
  var _a, _b, _c;
371
374
  const relevantMatches = this.state.pendingMatches || this.state.matches;
372
- const fromSearch = ((_a = relevantMatches[relevantMatches.length - 1]) == null ? void 0 : _a.search) || this.latestLocation.search;
375
+ const fromSearch = (
376
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
377
+ ((_a = relevantMatches[relevantMatches.length - 1]) == null ? void 0 : _a.search) || this.latestLocation.search
378
+ );
373
379
  const fromMatches = this.matchRoutes(
374
380
  this.latestLocation.pathname,
375
381
  fromSearch
376
382
  );
377
383
  const stayingMatches = matches == null ? void 0 : matches.filter(
378
- (d) => fromMatches == null ? void 0 : fromMatches.find((e) => e.routeId === d.routeId)
384
+ (d) => fromMatches.find((e) => e.routeId === d.routeId)
379
385
  );
380
386
  const fromRoute = this.looseRoutesById[(_b = last(fromMatches)) == null ? void 0 : _b.routeId];
381
387
  let pathname = dest.to ? this.resolvePathWithBase(
@@ -401,12 +407,9 @@ class Router {
401
407
  const postSearchFilters = (stayingMatches == null ? void 0 : stayingMatches.map(
402
408
  (match) => this.looseRoutesById[match.routeId].options.postSearchFilters ?? []
403
409
  ).flat().filter(Boolean)) ?? [];
404
- const preFilteredSearch = (preSearchFilters == null ? void 0 : preSearchFilters.length) ? preSearchFilters == null ? void 0 : preSearchFilters.reduce(
405
- (prev, next) => next(prev),
406
- fromSearch
407
- ) : fromSearch;
408
- const destSearch = dest.search === true ? preFilteredSearch : dest.search ? functionalUpdate(dest.search, preFilteredSearch) ?? {} : (preSearchFilters == null ? void 0 : preSearchFilters.length) ? preFilteredSearch : {};
409
- const postFilteredSearch = (postSearchFilters == null ? void 0 : postSearchFilters.length) ? postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
410
+ const preFilteredSearch = preSearchFilters.length ? preSearchFilters.reduce((prev, next) => next(prev), fromSearch) : fromSearch;
411
+ const destSearch = dest.search === true ? preFilteredSearch : dest.search ? functionalUpdate(dest.search, preFilteredSearch) : preSearchFilters.length ? preFilteredSearch : {};
412
+ const postFilteredSearch = postSearchFilters.length ? postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
410
413
  const search = replaceEqualDeep(fromSearch, postFilteredSearch);
411
414
  const searchStr = this.options.stringifySearch(search);
412
415
  const hash = dest.hash === true ? this.latestLocation.hash : dest.hash ? functionalUpdate(dest.hash, this.latestLocation.hash) : void 0;
@@ -425,11 +428,11 @@ class Router {
425
428
  };
426
429
  const buildWithMatches = (dest = {}, maskedDest) => {
427
430
  var _a;
428
- let next = build(dest);
431
+ const next = build(dest);
429
432
  let maskedNext = maskedDest ? build(maskedDest) : void 0;
430
433
  if (!maskedNext) {
431
434
  let params = {};
432
- let foundMask = (_a = this.options.routeMasks) == null ? void 0 : _a.find((d) => {
435
+ const foundMask = (_a = this.options.routeMasks) == null ? void 0 : _a.find((d) => {
433
436
  const match = matchPathname(this.basepath, next.pathname, {
434
437
  to: d.from,
435
438
  caseSensitive: false,
@@ -654,6 +657,7 @@ class Router {
654
657
  const matchPromises = [];
655
658
  validResolvedMatches.forEach((match, index) => {
656
659
  matchPromises.push(
660
+ // eslint-disable-next-line no-async-promise-executor
657
661
  new Promise(async (resolve, reject) => {
658
662
  var _a2;
659
663
  const parentMatchPromise = matchPromises[index - 1];
@@ -748,12 +752,13 @@ class Router {
748
752
  meta,
749
753
  headers
750
754
  };
751
- } catch (error) {
755
+ } catch (e) {
756
+ let error = e;
752
757
  if (latestPromise = checkLatest())
753
758
  return await latestPromise;
754
- handleError(error);
759
+ handleError(e);
755
760
  try {
756
- (_j = (_i = route.options).onError) == null ? void 0 : _j.call(_i, error);
761
+ (_j = (_i = route.options).onError) == null ? void 0 : _j.call(_i, e);
757
762
  } catch (onErrorError) {
758
763
  error = onErrorError;
759
764
  handleError(onErrorError);
@@ -768,10 +773,9 @@ class Router {
768
773
  updateMatch(match);
769
774
  };
770
775
  const age = Date.now() - match.updatedAt;
771
- let staleAge = preload ? route.options.preloadStaleTime ?? this.options.defaultPreloadStaleTime ?? 3e4 : route.options.staleTime ?? this.options.defaultStaleTime ?? 0;
772
- let shouldReload;
776
+ const staleAge = preload ? route.options.preloadStaleTime ?? this.options.defaultPreloadStaleTime ?? 3e4 : route.options.staleTime ?? this.options.defaultStaleTime ?? 0;
773
777
  const shouldReloadOption = route.options.shouldReload;
774
- shouldReload = typeof shouldReloadOption === "function" ? shouldReloadOption(loaderContext) : shouldReloadOption;
778
+ const shouldReload = typeof shouldReloadOption === "function" ? shouldReloadOption(loaderContext) : shouldReloadOption;
775
779
  matches[index] = match = {
776
780
  ...match,
777
781
  preload: !!preload && !this.state.matches.find((d) => d.id === match.id)
@@ -944,7 +948,7 @@ class Router {
944
948
  return this.latestLoadPromise;
945
949
  };
946
950
  this.resolveRedirect = (err) => {
947
- let redirect = err;
951
+ const redirect = err;
948
952
  if (!redirect.href) {
949
953
  redirect.href = this.buildLocation(redirect).href;
950
954
  }
@@ -966,18 +970,17 @@ class Router {
966
970
  });
967
971
  };
968
972
  this.preloadRoute = async (opts) => {
969
- var _a;
970
- let next = this.buildLocation(opts);
973
+ const next = this.buildLocation(opts);
971
974
  let matches = this.matchRoutes(next.pathname, next.search, {
972
975
  throwOnError: true,
973
976
  preload: true
974
977
  });
975
978
  const loadedMatchIds = Object.fromEntries(
976
- (_a = [
979
+ [
977
980
  ...this.state.matches,
978
981
  ...this.state.pendingMatches ?? [],
979
982
  ...this.state.cachedMatches
980
- ]) == null ? void 0 : _a.map((d) => [d.id, true])
983
+ ].map((d) => [d.id, true])
981
984
  );
982
985
  this.__store.batch(() => {
983
986
  matches.forEach((match) => {
@@ -1017,9 +1020,6 @@ class Router {
1017
1020
  return false;
1018
1021
  }
1019
1022
  const baseLocation = (opts == null ? void 0 : opts.pending) ? this.latestLocation : this.state.resolvedLocation;
1020
- if (!baseLocation) {
1021
- return false;
1022
- }
1023
1023
  const match = matchPathname(this.basepath, baseLocation.pathname, {
1024
1024
  ...opts,
1025
1025
  to: next.pathname
@@ -1113,7 +1113,7 @@ class Router {
1113
1113
  this.dehydratedData = ctx.payload;
1114
1114
  (_c = (_b = this.options).hydrate) == null ? void 0 : _c.call(_b, ctx.payload);
1115
1115
  const dehydratedState = ctx.router.state;
1116
- let matches = this.matchRoutes(
1116
+ const matches = this.matchRoutes(
1117
1117
  this.state.location.pathname,
1118
1118
  this.state.location.search
1119
1119
  ).map((match) => {
@@ -1125,23 +1125,20 @@ class Router {
1125
1125
  dehydratedMatch,
1126
1126
  `Could not find a client-side match for dehydrated match with id: ${match.id}!`
1127
1127
  );
1128
- if (dehydratedMatch) {
1129
- const route = this.looseRoutesById[match.routeId];
1130
- const assets = dehydratedMatch.status === "notFound" || dehydratedMatch.status === "redirected" ? {} : {
1131
- meta: (_b2 = (_a2 = route.options).meta) == null ? void 0 : _b2.call(_a2, {
1132
- params: match.params,
1133
- loaderData: dehydratedMatch.loaderData
1134
- }),
1135
- links: (_d = (_c2 = route.options).links) == null ? void 0 : _d.call(_c2),
1136
- scripts: (_f = (_e = route.options).scripts) == null ? void 0 : _f.call(_e)
1137
- };
1138
- return {
1139
- ...match,
1140
- ...dehydratedMatch,
1141
- ...assets
1142
- };
1143
- }
1144
- return match;
1128
+ const route = this.looseRoutesById[match.routeId];
1129
+ const assets = dehydratedMatch.status === "notFound" || dehydratedMatch.status === "redirected" ? {} : {
1130
+ meta: (_b2 = (_a2 = route.options).meta) == null ? void 0 : _b2.call(_a2, {
1131
+ params: match.params,
1132
+ loaderData: dehydratedMatch.loaderData
1133
+ }),
1134
+ links: (_d = (_c2 = route.options).links) == null ? void 0 : _d.call(_c2),
1135
+ scripts: (_f = (_e = route.options).scripts) == null ? void 0 : _f.call(_e)
1136
+ };
1137
+ return {
1138
+ ...match,
1139
+ ...dehydratedMatch,
1140
+ ...assets
1141
+ };
1145
1142
  });
1146
1143
  this.__store.setState((s) => {
1147
1144
  return {
@@ -1157,13 +1154,13 @@ class Router {
1157
1154
  );
1158
1155
  let routeCursor = (err.global ? this.looseRoutesById[rootRouteId] : this.looseRoutesById[err.routeId]) || this.looseRoutesById[rootRouteId];
1159
1156
  while (!routeCursor.options.notFoundComponent && !this.options.defaultNotFoundComponent && routeCursor.id !== rootRouteId) {
1160
- routeCursor = routeCursor == null ? void 0 : routeCursor.parentRoute;
1157
+ routeCursor = routeCursor.parentRoute;
1161
1158
  invariant(
1162
1159
  routeCursor,
1163
1160
  "Found invalid route tree while trying to find not-found handler."
1164
1161
  );
1165
1162
  }
1166
- let match = matchesByRouteId[routeCursor.id];
1163
+ const match = matchesByRouteId[routeCursor.id];
1167
1164
  invariant(match, "Could not find match for route: " + routeCursor.id);
1168
1165
  Object.assign(match, {
1169
1166
  status: "notFound",
@@ -1182,9 +1179,9 @@ class Router {
1182
1179
  defaultPendingMinMs: 500,
1183
1180
  context: void 0,
1184
1181
  ...options,
1185
- stringifySearch: (options == null ? void 0 : options.stringifySearch) ?? defaultStringifySearch,
1186
- parseSearch: (options == null ? void 0 : options.parseSearch) ?? defaultParseSearch,
1187
- transformer: (options == null ? void 0 : options.transformer) ?? JSON
1182
+ stringifySearch: options.stringifySearch ?? defaultStringifySearch,
1183
+ parseSearch: options.parseSearch ?? defaultParseSearch,
1184
+ transformer: options.transformer ?? JSON
1188
1185
  });
1189
1186
  if (typeof document !== "undefined") {
1190
1187
  window.__TSR__ROUTER__ = this;