@tanstack/router-core 1.131.16 → 1.131.17

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.
@@ -859,10 +859,7 @@ class RouterCore {
859
859
  const match = this.getMatch(matchId);
860
860
  if (shouldPending && match._nonReactive.pendingTimeout === void 0) {
861
861
  const pendingTimeout = setTimeout(() => {
862
- try {
863
- this.triggerOnReady(innerLoadContext);
864
- } catch {
865
- }
862
+ this.triggerOnReady(innerLoadContext);
866
863
  }, pendingMs);
867
864
  match._nonReactive.pendingTimeout = pendingTimeout;
868
865
  }
@@ -885,103 +882,122 @@ class RouterCore {
885
882
  return existingMatch._nonReactive.beforeLoadPromise ? existingMatch._nonReactive.beforeLoadPromise.then(then) : then();
886
883
  };
887
884
  this.executeBeforeLoad = (innerLoadContext, matchId, index, route) => {
888
- var _a, _b, _c;
885
+ var _a;
886
+ const match = this.getMatch(matchId);
887
+ match._nonReactive.beforeLoadPromise = createControlledPromise();
888
+ const prevLoadPromise = match._nonReactive.loadPromise;
889
+ match._nonReactive.loadPromise = createControlledPromise(() => {
890
+ prevLoadPromise == null ? void 0 : prevLoadPromise.resolve();
891
+ });
892
+ const { paramsError, searchError } = match;
893
+ if (paramsError) {
894
+ this.handleSerialError(
895
+ innerLoadContext,
896
+ index,
897
+ paramsError,
898
+ "PARSE_PARAMS"
899
+ );
900
+ }
901
+ if (searchError) {
902
+ this.handleSerialError(
903
+ innerLoadContext,
904
+ index,
905
+ searchError,
906
+ "VALIDATE_SEARCH"
907
+ );
908
+ }
909
+ this.setupPendingTimeout(innerLoadContext, matchId, route);
910
+ const abortController = new AbortController();
911
+ const parentMatchId = (_a = innerLoadContext.matches[index - 1]) == null ? void 0 : _a.id;
912
+ const parentMatch = parentMatchId ? this.getMatch(parentMatchId) : void 0;
913
+ const parentMatchContext = (parentMatch == null ? void 0 : parentMatch.context) ?? this.options.context ?? void 0;
914
+ const context = { ...parentMatchContext, ...match.__routeContext };
915
+ let isPending = false;
916
+ const pending = () => {
917
+ if (isPending) return;
918
+ isPending = true;
919
+ innerLoadContext.updateMatch(matchId, (prev) => ({
920
+ ...prev,
921
+ isFetching: "beforeLoad",
922
+ fetchCount: prev.fetchCount + 1,
923
+ abortController,
924
+ context
925
+ }));
926
+ };
889
927
  const resolve = () => {
890
- innerLoadContext.updateMatch(matchId, (prev) => {
891
- var _a2;
892
- (_a2 = prev._nonReactive.beforeLoadPromise) == null ? void 0 : _a2.resolve();
893
- prev._nonReactive.beforeLoadPromise = void 0;
894
- return {
895
- ...prev,
896
- isFetching: false
897
- };
898
- });
928
+ var _a2;
929
+ (_a2 = match._nonReactive.beforeLoadPromise) == null ? void 0 : _a2.resolve();
930
+ match._nonReactive.beforeLoadPromise = void 0;
931
+ innerLoadContext.updateMatch(matchId, (prev) => ({
932
+ ...prev,
933
+ isFetching: false
934
+ }));
899
935
  };
900
- try {
901
- const match = this.getMatch(matchId);
902
- match._nonReactive.beforeLoadPromise = createControlledPromise();
903
- const prevLoadPromise = match._nonReactive.loadPromise;
904
- match._nonReactive.loadPromise = createControlledPromise(() => {
905
- prevLoadPromise == null ? void 0 : prevLoadPromise.resolve();
936
+ if (!route.options.beforeLoad) {
937
+ batch(() => {
938
+ pending();
939
+ resolve();
906
940
  });
907
- const { paramsError, searchError } = this.getMatch(matchId);
908
- if (paramsError) {
909
- this.handleSerialError(
910
- innerLoadContext,
911
- index,
912
- paramsError,
913
- "PARSE_PARAMS"
914
- );
941
+ return;
942
+ }
943
+ const { search, params, cause } = match;
944
+ const preload = this.resolvePreload(innerLoadContext, matchId);
945
+ const beforeLoadFnContext = {
946
+ search,
947
+ abortController,
948
+ params,
949
+ preload,
950
+ context,
951
+ location: innerLoadContext.location,
952
+ navigate: (opts) => this.navigate({ ...opts, _fromLocation: innerLoadContext.location }),
953
+ buildLocation: this.buildLocation,
954
+ cause: preload ? "preload" : cause,
955
+ matches: innerLoadContext.matches
956
+ };
957
+ const updateContext = (beforeLoadContext2) => {
958
+ if (beforeLoadContext2 === void 0) {
959
+ batch(() => {
960
+ pending();
961
+ resolve();
962
+ });
963
+ return;
915
964
  }
916
- if (searchError) {
965
+ if (isRedirect(beforeLoadContext2) || isNotFound(beforeLoadContext2)) {
966
+ pending();
917
967
  this.handleSerialError(
918
968
  innerLoadContext,
919
969
  index,
920
- searchError,
921
- "VALIDATE_SEARCH"
970
+ beforeLoadContext2,
971
+ "BEFORE_LOAD"
922
972
  );
923
973
  }
924
- this.setupPendingTimeout(innerLoadContext, matchId, route);
925
- const abortController = new AbortController();
926
- const parentMatchId = (_a = innerLoadContext.matches[index - 1]) == null ? void 0 : _a.id;
927
- const parentMatch = parentMatchId ? this.getMatch(parentMatchId) : void 0;
928
- const parentMatchContext = (parentMatch == null ? void 0 : parentMatch.context) ?? this.options.context ?? void 0;
929
- innerLoadContext.updateMatch(matchId, (prev) => ({
930
- ...prev,
931
- isFetching: "beforeLoad",
932
- fetchCount: prev.fetchCount + 1,
933
- abortController,
934
- context: {
935
- ...parentMatchContext,
936
- ...prev.__routeContext
937
- }
938
- }));
939
- const { search, params, context, cause } = this.getMatch(matchId);
940
- const preload = this.resolvePreload(innerLoadContext, matchId);
941
- const beforeLoadFnContext = {
942
- search,
943
- abortController,
944
- params,
945
- preload,
946
- context,
947
- location: innerLoadContext.location,
948
- navigate: (opts) => this.navigate({ ...opts, _fromLocation: innerLoadContext.location }),
949
- buildLocation: this.buildLocation,
950
- cause: preload ? "preload" : cause,
951
- matches: innerLoadContext.matches
952
- };
953
- const updateContext = (beforeLoadContext2) => {
954
- if (isRedirect(beforeLoadContext2) || isNotFound(beforeLoadContext2)) {
955
- this.handleSerialError(
956
- innerLoadContext,
957
- index,
958
- beforeLoadContext2,
959
- "BEFORE_LOAD"
960
- );
961
- }
974
+ batch(() => {
975
+ pending();
962
976
  innerLoadContext.updateMatch(matchId, (prev) => ({
963
977
  ...prev,
964
978
  __beforeLoadContext: beforeLoadContext2,
965
979
  context: {
966
- ...parentMatchContext,
967
- ...prev.__routeContext,
980
+ ...prev.context,
968
981
  ...beforeLoadContext2
969
- },
970
- abortController
982
+ }
971
983
  }));
972
- };
973
- const beforeLoadContext = (_c = (_b = route.options).beforeLoad) == null ? void 0 : _c.call(_b, beforeLoadFnContext);
984
+ resolve();
985
+ });
986
+ };
987
+ let beforeLoadContext;
988
+ try {
989
+ beforeLoadContext = route.options.beforeLoad(beforeLoadFnContext);
974
990
  if (isPromise(beforeLoadContext)) {
975
- return beforeLoadContext.then(updateContext).catch((err) => {
991
+ pending();
992
+ return beforeLoadContext.catch((err) => {
976
993
  this.handleSerialError(innerLoadContext, index, err, "BEFORE_LOAD");
977
- }).then(resolve);
978
- } else {
979
- updateContext(beforeLoadContext);
994
+ }).then(updateContext);
980
995
  }
981
996
  } catch (err) {
997
+ pending();
982
998
  this.handleSerialError(innerLoadContext, index, err, "BEFORE_LOAD");
983
999
  }
984
- resolve();
1000
+ updateContext(beforeLoadContext);
985
1001
  return;
986
1002
  };
987
1003
  this.handleBeforeLoad = (innerLoadContext, index) => {
@@ -1118,7 +1134,8 @@ class RouterCore {
1118
1134
  }));
1119
1135
  } catch (e) {
1120
1136
  let error = e;
1121
- await this.potentialPendingMinPromise(matchId);
1137
+ const pendingPromise = this.potentialPendingMinPromise(matchId);
1138
+ if (pendingPromise) await pendingPromise;
1122
1139
  this.handleRedirectAndNotFound(
1123
1140
  innerLoadContext,
1124
1141
  this.getMatch(matchId),