@tanstack/router-core 1.125.0 → 1.125.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.
@@ -211,7 +211,13 @@ class RouterCore {
211
211
  const match = this.getMatch(id);
212
212
  if (!match) return;
213
213
  match.abortController.abort();
214
- clearTimeout(match.pendingTimeout);
214
+ this.updateMatch(id, (prev) => {
215
+ clearTimeout(prev.pendingTimeout);
216
+ return {
217
+ ...prev,
218
+ pendingTimeout: void 0
219
+ };
220
+ });
215
221
  };
216
222
  this.cancelMatches = () => {
217
223
  var _a;
@@ -877,19 +883,26 @@ class RouterCore {
877
883
  }
878
884
  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)));
879
885
  let executeBeforeLoad = true;
880
- if (
881
- // If we are in the middle of a load, either of these will be present
882
- // (not to be confused with `loadPromise`, which is always defined)
883
- existingMatch.beforeLoadPromise || existingMatch.loaderPromise
884
- ) {
885
- if (shouldPending) {
886
- setTimeout(() => {
886
+ const setupPendingTimeout = () => {
887
+ if (shouldPending && this.getMatch(matchId).pendingTimeout === void 0) {
888
+ const pendingTimeout = setTimeout(() => {
887
889
  try {
888
890
  triggerOnReady();
889
891
  } catch {
890
892
  }
891
893
  }, pendingMs);
894
+ updateMatch(matchId, (prev) => ({
895
+ ...prev,
896
+ pendingTimeout
897
+ }));
892
898
  }
899
+ };
900
+ if (
901
+ // If we are in the middle of a load, either of these will be present
902
+ // (not to be confused with `loadPromise`, which is always defined)
903
+ existingMatch.beforeLoadPromise || existingMatch.loaderPromise
904
+ ) {
905
+ setupPendingTimeout();
893
906
  await existingMatch.beforeLoadPromise;
894
907
  const match = this.getMatch(matchId);
895
908
  if (match.status === "error") {
@@ -910,16 +923,6 @@ class RouterCore {
910
923
  beforeLoadPromise: createControlledPromise()
911
924
  };
912
925
  });
913
- const abortController = new AbortController();
914
- let pendingTimeout;
915
- if (shouldPending) {
916
- pendingTimeout = setTimeout(() => {
917
- try {
918
- triggerOnReady();
919
- } catch {
920
- }
921
- }, pendingMs);
922
- }
923
926
  const { paramsError, searchError } = this.getMatch(matchId);
924
927
  if (paramsError) {
925
928
  handleSerialError(index, paramsError, "PARSE_PARAMS");
@@ -927,13 +930,14 @@ class RouterCore {
927
930
  if (searchError) {
928
931
  handleSerialError(index, searchError, "VALIDATE_SEARCH");
929
932
  }
933
+ setupPendingTimeout();
934
+ const abortController = new AbortController();
930
935
  const parentMatchContext = (parentMatch == null ? void 0 : parentMatch.context) ?? this.options.context ?? {};
931
936
  updateMatch(matchId, (prev) => ({
932
937
  ...prev,
933
938
  isFetching: "beforeLoad",
934
939
  fetchCount: prev.fetchCount + 1,
935
940
  abortController,
936
- pendingTimeout,
937
941
  context: {
938
942
  ...parentMatchContext,
939
943
  ...prev.__routeContext
@@ -1196,14 +1200,18 @@ class RouterCore {
1196
1200
  loaderPromise == null ? void 0 : loaderPromise.resolve();
1197
1201
  loadPromise == null ? void 0 : loadPromise.resolve();
1198
1202
  }
1199
- updateMatch(matchId, (prev) => ({
1200
- ...prev,
1201
- isFetching: loaderIsRunningAsync ? prev.isFetching : false,
1202
- loaderPromise: loaderIsRunningAsync ? prev.loaderPromise : void 0,
1203
- invalid: false,
1204
- _dehydrated: void 0,
1205
- _forcePending: void 0
1206
- }));
1203
+ updateMatch(matchId, (prev) => {
1204
+ clearTimeout(prev.pendingTimeout);
1205
+ return {
1206
+ ...prev,
1207
+ isFetching: loaderIsRunningAsync ? prev.isFetching : false,
1208
+ loaderPromise: loaderIsRunningAsync ? prev.loaderPromise : void 0,
1209
+ invalid: false,
1210
+ pendingTimeout: void 0,
1211
+ _dehydrated: void 0,
1212
+ _forcePending: void 0
1213
+ };
1214
+ });
1207
1215
  return this.getMatch(matchId);
1208
1216
  })()
1209
1217
  );