@tanstack/react-router 1.92.13 → 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.
@@ -617,7 +617,7 @@ class Router {
617
617
  to
618
618
  });
619
619
  };
620
- this.load = async () => {
620
+ this.load = async (opts) => {
621
621
  this.latestLocation = this.parseLocation(this.latestLocation);
622
622
  let redirect;
623
623
  let notFound$1;
@@ -663,6 +663,7 @@ class Router {
663
663
  hrefChanged
664
664
  });
665
665
  await this.loadMatches({
666
+ sync: opts == null ? void 0 : opts.sync,
666
667
  matches: pendingMatches,
667
668
  location: next,
668
669
  // eslint-disable-next-line @typescript-eslint/require-await
@@ -794,7 +795,8 @@ class Router {
794
795
  matches,
795
796
  preload: allPreload,
796
797
  onReady,
797
- updateMatch = this.updateMatch
798
+ updateMatch = this.updateMatch,
799
+ sync
798
800
  }) => {
799
801
  let firstBadMatchIndex;
800
802
  let rendered = false;
@@ -1003,7 +1005,8 @@ class Router {
1003
1005
  matchPromises.push(
1004
1006
  (async () => {
1005
1007
  const { loaderPromise: prevLoaderPromise } = this.getMatch(matchId);
1006
- let loaderRunningAsync = false;
1008
+ let loaderShouldRunAsync = false;
1009
+ let loaderIsRunningAsync = false;
1007
1010
  if (prevLoaderPromise) {
1008
1011
  await prevLoaderPromise;
1009
1012
  } else {
@@ -1127,30 +1130,39 @@ class Router {
1127
1130
  }
1128
1131
  };
1129
1132
  const { status, invalid } = this.getMatch(matchId);
1130
- loaderRunningAsync = status === "success" && (invalid || (shouldReload ?? age > staleAge));
1133
+ loaderShouldRunAsync = status === "success" && (invalid || (shouldReload ?? age > staleAge));
1131
1134
  if (preload && route.options.preload === false) {
1132
- } else if (loaderRunningAsync) {
1133
- ;
1135
+ } else if (loaderShouldRunAsync && !sync) {
1136
+ loaderIsRunningAsync = true;
1134
1137
  (async () => {
1135
1138
  try {
1136
1139
  await runLoader();
1140
+ const { loaderPromise, loadPromise } = this.getMatch(matchId);
1141
+ loaderPromise == null ? void 0 : loaderPromise.resolve();
1142
+ loadPromise == null ? void 0 : loadPromise.resolve();
1143
+ updateMatch(matchId, (prev) => ({
1144
+ ...prev,
1145
+ loaderPromise: void 0
1146
+ }));
1137
1147
  } catch (err) {
1138
1148
  if (redirects.isResolvedRedirect(err)) {
1139
1149
  await this.navigate(err);
1140
1150
  }
1141
1151
  }
1142
1152
  })();
1143
- } else if (status !== "success") {
1153
+ } else if (status !== "success" || loaderShouldRunAsync && sync) {
1144
1154
  await runLoader();
1145
1155
  }
1156
+ }
1157
+ if (!loaderIsRunningAsync) {
1146
1158
  const { loaderPromise, loadPromise } = this.getMatch(matchId);
1147
1159
  loaderPromise == null ? void 0 : loaderPromise.resolve();
1148
1160
  loadPromise == null ? void 0 : loadPromise.resolve();
1149
1161
  }
1150
1162
  updateMatch(matchId, (prev) => ({
1151
1163
  ...prev,
1152
- isFetching: loaderRunningAsync ? prev.isFetching : false,
1153
- loaderPromise: void 0,
1164
+ isFetching: loaderIsRunningAsync ? prev.isFetching : false,
1165
+ loaderPromise: loaderIsRunningAsync ? prev.loaderPromise : void 0,
1154
1166
  invalid: false
1155
1167
  }));
1156
1168
  return this.getMatch(matchId);
@@ -1196,7 +1208,7 @@ class Router {
1196
1208
  pendingMatches: (_a = s.pendingMatches) == null ? void 0 : _a.map(invalidate)
1197
1209
  };
1198
1210
  });
1199
- return this.load();
1211
+ return this.load({ sync: opts == null ? void 0 : opts.sync });
1200
1212
  };
1201
1213
  this.resolveRedirect = (err) => {
1202
1214
  const redirect = err;