@tanstack/react-router 1.92.11 → 1.93.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.
@@ -554,20 +554,24 @@ export declare class Router<in out TRouteTree extends AnyRoute, in out TTrailing
554
554
  buildAndCommitLocation: ({ replace, resetScroll, hashScrollIntoView, viewTransition, ignoreBlocker, href, ...rest }?: BuildNextOptions & CommitLocationOptions) => Promise<void>;
555
555
  navigate: NavigateFn;
556
556
  latestLoadPromise: undefined | Promise<void>;
557
- load: () => Promise<void>;
557
+ load: (opts?: {
558
+ sync?: boolean;
559
+ }) => Promise<void>;
558
560
  startViewTransition: (fn: () => Promise<void>) => void;
559
561
  updateMatch: (id: string, updater: (match: AnyRouteMatch) => AnyRouteMatch) => AnyRouteMatch;
560
562
  getMatch: (matchId: string) => import('./Matches.cjs').RouteMatch<any, any, any, any, any, any, any> | undefined;
561
- loadMatches: ({ location, matches, preload: allPreload, onReady, updateMatch, }: {
563
+ loadMatches: ({ location, matches, preload: allPreload, onReady, updateMatch, sync, }: {
562
564
  location: ParsedLocation;
563
565
  matches: Array<AnyRouteMatch>;
564
566
  preload?: boolean;
565
567
  onReady?: () => Promise<void>;
566
568
  updateMatch?: (id: string, updater: (match: AnyRouteMatch) => AnyRouteMatch) => void;
567
569
  getMatch?: (matchId: string) => AnyRouteMatch | undefined;
570
+ sync?: boolean;
568
571
  }) => Promise<Array<MakeRouteMatch>>;
569
572
  invalidate: <TRouter extends AnyRouter = this>(opts?: {
570
573
  filter?: (d: MakeRouteMatchUnion<TRouter>) => boolean;
574
+ sync?: boolean;
571
575
  }) => Promise<void>;
572
576
  resolveRedirect: (err: AnyRedirect) => ResolvedRedirect;
573
577
  clearCache: <TRouter extends AnyRouter = this>(opts?: {
@@ -554,20 +554,24 @@ export declare class Router<in out TRouteTree extends AnyRoute, in out TTrailing
554
554
  buildAndCommitLocation: ({ replace, resetScroll, hashScrollIntoView, viewTransition, ignoreBlocker, href, ...rest }?: BuildNextOptions & CommitLocationOptions) => Promise<void>;
555
555
  navigate: NavigateFn;
556
556
  latestLoadPromise: undefined | Promise<void>;
557
- load: () => Promise<void>;
557
+ load: (opts?: {
558
+ sync?: boolean;
559
+ }) => Promise<void>;
558
560
  startViewTransition: (fn: () => Promise<void>) => void;
559
561
  updateMatch: (id: string, updater: (match: AnyRouteMatch) => AnyRouteMatch) => AnyRouteMatch;
560
562
  getMatch: (matchId: string) => import('./Matches.js').RouteMatch<any, any, any, any, any, any, any> | undefined;
561
- loadMatches: ({ location, matches, preload: allPreload, onReady, updateMatch, }: {
563
+ loadMatches: ({ location, matches, preload: allPreload, onReady, updateMatch, sync, }: {
562
564
  location: ParsedLocation;
563
565
  matches: Array<AnyRouteMatch>;
564
566
  preload?: boolean;
565
567
  onReady?: () => Promise<void>;
566
568
  updateMatch?: (id: string, updater: (match: AnyRouteMatch) => AnyRouteMatch) => void;
567
569
  getMatch?: (matchId: string) => AnyRouteMatch | undefined;
570
+ sync?: boolean;
568
571
  }) => Promise<Array<MakeRouteMatch>>;
569
572
  invalidate: <TRouter extends AnyRouter = this>(opts?: {
570
573
  filter?: (d: MakeRouteMatchUnion<TRouter>) => boolean;
574
+ sync?: boolean;
571
575
  }) => Promise<void>;
572
576
  resolveRedirect: (err: AnyRedirect) => ResolvedRedirect;
573
577
  clearCache: <TRouter extends AnyRouter = this>(opts?: {
@@ -615,7 +615,7 @@ class Router {
615
615
  to
616
616
  });
617
617
  };
618
- this.load = async () => {
618
+ this.load = async (opts) => {
619
619
  this.latestLocation = this.parseLocation(this.latestLocation);
620
620
  let redirect;
621
621
  let notFound;
@@ -661,6 +661,7 @@ class Router {
661
661
  hrefChanged
662
662
  });
663
663
  await this.loadMatches({
664
+ sync: opts == null ? void 0 : opts.sync,
664
665
  matches: pendingMatches,
665
666
  location: next,
666
667
  // eslint-disable-next-line @typescript-eslint/require-await
@@ -792,7 +793,8 @@ class Router {
792
793
  matches,
793
794
  preload: allPreload,
794
795
  onReady,
795
- updateMatch = this.updateMatch
796
+ updateMatch = this.updateMatch,
797
+ sync
796
798
  }) => {
797
799
  let firstBadMatchIndex;
798
800
  let rendered = false;
@@ -938,8 +940,7 @@ class Router {
938
940
  pendingTimeout,
939
941
  context: {
940
942
  ...getParentMatchContext(),
941
- ...prev.__routeContext,
942
- ...prev.__beforeLoadContext
943
+ ...prev.__routeContext
943
944
  }
944
945
  }));
945
946
  const { search, params, context, cause } = this.getMatch(matchId);
@@ -1002,7 +1003,8 @@ class Router {
1002
1003
  matchPromises.push(
1003
1004
  (async () => {
1004
1005
  const { loaderPromise: prevLoaderPromise } = this.getMatch(matchId);
1005
- let loaderRunningAsync = false;
1006
+ let loaderShouldRunAsync = false;
1007
+ let loaderIsRunningAsync = false;
1006
1008
  if (prevLoaderPromise) {
1007
1009
  await prevLoaderPromise;
1008
1010
  } else {
@@ -1126,30 +1128,39 @@ class Router {
1126
1128
  }
1127
1129
  };
1128
1130
  const { status, invalid } = this.getMatch(matchId);
1129
- loaderRunningAsync = status === "success" && (invalid || (shouldReload ?? age > staleAge));
1131
+ loaderShouldRunAsync = status === "success" && (invalid || (shouldReload ?? age > staleAge));
1130
1132
  if (preload && route.options.preload === false) {
1131
- } else if (loaderRunningAsync) {
1132
- ;
1133
+ } else if (loaderShouldRunAsync && !sync) {
1134
+ loaderIsRunningAsync = true;
1133
1135
  (async () => {
1134
1136
  try {
1135
1137
  await runLoader();
1138
+ const { loaderPromise, loadPromise } = this.getMatch(matchId);
1139
+ loaderPromise == null ? void 0 : loaderPromise.resolve();
1140
+ loadPromise == null ? void 0 : loadPromise.resolve();
1141
+ updateMatch(matchId, (prev) => ({
1142
+ ...prev,
1143
+ loaderPromise: void 0
1144
+ }));
1136
1145
  } catch (err) {
1137
1146
  if (isResolvedRedirect(err)) {
1138
1147
  await this.navigate(err);
1139
1148
  }
1140
1149
  }
1141
1150
  })();
1142
- } else if (status !== "success") {
1151
+ } else if (status !== "success" || loaderShouldRunAsync && sync) {
1143
1152
  await runLoader();
1144
1153
  }
1154
+ }
1155
+ if (!loaderIsRunningAsync) {
1145
1156
  const { loaderPromise, loadPromise } = this.getMatch(matchId);
1146
1157
  loaderPromise == null ? void 0 : loaderPromise.resolve();
1147
1158
  loadPromise == null ? void 0 : loadPromise.resolve();
1148
1159
  }
1149
1160
  updateMatch(matchId, (prev) => ({
1150
1161
  ...prev,
1151
- isFetching: loaderRunningAsync ? prev.isFetching : false,
1152
- loaderPromise: void 0,
1162
+ isFetching: loaderIsRunningAsync ? prev.isFetching : false,
1163
+ loaderPromise: loaderIsRunningAsync ? prev.loaderPromise : void 0,
1153
1164
  invalid: false
1154
1165
  }));
1155
1166
  return this.getMatch(matchId);
@@ -1195,7 +1206,7 @@ class Router {
1195
1206
  pendingMatches: (_a = s.pendingMatches) == null ? void 0 : _a.map(invalidate)
1196
1207
  };
1197
1208
  });
1198
- return this.load();
1209
+ return this.load({ sync: opts == null ? void 0 : opts.sync });
1199
1210
  };
1200
1211
  this.resolveRedirect = (err) => {
1201
1212
  const redirect = err;