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