@tanstack/router-core 1.131.7 → 1.132.0-alpha.1

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 (88) hide show
  1. package/dist/cjs/Matches.cjs.map +1 -1
  2. package/dist/cjs/Matches.d.cts +9 -7
  3. package/dist/cjs/defer.cjs +1 -1
  4. package/dist/cjs/defer.cjs.map +1 -1
  5. package/dist/cjs/index.cjs +0 -2
  6. package/dist/cjs/index.cjs.map +1 -1
  7. package/dist/cjs/index.d.cts +1 -1
  8. package/dist/cjs/lru-cache.cjs.map +1 -1
  9. package/dist/cjs/not-found.cjs +1 -1
  10. package/dist/cjs/not-found.cjs.map +1 -1
  11. package/dist/cjs/path.cjs +10 -12
  12. package/dist/cjs/path.cjs.map +1 -1
  13. package/dist/cjs/qss.cjs.map +1 -1
  14. package/dist/cjs/redirect.cjs.map +1 -1
  15. package/dist/cjs/route.cjs +6 -7
  16. package/dist/cjs/route.cjs.map +1 -1
  17. package/dist/cjs/router.cjs +168 -196
  18. package/dist/cjs/router.cjs.map +1 -1
  19. package/dist/cjs/router.d.cts +1 -2
  20. package/dist/cjs/scroll-restoration.cjs +2 -3
  21. package/dist/cjs/scroll-restoration.cjs.map +1 -1
  22. package/dist/cjs/scroll-restoration.d.cts +9 -0
  23. package/dist/cjs/searchMiddleware.cjs.map +1 -1
  24. package/dist/cjs/searchParams.cjs.map +1 -1
  25. package/dist/cjs/ssr/createRequestHandler.cjs +2 -3
  26. package/dist/cjs/ssr/createRequestHandler.cjs.map +1 -1
  27. package/dist/cjs/ssr/handlerCallback.cjs.map +1 -1
  28. package/dist/cjs/ssr/headers.cjs.map +1 -1
  29. package/dist/cjs/ssr/json.cjs +1 -1
  30. package/dist/cjs/ssr/json.cjs.map +1 -1
  31. package/dist/cjs/ssr/seroval-plugins.cjs.map +1 -1
  32. package/dist/cjs/ssr/ssr-client.cjs +47 -48
  33. package/dist/cjs/ssr/ssr-client.cjs.map +1 -1
  34. package/dist/cjs/ssr/ssr-server.cjs +2 -3
  35. package/dist/cjs/ssr/ssr-server.cjs.map +1 -1
  36. package/dist/cjs/ssr/transformStreamWithRouter.cjs +3 -4
  37. package/dist/cjs/ssr/transformStreamWithRouter.cjs.map +1 -1
  38. package/dist/cjs/typePrimitives.d.cts +6 -6
  39. package/dist/cjs/utils.cjs +4 -27
  40. package/dist/cjs/utils.cjs.map +1 -1
  41. package/dist/cjs/utils.d.cts +0 -6
  42. package/dist/esm/Matches.d.ts +9 -7
  43. package/dist/esm/Matches.js.map +1 -1
  44. package/dist/esm/defer.js +1 -1
  45. package/dist/esm/defer.js.map +1 -1
  46. package/dist/esm/index.d.ts +1 -1
  47. package/dist/esm/index.js +1 -3
  48. package/dist/esm/lru-cache.js.map +1 -1
  49. package/dist/esm/not-found.js +1 -1
  50. package/dist/esm/not-found.js.map +1 -1
  51. package/dist/esm/path.js +10 -12
  52. package/dist/esm/path.js.map +1 -1
  53. package/dist/esm/qss.js.map +1 -1
  54. package/dist/esm/redirect.js.map +1 -1
  55. package/dist/esm/route.js +6 -7
  56. package/dist/esm/route.js.map +1 -1
  57. package/dist/esm/router.d.ts +1 -2
  58. package/dist/esm/router.js +168 -196
  59. package/dist/esm/router.js.map +1 -1
  60. package/dist/esm/scroll-restoration.d.ts +9 -0
  61. package/dist/esm/scroll-restoration.js +2 -3
  62. package/dist/esm/scroll-restoration.js.map +1 -1
  63. package/dist/esm/searchMiddleware.js.map +1 -1
  64. package/dist/esm/searchParams.js.map +1 -1
  65. package/dist/esm/ssr/createRequestHandler.js +2 -3
  66. package/dist/esm/ssr/createRequestHandler.js.map +1 -1
  67. package/dist/esm/ssr/handlerCallback.js.map +1 -1
  68. package/dist/esm/ssr/headers.js.map +1 -1
  69. package/dist/esm/ssr/json.js +1 -1
  70. package/dist/esm/ssr/json.js.map +1 -1
  71. package/dist/esm/ssr/seroval-plugins.js.map +1 -1
  72. package/dist/esm/ssr/ssr-client.js +47 -48
  73. package/dist/esm/ssr/ssr-client.js.map +1 -1
  74. package/dist/esm/ssr/ssr-server.js +2 -3
  75. package/dist/esm/ssr/ssr-server.js.map +1 -1
  76. package/dist/esm/ssr/transformStreamWithRouter.js +3 -4
  77. package/dist/esm/ssr/transformStreamWithRouter.js.map +1 -1
  78. package/dist/esm/typePrimitives.d.ts +6 -6
  79. package/dist/esm/utils.d.ts +0 -6
  80. package/dist/esm/utils.js +5 -28
  81. package/dist/esm/utils.js.map +1 -1
  82. package/package.json +2 -2
  83. package/src/Matches.ts +8 -16
  84. package/src/index.ts +0 -2
  85. package/src/router.ts +112 -110
  86. package/src/ssr/ssr-client.ts +41 -42
  87. package/src/typePrimitives.ts +6 -6
  88. package/src/utils.ts +0 -41
@@ -27,9 +27,9 @@ function defaultSerializeError(err) {
27
27
  function getLocationChangeInfo(routerState) {
28
28
  const fromLocation = routerState.resolvedLocation;
29
29
  const toLocation = routerState.location;
30
- const pathChanged = (fromLocation == null ? void 0 : fromLocation.pathname) !== toLocation.pathname;
31
- const hrefChanged = (fromLocation == null ? void 0 : fromLocation.href) !== toLocation.href;
32
- const hashChanged = (fromLocation == null ? void 0 : fromLocation.hash) !== toLocation.hash;
30
+ const pathChanged = fromLocation?.pathname !== toLocation.pathname;
31
+ const hrefChanged = fromLocation?.href !== toLocation.href;
32
+ const hashChanged = fromLocation?.hash !== toLocation.hash;
33
33
  return { fromLocation, toLocation, pathChanged, hrefChanged, hashChanged };
34
34
  }
35
35
  class RouterCore {
@@ -48,7 +48,6 @@ class RouterCore {
48
48
  this.isScrollRestorationSetup = false;
49
49
  this.startTransition = (fn) => fn();
50
50
  this.update = (newOptions) => {
51
- var _a;
52
51
  if (newOptions.notFoundRoute) {
53
52
  console.warn(
54
53
  "The notFoundRoute API is deprecated and will be removed in the next major version. See https://tanstack.com/router/v1/docs/framework/react/guide/not-found-errors#migrating-from-notfoundroute for more info."
@@ -77,7 +76,7 @@ class RouterCore {
77
76
  this.history = this.options.history ?? (this.isServer ? createMemoryHistory({
78
77
  initialEntries: [this.basepath || "/"]
79
78
  }) : createBrowserHistory());
80
- this.updateLatestLocation();
79
+ this.latestLocation = this.parseLocation();
81
80
  }
82
81
  if (this.options.routeTree !== this.routeTree) {
83
82
  this.routeTree = this.options.routeTree;
@@ -96,18 +95,12 @@ class RouterCore {
96
95
  });
97
96
  setupScrollRestoration(this);
98
97
  }
99
- if (typeof window !== "undefined" && "CSS" in window && typeof ((_a = window.CSS) == null ? void 0 : _a.supports) === "function") {
98
+ if (typeof window !== "undefined" && "CSS" in window && typeof window.CSS?.supports === "function") {
100
99
  this.isViewTransitionTypesSupported = window.CSS.supports(
101
100
  "selector(:active-view-transition-type(a)"
102
101
  );
103
102
  }
104
103
  };
105
- this.updateLatestLocation = () => {
106
- this.latestLocation = this.parseLocation(
107
- this.history.location,
108
- this.latestLocation
109
- );
110
- };
111
104
  this.buildRouteTree = () => {
112
105
  const { routesById, routesByPath, flatRoutes } = processRouteTree({
113
106
  routeTree: this.routeTree,
@@ -145,7 +138,7 @@ class RouterCore {
145
138
  }
146
139
  });
147
140
  };
148
- this.parseLocation = (locationToParse, previousLocation) => {
141
+ this.parseLocation = (previousLocation, locationToParse) => {
149
142
  const parse = ({
150
143
  pathname,
151
144
  search,
@@ -157,13 +150,13 @@ class RouterCore {
157
150
  return {
158
151
  pathname,
159
152
  searchStr,
160
- search: replaceEqualDeep(previousLocation == null ? void 0 : previousLocation.search, parsedSearch),
153
+ search: replaceEqualDeep(previousLocation?.search, parsedSearch),
161
154
  hash: hash.split("#").reverse()[0] ?? "",
162
155
  href: `${pathname}${searchStr}${hash}`,
163
- state: replaceEqualDeep(previousLocation == null ? void 0 : previousLocation.state, state)
156
+ state: replaceEqualDeep(previousLocation?.state, state)
164
157
  };
165
158
  };
166
- const location = parse(locationToParse);
159
+ const location = parse(locationToParse ?? this.history.location);
167
160
  const { __tempLocation, __tempKey } = location.state;
168
161
  if (__tempLocation && (!__tempKey || __tempKey === this.tempLocationKey)) {
169
162
  const parsedTempLocation = parse(__tempLocation);
@@ -217,24 +210,27 @@ class RouterCore {
217
210
  const match = this.getMatch(id);
218
211
  if (!match) return;
219
212
  match.abortController.abort();
220
- match._nonReactive.pendingTimeout = void 0;
221
- clearTimeout(match._nonReactive.pendingTimeout);
213
+ this.updateMatch(id, (prev) => {
214
+ clearTimeout(prev.pendingTimeout);
215
+ return {
216
+ ...prev,
217
+ pendingTimeout: void 0
218
+ };
219
+ });
222
220
  };
223
221
  this.cancelMatches = () => {
224
- var _a;
225
- (_a = this.state.pendingMatches) == null ? void 0 : _a.forEach((match) => {
222
+ this.state.pendingMatches?.forEach((match) => {
226
223
  this.cancelMatch(match.id);
227
224
  });
228
225
  };
229
226
  this.buildLocation = (opts) => {
230
227
  const build = (dest = {}) => {
231
- var _a;
232
228
  const currentLocation = dest._fromLocation || this.latestLocation;
233
229
  const allCurrentLocationMatches = this.matchRoutes(currentLocation, {
234
230
  _buildLocation: true
235
231
  });
236
232
  const lastMatch = last(allCurrentLocationMatches);
237
- let fromPath = this.resolvePathWithBase(lastMatch.fullPath, ".");
233
+ let fromPath = lastMatch.fullPath;
238
234
  const toPath = dest.to ? this.resolvePathWithBase(fromPath, `${dest.to}`) : this.resolvePathWithBase(fromPath, ".");
239
235
  const routeIsChanging = !!dest.to && !comparePaths(dest.to.toString(), fromPath) && !comparePaths(toPath, fromPath);
240
236
  if (dest.unsafeRelative === "path") {
@@ -257,7 +253,6 @@ class RouterCore {
257
253
  }
258
254
  }
259
255
  }
260
- fromPath = this.resolvePathWithBase(fromPath, ".");
261
256
  const fromSearch = lastMatch.search;
262
257
  const fromParams = { ...lastMatch.params };
263
258
  const nextTo = dest.to ? this.resolvePathWithBase(fromPath, `${dest.to}`) : this.resolvePathWithBase(fromPath, ".");
@@ -270,13 +265,16 @@ class RouterCore {
270
265
  params: nextParams ?? {},
271
266
  parseCache: this.parsePathnameCache
272
267
  }).interpolatedPath;
273
- const destRoutes = this.matchRoutes(interpolatedNextTo, void 0, {
274
- _buildLocation: true
275
- }).map((d) => this.looseRoutesById[d.routeId]);
268
+ const destRoutes = this.matchRoutes(
269
+ interpolatedNextTo,
270
+ {},
271
+ {
272
+ _buildLocation: true
273
+ }
274
+ ).map((d) => this.looseRoutesById[d.routeId]);
276
275
  if (Object.keys(nextParams).length > 0) {
277
276
  destRoutes.map((route) => {
278
- var _a2;
279
- return ((_a2 = route.options.params) == null ? void 0 : _a2.stringify) ?? route.options.stringifyParams;
277
+ return route.options.params?.stringify ?? route.options.stringifyParams;
280
278
  }).filter(Boolean).forEach((fn) => {
281
279
  nextParams = { ...nextParams, ...fn(nextParams) };
282
280
  });
@@ -292,7 +290,7 @@ class RouterCore {
292
290
  parseCache: this.parsePathnameCache
293
291
  }).interpolatedPath;
294
292
  let nextSearch = fromSearch;
295
- if (opts._includeValidateSearch && ((_a = this.options.search) == null ? void 0 : _a.strict)) {
293
+ if (opts._includeValidateSearch && this.options.search?.strict) {
296
294
  let validatedSearch = {};
297
295
  destRoutes.forEach((route) => {
298
296
  try {
@@ -333,12 +331,11 @@ class RouterCore {
333
331
  };
334
332
  };
335
333
  const buildWithMatches = (dest = {}, maskedDest) => {
336
- var _a;
337
334
  const next = build(dest);
338
335
  let maskedNext = maskedDest ? build(maskedDest) : void 0;
339
336
  if (!maskedNext) {
340
337
  let params = {};
341
- const foundMask = (_a = this.options.routeMasks) == null ? void 0 : _a.find((d) => {
338
+ const foundMask = this.options.routeMasks?.find((d) => {
342
339
  const match = matchPathname(
343
340
  this.basepath,
344
341
  next.pathname,
@@ -404,7 +401,7 @@ class RouterCore {
404
401
  const isSameUrl = this.latestLocation.href === next.href;
405
402
  const previousCommitPromise = this.commitLocationPromise;
406
403
  this.commitLocationPromise = createControlledPromise(() => {
407
- previousCommitPromise == null ? void 0 : previousCommitPromise.resolve();
404
+ previousCommitPromise?.resolve();
408
405
  });
409
406
  if (isSameUrl && isSameState()) {
410
407
  this.load();
@@ -508,7 +505,7 @@ class RouterCore {
508
505
  };
509
506
  this.beforeLoad = () => {
510
507
  this.cancelMatches();
511
- this.updateLatestLocation();
508
+ this.latestLocation = this.parseLocation(this.latestLocation);
512
509
  if (this.isServer) {
513
510
  const nextLocation = this.buildLocation({
514
511
  to: this.latestLocation.pathname,
@@ -549,7 +546,6 @@ class RouterCore {
549
546
  let loadPromise;
550
547
  loadPromise = new Promise((resolve) => {
551
548
  this.startTransition(async () => {
552
- var _a;
553
549
  try {
554
550
  this.beforeLoad();
555
551
  const next = this.latestLocation;
@@ -571,7 +567,7 @@ class RouterCore {
571
567
  })
572
568
  });
573
569
  await this.loadMatches({
574
- sync: opts == null ? void 0 : opts.sync,
570
+ sync: opts?.sync,
575
571
  matches: this.state.pendingMatches,
576
572
  location: next,
577
573
  // eslint-disable-next-line @typescript-eslint/require-await
@@ -613,8 +609,7 @@ class RouterCore {
613
609
  [stayingMatches, "onStay"]
614
610
  ].forEach(([matches, hook]) => {
615
611
  matches.forEach((match) => {
616
- var _a2, _b;
617
- (_b = (_a2 = this.looseRoutesById[match.routeId].options)[hook]) == null ? void 0 : _b.call(_a2, match);
612
+ this.looseRoutesById[match.routeId].options[hook]?.(match);
618
613
  });
619
614
  });
620
615
  });
@@ -640,7 +635,7 @@ class RouterCore {
640
635
  }));
641
636
  }
642
637
  if (this.latestLoadPromise === loadPromise) {
643
- (_a = this.commitLocationPromise) == null ? void 0 : _a.resolve();
638
+ this.commitLocationPromise?.resolve();
644
639
  this.latestLoadPromise = void 0;
645
640
  this.commitLocationPromise = void 0;
646
641
  }
@@ -686,22 +681,17 @@ class RouterCore {
686
681
  }
687
682
  };
688
683
  this.updateMatch = (id, updater) => {
689
- var _a;
690
- const matchesKey = ((_a = this.state.pendingMatches) == null ? void 0 : _a.some((d) => d.id === id)) ? "pendingMatches" : this.state.matches.some((d) => d.id === id) ? "matches" : this.state.cachedMatches.some((d) => d.id === id) ? "cachedMatches" : "";
684
+ const matchesKey = this.state.pendingMatches?.some((d) => d.id === id) ? "pendingMatches" : this.state.matches.some((d) => d.id === id) ? "matches" : this.state.cachedMatches.some((d) => d.id === id) ? "cachedMatches" : "";
691
685
  if (matchesKey) {
692
- this.__store.setState((s) => {
693
- var _a2;
694
- return {
695
- ...s,
696
- [matchesKey]: (_a2 = s[matchesKey]) == null ? void 0 : _a2.map((d) => d.id === id ? updater(d) : d)
697
- };
698
- });
686
+ this.__store.setState((s) => ({
687
+ ...s,
688
+ [matchesKey]: s[matchesKey]?.map((d) => d.id === id ? updater(d) : d)
689
+ }));
699
690
  }
700
691
  };
701
692
  this.getMatch = (matchId) => {
702
- var _a;
703
693
  const findFn = (d) => d.id === matchId;
704
- return this.state.cachedMatches.find(findFn) ?? ((_a = this.state.pendingMatches) == null ? void 0 : _a.find(findFn)) ?? this.state.matches.find(findFn);
694
+ return this.state.cachedMatches.find(findFn) ?? this.state.pendingMatches?.find(findFn) ?? this.state.matches.find(findFn);
705
695
  };
706
696
  this.loadMatches = async ({
707
697
  location,
@@ -716,7 +706,7 @@ class RouterCore {
716
706
  const triggerOnReady = async () => {
717
707
  if (!rendered) {
718
708
  rendered = true;
719
- await (onReady == null ? void 0 : onReady());
709
+ await onReady?.();
720
710
  }
721
711
  };
722
712
  const resolvePreload = (matchId) => {
@@ -726,7 +716,6 @@ class RouterCore {
726
716
  triggerOnReady();
727
717
  }
728
718
  const handleRedirectAndNotFound = (match, err) => {
729
- var _a, _b, _c;
730
719
  if (isRedirect(err) || isNotFound(err)) {
731
720
  if (isRedirect(err)) {
732
721
  if (err.redirectHandled) {
@@ -735,20 +724,20 @@ class RouterCore {
735
724
  }
736
725
  }
737
726
  }
738
- (_a = match._nonReactive.beforeLoadPromise) == null ? void 0 : _a.resolve();
739
- (_b = match._nonReactive.loaderPromise) == null ? void 0 : _b.resolve();
740
- match._nonReactive.beforeLoadPromise = void 0;
741
- match._nonReactive.loaderPromise = void 0;
727
+ match.beforeLoadPromise?.resolve();
728
+ match.loaderPromise?.resolve();
742
729
  updateMatch(match.id, (prev) => ({
743
730
  ...prev,
744
731
  status: isRedirect(err) ? "redirected" : isNotFound(err) ? "notFound" : "error",
745
732
  isFetching: false,
746
- error: err
733
+ error: err,
734
+ beforeLoadPromise: void 0,
735
+ loaderPromise: void 0
747
736
  }));
748
737
  if (!err.routeId) {
749
738
  err.routeId = match.routeId;
750
739
  }
751
- (_c = match._nonReactive.loadPromise) == null ? void 0 : _c.resolve();
740
+ match.loadPromise?.resolve();
752
741
  if (isRedirect(err)) {
753
742
  rendered = true;
754
743
  err.options._fromLocation = location;
@@ -765,7 +754,7 @@ class RouterCore {
765
754
  };
766
755
  const shouldSkipLoader = (matchId) => {
767
756
  const match = this.getMatch(matchId);
768
- if (!this.isServer && match._nonReactive.dehydrated) {
757
+ if (!this.isServer && match._dehydrated) {
769
758
  return true;
770
759
  }
771
760
  if (this.isServer) {
@@ -779,10 +768,8 @@ class RouterCore {
779
768
  await new Promise((resolveAll, rejectAll) => {
780
769
  ;
781
770
  (async () => {
782
- var _a, _b, _c, _d;
783
771
  try {
784
772
  const handleSerialError = (index, err, routerCode) => {
785
- var _a2, _b2;
786
773
  const { id: matchId, routeId } = matches[index];
787
774
  const route = this.looseRoutesById[routeId];
788
775
  if (err instanceof Promise) {
@@ -792,29 +779,28 @@ class RouterCore {
792
779
  firstBadMatchIndex = firstBadMatchIndex ?? index;
793
780
  handleRedirectAndNotFound(this.getMatch(matchId), err);
794
781
  try {
795
- (_b2 = (_a2 = route.options).onError) == null ? void 0 : _b2.call(_a2, err);
782
+ route.options.onError?.(err);
796
783
  } catch (errorHandlerErr) {
797
784
  err = errorHandlerErr;
798
785
  handleRedirectAndNotFound(this.getMatch(matchId), err);
799
786
  }
800
787
  updateMatch(matchId, (prev) => {
801
- var _a3, _b3;
802
- (_a3 = prev._nonReactive.beforeLoadPromise) == null ? void 0 : _a3.resolve();
803
- prev._nonReactive.beforeLoadPromise = void 0;
804
- (_b3 = prev._nonReactive.loadPromise) == null ? void 0 : _b3.resolve();
788
+ prev.beforeLoadPromise?.resolve();
789
+ prev.loadPromise?.resolve();
805
790
  return {
806
791
  ...prev,
807
792
  error: err,
808
793
  status: "error",
809
794
  isFetching: false,
810
795
  updatedAt: Date.now(),
811
- abortController: new AbortController()
796
+ abortController: new AbortController(),
797
+ beforeLoadPromise: void 0
812
798
  };
813
799
  });
814
800
  };
815
801
  for (const [index, { id: matchId, routeId }] of matches.entries()) {
816
802
  const existingMatch = this.getMatch(matchId);
817
- const parentMatchId = (_a = matches[index - 1]) == null ? void 0 : _a.id;
803
+ const parentMatchId = matches[index - 1]?.id;
818
804
  const parentMatch = parentMatchId ? this.getMatch(parentMatchId) : void 0;
819
805
  const route = this.looseRoutesById[routeId];
820
806
  const pendingMs = route.options.pendingMs ?? this.options.defaultPendingMs;
@@ -824,7 +810,7 @@ class RouterCore {
824
810
  ssr = matchId === rootRouteId;
825
811
  } else {
826
812
  const defaultSsr = this.options.defaultSsr ?? true;
827
- if ((parentMatch == null ? void 0 : parentMatch.ssr) === false) {
813
+ if (parentMatch?.ssr === false) {
828
814
  ssr = false;
829
815
  } else {
830
816
  let tempSsr;
@@ -858,39 +844,44 @@ class RouterCore {
858
844
  } else {
859
845
  tempSsr = route.options.ssr;
860
846
  }
861
- if (tempSsr === true && (parentMatch == null ? void 0 : parentMatch.ssr) === "data-only") {
847
+ if (tempSsr === true && parentMatch?.ssr === "data-only") {
862
848
  ssr = "data-only";
863
849
  } else {
864
850
  ssr = tempSsr;
865
851
  }
866
852
  }
867
853
  }
868
- existingMatch.ssr = ssr;
854
+ updateMatch(matchId, (prev) => ({
855
+ ...prev,
856
+ ssr
857
+ }));
869
858
  }
870
859
  if (shouldSkipLoader(matchId)) {
871
860
  continue;
872
861
  }
873
- const shouldPending = !!(onReady && !this.isServer && !resolvePreload(matchId) && (route.options.loader || route.options.beforeLoad || routeNeedsPreload(route)) && typeof pendingMs === "number" && pendingMs !== Infinity && (route.options.pendingComponent ?? ((_b = this.options) == null ? void 0 : _b.defaultPendingComponent)));
862
+ const shouldPending = !!(onReady && !this.isServer && !resolvePreload(matchId) && (route.options.loader || route.options.beforeLoad || routeNeedsPreload(route)) && typeof pendingMs === "number" && pendingMs !== Infinity && (route.options.pendingComponent ?? this.options?.defaultPendingComponent));
874
863
  let executeBeforeLoad = true;
875
864
  const setupPendingTimeout = () => {
876
- const match = this.getMatch(matchId);
877
- if (shouldPending && match._nonReactive.pendingTimeout === void 0) {
865
+ if (shouldPending && this.getMatch(matchId).pendingTimeout === void 0) {
878
866
  const pendingTimeout = setTimeout(() => {
879
867
  try {
880
868
  triggerOnReady();
881
869
  } catch {
882
870
  }
883
871
  }, pendingMs);
884
- match._nonReactive.pendingTimeout = pendingTimeout;
872
+ updateMatch(matchId, (prev) => ({
873
+ ...prev,
874
+ pendingTimeout
875
+ }));
885
876
  }
886
877
  };
887
878
  if (
888
879
  // If we are in the middle of a load, either of these will be present
889
880
  // (not to be confused with `loadPromise`, which is always defined)
890
- existingMatch._nonReactive.beforeLoadPromise || existingMatch._nonReactive.loaderPromise
881
+ existingMatch.beforeLoadPromise || existingMatch.loaderPromise
891
882
  ) {
892
883
  setupPendingTimeout();
893
- await existingMatch._nonReactive.beforeLoadPromise;
884
+ await existingMatch.beforeLoadPromise;
894
885
  const match = this.getMatch(matchId);
895
886
  if (match.status === "error") {
896
887
  executeBeforeLoad = true;
@@ -900,11 +891,15 @@ class RouterCore {
900
891
  }
901
892
  if (executeBeforeLoad) {
902
893
  try {
903
- const match = this.getMatch(matchId);
904
- match._nonReactive.beforeLoadPromise = createControlledPromise();
905
- const prevLoadPromise = match._nonReactive.loadPromise;
906
- match._nonReactive.loadPromise = createControlledPromise(() => {
907
- prevLoadPromise == null ? void 0 : prevLoadPromise.resolve();
894
+ updateMatch(matchId, (prev) => {
895
+ const prevLoadPromise = prev.loadPromise;
896
+ return {
897
+ ...prev,
898
+ loadPromise: createControlledPromise(() => {
899
+ prevLoadPromise?.resolve();
900
+ }),
901
+ beforeLoadPromise: createControlledPromise()
902
+ };
908
903
  });
909
904
  const { paramsError, searchError } = this.getMatch(matchId);
910
905
  if (paramsError) {
@@ -915,7 +910,7 @@ class RouterCore {
915
910
  }
916
911
  setupPendingTimeout();
917
912
  const abortController = new AbortController();
918
- const parentMatchContext = (parentMatch == null ? void 0 : parentMatch.context) ?? this.options.context ?? void 0;
913
+ const parentMatchContext = parentMatch?.context ?? this.options.context ?? {};
919
914
  updateMatch(matchId, (prev) => ({
920
915
  ...prev,
921
916
  isFetching: "beforeLoad",
@@ -940,7 +935,7 @@ class RouterCore {
940
935
  cause: preload ? "preload" : cause,
941
936
  matches
942
937
  };
943
- const beforeLoadContext = await ((_d = (_c = route.options).beforeLoad) == null ? void 0 : _d.call(_c, beforeLoadFnContext));
938
+ const beforeLoadContext = await route.options.beforeLoad?.(beforeLoadFnContext);
944
939
  if (isRedirect(beforeLoadContext) || isNotFound(beforeLoadContext)) {
945
940
  handleSerialError(index, beforeLoadContext, "BEFORE_LOAD");
946
941
  }
@@ -960,11 +955,10 @@ class RouterCore {
960
955
  handleSerialError(index, err, "BEFORE_LOAD");
961
956
  }
962
957
  updateMatch(matchId, (prev) => {
963
- var _a2;
964
- (_a2 = prev._nonReactive.beforeLoadPromise) == null ? void 0 : _a2.resolve();
965
- prev._nonReactive.beforeLoadPromise = void 0;
958
+ prev.beforeLoadPromise?.resolve();
966
959
  return {
967
960
  ...prev,
961
+ beforeLoadPromise: void 0,
968
962
  isFetching: false
969
963
  };
970
964
  });
@@ -975,12 +969,10 @@ class RouterCore {
975
969
  validResolvedMatches.forEach(({ id: matchId, routeId }, index) => {
976
970
  matchPromises.push(
977
971
  (async () => {
978
- var _a2, _b2;
979
972
  let loaderShouldRunAsync = false;
980
973
  let loaderIsRunningAsync = false;
981
974
  const route = this.looseRoutesById[routeId];
982
975
  const executeHead = async () => {
983
- var _a3, _b3, _c2, _d2, _e, _f;
984
976
  const match = this.getMatch(matchId);
985
977
  if (!match) {
986
978
  return;
@@ -991,13 +983,13 @@ class RouterCore {
991
983
  params: match.params,
992
984
  loaderData: match.loaderData
993
985
  };
994
- const headFnContent = await ((_b3 = (_a3 = route.options).head) == null ? void 0 : _b3.call(_a3, assetContext));
995
- const meta = headFnContent == null ? void 0 : headFnContent.meta;
996
- const links = headFnContent == null ? void 0 : headFnContent.links;
997
- const headScripts = headFnContent == null ? void 0 : headFnContent.scripts;
998
- const styles = headFnContent == null ? void 0 : headFnContent.styles;
999
- const scripts = await ((_d2 = (_c2 = route.options).scripts) == null ? void 0 : _d2.call(_c2, assetContext));
1000
- const headers = await ((_f = (_e = route.options).headers) == null ? void 0 : _f.call(_e, assetContext));
986
+ const headFnContent = await route.options.head?.(assetContext);
987
+ const meta = headFnContent?.meta;
988
+ const links = headFnContent?.links;
989
+ const headScripts = headFnContent?.scripts;
990
+ const styles = headFnContent?.styles;
991
+ const scripts = await route.options.scripts?.(assetContext);
992
+ const headers = await route.options.headers?.(assetContext);
1001
993
  return {
1002
994
  meta,
1003
995
  links,
@@ -1009,8 +1001,8 @@ class RouterCore {
1009
1001
  };
1010
1002
  const potentialPendingMinPromise = async () => {
1011
1003
  const latestMatch = this.getMatch(matchId);
1012
- if (latestMatch._nonReactive.minPendingPromise) {
1013
- await latestMatch._nonReactive.minPendingPromise;
1004
+ if (latestMatch.minPendingPromise) {
1005
+ await latestMatch.minPendingPromise;
1014
1006
  }
1015
1007
  };
1016
1008
  const prevMatch = this.getMatch(matchId);
@@ -1023,11 +1015,11 @@ class RouterCore {
1023
1015
  }));
1024
1016
  return this.getMatch(matchId);
1025
1017
  }
1026
- } else if (prevMatch._nonReactive.loaderPromise) {
1018
+ } else if (prevMatch.loaderPromise) {
1027
1019
  if (prevMatch.status === "success" && !sync && !prevMatch.preload) {
1028
1020
  return this.getMatch(matchId);
1029
1021
  }
1030
- await prevMatch._nonReactive.loaderPromise;
1022
+ await prevMatch.loaderPromise;
1031
1023
  const match = this.getMatch(matchId);
1032
1024
  if (match.error) {
1033
1025
  handleRedirectAndNotFound(match, match.error);
@@ -1061,15 +1053,12 @@ class RouterCore {
1061
1053
  const staleAge = preload ? route.options.preloadStaleTime ?? this.options.defaultPreloadStaleTime ?? 3e4 : route.options.staleTime ?? this.options.defaultStaleTime ?? 0;
1062
1054
  const shouldReloadOption = route.options.shouldReload;
1063
1055
  const shouldReload = typeof shouldReloadOption === "function" ? shouldReloadOption(getLoaderContext()) : shouldReloadOption;
1064
- updateMatch(matchId, (prev) => {
1065
- prev._nonReactive.loaderPromise = createControlledPromise();
1066
- return {
1067
- ...prev,
1068
- preload: !!preload && !this.state.matches.some((d) => d.id === matchId)
1069
- };
1070
- });
1056
+ updateMatch(matchId, (prev) => ({
1057
+ ...prev,
1058
+ loaderPromise: createControlledPromise(),
1059
+ preload: !!preload && !this.state.matches.some((d) => d.id === matchId)
1060
+ }));
1071
1061
  const runLoader = async () => {
1072
- var _a3, _b3, _c2, _d2;
1073
1062
  try {
1074
1063
  try {
1075
1064
  if (!this.isServer || this.isServer && this.getMatch(matchId).ssr === true) {
@@ -1079,7 +1068,7 @@ class RouterCore {
1079
1068
  ...prev,
1080
1069
  isFetching: "loader"
1081
1070
  }));
1082
- const loaderData = await ((_b3 = (_a3 = route.options).loader) == null ? void 0 : _b3.call(_a3, getLoaderContext()));
1071
+ const loaderData = await route.options.loader?.(getLoaderContext());
1083
1072
  handleRedirectAndNotFound(
1084
1073
  this.getMatch(matchId),
1085
1074
  loaderData
@@ -1105,7 +1094,7 @@ class RouterCore {
1105
1094
  await potentialPendingMinPromise();
1106
1095
  handleRedirectAndNotFound(this.getMatch(matchId), e);
1107
1096
  try {
1108
- (_d2 = (_c2 = route.options).onError) == null ? void 0 : _d2.call(_c2, e);
1097
+ route.options.onError?.(e);
1109
1098
  } catch (onErrorError) {
1110
1099
  error = onErrorError;
1111
1100
  handleRedirectAndNotFound(
@@ -1124,13 +1113,11 @@ class RouterCore {
1124
1113
  }
1125
1114
  } catch (err) {
1126
1115
  const head = await executeHead();
1127
- updateMatch(matchId, (prev) => {
1128
- prev._nonReactive.loaderPromise = void 0;
1129
- return {
1130
- ...prev,
1131
- ...head
1132
- };
1133
- });
1116
+ updateMatch(matchId, (prev) => ({
1117
+ ...prev,
1118
+ loaderPromise: void 0,
1119
+ ...head
1120
+ }));
1134
1121
  handleRedirectAndNotFound(this.getMatch(matchId), err);
1135
1122
  }
1136
1123
  };
@@ -1140,13 +1127,15 @@ class RouterCore {
1140
1127
  } else if (loaderShouldRunAsync && !sync) {
1141
1128
  loaderIsRunningAsync = true;
1142
1129
  (async () => {
1143
- var _a3, _b3;
1144
1130
  try {
1145
1131
  await runLoader();
1146
- const match = this.getMatch(matchId);
1147
- (_a3 = match._nonReactive.loaderPromise) == null ? void 0 : _a3.resolve();
1148
- (_b3 = match._nonReactive.loadPromise) == null ? void 0 : _b3.resolve();
1149
- match._nonReactive.loaderPromise = void 0;
1132
+ const { loaderPromise, loadPromise } = this.getMatch(matchId);
1133
+ loaderPromise?.resolve();
1134
+ loadPromise?.resolve();
1135
+ updateMatch(matchId, (prev) => ({
1136
+ ...prev,
1137
+ loaderPromise: void 0
1138
+ }));
1150
1139
  } catch (err) {
1151
1140
  if (isRedirect(err)) {
1152
1141
  await this.navigate(err.options);
@@ -1164,20 +1153,19 @@ class RouterCore {
1164
1153
  }
1165
1154
  }
1166
1155
  if (!loaderIsRunningAsync) {
1167
- const match = this.getMatch(matchId);
1168
- (_a2 = match._nonReactive.loaderPromise) == null ? void 0 : _a2.resolve();
1169
- (_b2 = match._nonReactive.loadPromise) == null ? void 0 : _b2.resolve();
1156
+ const { loaderPromise, loadPromise } = this.getMatch(matchId);
1157
+ loaderPromise?.resolve();
1158
+ loadPromise?.resolve();
1170
1159
  }
1171
1160
  updateMatch(matchId, (prev) => {
1172
- clearTimeout(prev._nonReactive.pendingTimeout);
1173
- prev._nonReactive.pendingTimeout = void 0;
1174
- if (!loaderIsRunningAsync)
1175
- prev._nonReactive.loaderPromise = void 0;
1176
- prev._nonReactive.dehydrated = void 0;
1161
+ clearTimeout(prev.pendingTimeout);
1177
1162
  return {
1178
1163
  ...prev,
1179
1164
  isFetching: loaderIsRunningAsync ? prev.isFetching : false,
1180
- invalid: false
1165
+ loaderPromise: loaderIsRunningAsync ? prev.loaderPromise : void 0,
1166
+ invalid: false,
1167
+ pendingTimeout: void 0,
1168
+ _dehydrated: void 0
1181
1169
  };
1182
1170
  });
1183
1171
  return this.getMatch(matchId);
@@ -1204,27 +1192,23 @@ class RouterCore {
1204
1192
  };
1205
1193
  this.invalidate = (opts) => {
1206
1194
  const invalidate = (d) => {
1207
- var _a;
1208
- if (((_a = opts == null ? void 0 : opts.filter) == null ? void 0 : _a.call(opts, d)) ?? true) {
1195
+ if (opts?.filter?.(d) ?? true) {
1209
1196
  return {
1210
1197
  ...d,
1211
1198
  invalid: true,
1212
- ...(opts == null ? void 0 : opts.forcePending) || d.status === "error" ? { status: "pending", error: void 0 } : void 0
1199
+ ...opts?.forcePending || d.status === "error" ? { status: "pending", error: void 0 } : {}
1213
1200
  };
1214
1201
  }
1215
1202
  return d;
1216
1203
  };
1217
- this.__store.setState((s) => {
1218
- var _a;
1219
- return {
1220
- ...s,
1221
- matches: s.matches.map(invalidate),
1222
- cachedMatches: s.cachedMatches.map(invalidate),
1223
- pendingMatches: (_a = s.pendingMatches) == null ? void 0 : _a.map(invalidate)
1224
- };
1225
- });
1204
+ this.__store.setState((s) => ({
1205
+ ...s,
1206
+ matches: s.matches.map(invalidate),
1207
+ cachedMatches: s.cachedMatches.map(invalidate),
1208
+ pendingMatches: s.pendingMatches?.map(invalidate)
1209
+ }));
1226
1210
  this.shouldViewTransition = false;
1227
- return this.load({ sync: opts == null ? void 0 : opts.sync });
1211
+ return this.load({ sync: opts?.sync });
1228
1212
  };
1229
1213
  this.resolveRedirect = (redirect2) => {
1230
1214
  if (!redirect2.options.href) {
@@ -1237,7 +1221,7 @@ class RouterCore {
1237
1221
  return redirect2;
1238
1222
  };
1239
1223
  this.clearCache = (opts) => {
1240
- const filter = opts == null ? void 0 : opts.filter;
1224
+ const filter = opts?.filter;
1241
1225
  if (filter !== void 0) {
1242
1226
  this.__store.setState((s) => {
1243
1227
  return {
@@ -1286,7 +1270,7 @@ class RouterCore {
1286
1270
  () => Promise.all(
1287
1271
  componentTypes.map(async (type) => {
1288
1272
  const component = route.options[type];
1289
- if (component == null ? void 0 : component.preload) {
1273
+ if (component?.preload) {
1290
1274
  await component.preload();
1291
1275
  }
1292
1276
  })
@@ -1362,10 +1346,10 @@ class RouterCore {
1362
1346
  leaveParams: true
1363
1347
  };
1364
1348
  const next = this.buildLocation(matchLocation);
1365
- if ((opts == null ? void 0 : opts.pending) && this.state.status !== "pending") {
1349
+ if (opts?.pending && this.state.status !== "pending") {
1366
1350
  return false;
1367
1351
  }
1368
- const pending = (opts == null ? void 0 : opts.pending) === void 0 ? !this.state.isLoading : opts.pending;
1352
+ const pending = opts?.pending === void 0 ? !this.state.isLoading : opts.pending;
1369
1353
  const baseLocation = pending ? this.latestLocation : this.state.resolvedLocation || this.state.location;
1370
1354
  const match = matchPathname(
1371
1355
  this.basepath,
@@ -1384,7 +1368,7 @@ class RouterCore {
1384
1368
  return false;
1385
1369
  }
1386
1370
  }
1387
- if (match && ((opts == null ? void 0 : opts.includeSearch) ?? true)) {
1371
+ if (match && (opts?.includeSearch ?? true)) {
1388
1372
  return deepEqual(baseLocation.search, next.search, { partial: true }) ? match : false;
1389
1373
  }
1390
1374
  return match;
@@ -1392,13 +1376,12 @@ class RouterCore {
1392
1376
  this._handleNotFound = (matches, err, {
1393
1377
  updateMatch = this.updateMatch
1394
1378
  } = {}) => {
1395
- var _a;
1396
1379
  const routeCursor = this.routesById[err.routeId ?? ""] ?? this.routeTree;
1397
1380
  const matchesByRouteId = {};
1398
1381
  for (const match of matches) {
1399
1382
  matchesByRouteId[match.routeId] = match;
1400
1383
  }
1401
- if (!routeCursor.options.notFoundComponent && ((_a = this.options) == null ? void 0 : _a.defaultNotFoundComponent)) {
1384
+ if (!routeCursor.options.notFoundComponent && this.options?.defaultNotFoundComponent) {
1402
1385
  routeCursor.options.notFoundComponent = this.options.defaultNotFoundComponent;
1403
1386
  }
1404
1387
  invariant(
@@ -1456,10 +1439,9 @@ class RouterCore {
1456
1439
  return this.routesById;
1457
1440
  }
1458
1441
  matchRoutesInternal(next, opts) {
1459
- var _a;
1460
1442
  const { foundRoute, matchedRoutes, routeParams } = this.getMatchedRoutes(
1461
1443
  next.pathname,
1462
- (_a = opts == null ? void 0 : opts.dest) == null ? void 0 : _a.to
1444
+ opts?.dest?.to
1463
1445
  );
1464
1446
  let isGlobalNotFound = false;
1465
1447
  if (
@@ -1490,9 +1472,8 @@ class RouterCore {
1490
1472
  return rootRouteId;
1491
1473
  })();
1492
1474
  const parseErrors = matchedRoutes.map((route) => {
1493
- var _a2;
1494
1475
  let parsedParamsError;
1495
- const parseParams = ((_a2 = route.options.params) == null ? void 0 : _a2.parse) ?? route.options.parseParams;
1476
+ const parseParams = route.options.params?.parse ?? route.options.parseParams;
1496
1477
  if (parseParams) {
1497
1478
  try {
1498
1479
  const parsedParams = parseParams(routeParams);
@@ -1501,7 +1482,7 @@ class RouterCore {
1501
1482
  parsedParamsError = new PathParamError(err.message, {
1502
1483
  cause: err
1503
1484
  });
1504
- if (opts == null ? void 0 : opts.throwOnError) {
1485
+ if (opts?.throwOnError) {
1505
1486
  throw parsedParamsError;
1506
1487
  }
1507
1488
  return parsedParamsError;
@@ -1511,18 +1492,17 @@ class RouterCore {
1511
1492
  });
1512
1493
  const matches = [];
1513
1494
  const getParentContext = (parentMatch) => {
1514
- const parentMatchId = parentMatch == null ? void 0 : parentMatch.id;
1515
- const parentContext = !parentMatchId ? this.options.context ?? void 0 : parentMatch.context ?? this.options.context ?? void 0;
1495
+ const parentMatchId = parentMatch?.id;
1496
+ const parentContext = !parentMatchId ? this.options.context ?? {} : parentMatch.context ?? this.options.context ?? {};
1516
1497
  return parentContext;
1517
1498
  };
1518
1499
  matchedRoutes.forEach((route, index) => {
1519
- var _a2, _b;
1520
1500
  const parentMatch = matches[index - 1];
1521
1501
  const [preMatchSearch, strictMatchSearch, searchError] = (() => {
1522
- const parentSearch = (parentMatch == null ? void 0 : parentMatch.search) ?? next.search;
1523
- const parentStrictSearch = (parentMatch == null ? void 0 : parentMatch._strictSearch) ?? void 0;
1502
+ const parentSearch = parentMatch?.search ?? next.search;
1503
+ const parentStrictSearch = parentMatch?._strictSearch ?? {};
1524
1504
  try {
1525
- const strictSearch = validateSearch(route.options.validateSearch, { ...parentSearch }) ?? void 0;
1505
+ const strictSearch = validateSearch(route.options.validateSearch, { ...parentSearch }) ?? {};
1526
1506
  return [
1527
1507
  {
1528
1508
  ...parentSearch,
@@ -1538,15 +1518,15 @@ class RouterCore {
1538
1518
  cause: err
1539
1519
  });
1540
1520
  }
1541
- if (opts == null ? void 0 : opts.throwOnError) {
1521
+ if (opts?.throwOnError) {
1542
1522
  throw searchParamError;
1543
1523
  }
1544
1524
  return [parentSearch, {}, searchParamError];
1545
1525
  }
1546
1526
  })();
1547
- const loaderDeps = ((_b = (_a2 = route.options).loaderDeps) == null ? void 0 : _b.call(_a2, {
1527
+ const loaderDeps = route.options.loaderDeps?.({
1548
1528
  search: preMatchSearch
1549
- })) ?? "";
1529
+ }) ?? "";
1550
1530
  const loaderDepsHash = loaderDeps ? JSON.stringify(loaderDeps) : "";
1551
1531
  const { usedParams, interpolatedPath } = interpolatePath({
1552
1532
  path: route.fullPath,
@@ -1592,10 +1572,7 @@ class RouterCore {
1592
1572
  isFetching: false,
1593
1573
  error: void 0,
1594
1574
  paramsError: parseErrors[index],
1595
- __routeContext: void 0,
1596
- _nonReactive: {
1597
- loadPromise: createControlledPromise()
1598
- },
1575
+ __routeContext: {},
1599
1576
  __beforeLoadContext: void 0,
1600
1577
  context: {},
1601
1578
  abortController: new AbortController(),
@@ -1609,10 +1586,11 @@ class RouterCore {
1609
1586
  headScripts: void 0,
1610
1587
  meta: void 0,
1611
1588
  staticData: route.options.staticData || {},
1589
+ loadPromise: createControlledPromise(),
1612
1590
  fullPath: route.fullPath
1613
1591
  };
1614
1592
  }
1615
- if (!(opts == null ? void 0 : opts.preload)) {
1593
+ if (!opts?.preload) {
1616
1594
  match.globalNotFound = globalNotFoundRouteId === route.id;
1617
1595
  }
1618
1596
  match.searchError = searchError;
@@ -1627,24 +1605,22 @@ class RouterCore {
1627
1605
  matches.forEach((match, index) => {
1628
1606
  const route = this.looseRoutesById[match.routeId];
1629
1607
  const existingMatch = this.getMatch(match.id);
1630
- if (!existingMatch && (opts == null ? void 0 : opts._buildLocation) !== true) {
1608
+ if (!existingMatch && opts?._buildLocation !== true) {
1631
1609
  const parentMatch = matches[index - 1];
1632
1610
  const parentContext = getParentContext(parentMatch);
1633
- if (route.options.context) {
1634
- const contextFnContext = {
1635
- deps: match.loaderDeps,
1636
- params: match.params,
1637
- context: parentContext ?? {},
1638
- location: next,
1639
- navigate: (opts2) => this.navigate({ ...opts2, _fromLocation: next }),
1640
- buildLocation: this.buildLocation,
1641
- cause: match.cause,
1642
- abortController: match.abortController,
1643
- preload: !!match.preload,
1644
- matches
1645
- };
1646
- match.__routeContext = route.options.context(contextFnContext) ?? void 0;
1647
- }
1611
+ const contextFnContext = {
1612
+ deps: match.loaderDeps,
1613
+ params: match.params,
1614
+ context: parentContext,
1615
+ location: next,
1616
+ navigate: (opts2) => this.navigate({ ...opts2, _fromLocation: next }),
1617
+ buildLocation: this.buildLocation,
1618
+ cause: match.cause,
1619
+ abortController: match.abortController,
1620
+ preload: !!match.preload,
1621
+ matches
1622
+ };
1623
+ match.__routeContext = route.options.context?.(contextFnContext) ?? {};
1648
1624
  match.context = {
1649
1625
  ...parentContext,
1650
1626
  ...match.__routeContext,
@@ -1710,9 +1686,8 @@ const componentTypes = [
1710
1686
  "notFoundComponent"
1711
1687
  ];
1712
1688
  function routeNeedsPreload(route) {
1713
- var _a;
1714
1689
  for (const componentType of componentTypes) {
1715
- if ((_a = route.options[componentType]) == null ? void 0 : _a.preload) {
1690
+ if (route.options[componentType]?.preload) {
1716
1691
  return true;
1717
1692
  }
1718
1693
  }
@@ -1746,7 +1721,7 @@ function processRouteTree({
1746
1721
  const routesByPath = {};
1747
1722
  const recurseRoutes = (childRoutes) => {
1748
1723
  childRoutes.forEach((childRoute, i) => {
1749
- initRoute == null ? void 0 : initRoute(childRoute, i);
1724
+ initRoute?.(childRoute, i);
1750
1725
  const existingRoute = routesById[childRoute.id];
1751
1726
  invariant(
1752
1727
  !existingRoute,
@@ -1760,7 +1735,7 @@ function processRouteTree({
1760
1735
  }
1761
1736
  }
1762
1737
  const children = childRoute.children;
1763
- if (children == null ? void 0 : children.length) {
1738
+ if (children?.length) {
1764
1739
  recurseRoutes(children);
1765
1740
  }
1766
1741
  });
@@ -1769,14 +1744,13 @@ function processRouteTree({
1769
1744
  const scoredRoutes = [];
1770
1745
  const routes = Object.values(routesById);
1771
1746
  routes.forEach((d, i) => {
1772
- var _a;
1773
1747
  if (d.isRoot || !d.path) {
1774
1748
  return;
1775
1749
  }
1776
1750
  const trimmed = trimPathLeft(d.fullPath);
1777
1751
  let parsed = parsePathname(trimmed);
1778
1752
  let skip = 0;
1779
- while (parsed.length > skip + 1 && ((_a = parsed[skip]) == null ? void 0 : _a.value) === "/") {
1753
+ while (parsed.length > skip + 1 && parsed[skip]?.value === "/") {
1780
1754
  skip++;
1781
1755
  }
1782
1756
  if (skip > 0) parsed = parsed.slice(skip);
@@ -1861,13 +1835,12 @@ function getMatchedRoutes({
1861
1835
  let routeParams = {};
1862
1836
  const trimmedPath = trimPathRight(pathname);
1863
1837
  const getMatchedParams = (route) => {
1864
- var _a;
1865
1838
  const result = matchPathname(
1866
1839
  basepath,
1867
1840
  trimmedPath,
1868
1841
  {
1869
1842
  to: route.fullPath,
1870
- caseSensitive: ((_a = route.options) == null ? void 0 : _a.caseSensitive) ?? caseSensitive,
1843
+ caseSensitive: route.options?.caseSensitive ?? caseSensitive,
1871
1844
  // we need fuzzy matching for `notFoundMode: 'fuzzy'`
1872
1845
  fuzzy: true
1873
1846
  },
@@ -1916,10 +1889,9 @@ function applySearchMiddleware({
1916
1889
  }) {
1917
1890
  const allMiddlewares = destRoutes.reduce(
1918
1891
  (acc, route) => {
1919
- var _a;
1920
1892
  const middlewares = [];
1921
1893
  if ("search" in route.options) {
1922
- if ((_a = route.options.search) == null ? void 0 : _a.middlewares) {
1894
+ if (route.options.search?.middlewares) {
1923
1895
  middlewares.push(...route.options.search.middlewares);
1924
1896
  }
1925
1897
  } else if (route.options.preSearchFilters || route.options.postSearchFilters) {
@@ -1951,7 +1923,7 @@ function applySearchMiddleware({
1951
1923
  try {
1952
1924
  const validatedSearch = {
1953
1925
  ...result,
1954
- ...validateSearch(route.options.validateSearch, result) ?? void 0
1926
+ ...validateSearch(route.options.validateSearch, result) ?? {}
1955
1927
  };
1956
1928
  return validatedSearch;
1957
1929
  } catch {