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