@tanstack/react-router 1.36.2 → 1.38.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.
@@ -692,7 +692,6 @@ class Router {
692
692
  redirect = err;
693
693
  if (!this.isServer) {
694
694
  this.navigate({ ...err, replace: true, __isRedirect: true });
695
- this.load();
696
695
  }
697
696
  } else if (isNotFound(err)) {
698
697
  notFound = err;
@@ -763,7 +762,7 @@ class Router {
763
762
  }
764
763
  if (isRedirect(err)) {
765
764
  rendered = true;
766
- err = this.resolveRedirect(err);
765
+ err = this.resolveRedirect({ ...err, _fromLocation: location });
767
766
  throw err;
768
767
  } else if (isNotFound(err)) {
769
768
  this.handleNotFound(matches, err);
@@ -775,7 +774,6 @@ class Router {
775
774
  await new Promise((resolveAll, rejectAll) => {
776
775
  ;
777
776
  (async () => {
778
- var _a, _b;
779
777
  try {
780
778
  for (let [index, match] of matches.entries()) {
781
779
  const parentMatch = matches[index - 1];
@@ -807,7 +805,7 @@ class Router {
807
805
  loadPromise
808
806
  }));
809
807
  const handleSerialError = (err, routerCode) => {
810
- var _a2, _b2;
808
+ var _a, _b;
811
809
  if (err instanceof Promise) {
812
810
  throw err;
813
811
  }
@@ -815,7 +813,7 @@ class Router {
815
813
  firstBadMatchIndex = firstBadMatchIndex ?? index;
816
814
  handleRedirectAndNotFound(match, err);
817
815
  try {
818
- (_b2 = (_a2 = route.options).onError) == null ? void 0 : _b2.call(_a2, err);
816
+ (_b = (_a = route.options).onError) == null ? void 0 : _b.call(_a, err);
819
817
  } catch (errorHandlerErr) {
820
818
  err = errorHandlerErr;
821
819
  handleRedirectAndNotFound(match, err);
@@ -836,25 +834,27 @@ class Router {
836
834
  }
837
835
  try {
838
836
  const parentContext = (parentMatch == null ? void 0 : parentMatch.context) ?? this.options.context ?? {};
839
- matches[index] = match = updateMatch(match.id, () => ({
837
+ matches[index] = match = {
840
838
  ...match,
841
839
  routeContext: replaceEqualDeep(
842
840
  match.routeContext,
843
841
  parentContext
844
842
  ),
843
+ context: replaceEqualDeep(match.context, parentContext),
845
844
  abortController
846
- }));
847
- const beforeLoadContext = await ((_b = (_a = route.options).beforeLoad) == null ? void 0 : _b.call(_a, {
845
+ };
846
+ const beforeLoadFnContext = {
848
847
  search: match.search,
849
848
  abortController,
850
849
  params: match.params,
851
850
  preload: !!preload,
852
- context: parentContext,
851
+ context: match.routeContext,
853
852
  location,
854
853
  navigate: (opts) => this.navigate({ ...opts, _fromLocation: location }),
855
854
  buildLocation: this.buildLocation,
856
855
  cause: preload ? "preload" : match.cause
857
- })) ?? {};
856
+ };
857
+ const beforeLoadContext = route.options.beforeLoad ? await route.options.beforeLoad(beforeLoadFnContext) ?? {} : {};
858
858
  checkLatest();
859
859
  if (isRedirect(beforeLoadContext) || isNotFound(beforeLoadContext)) {
860
860
  handleSerialError(beforeLoadContext, "BEFORE_LOAD");
@@ -897,8 +897,8 @@ class Router {
897
897
  cause: preload ? "preload" : match.cause,
898
898
  route
899
899
  };
900
- const fetch = async () => {
901
- var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
900
+ const fetchAndResolveInLoaderLifetime = async () => {
901
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
902
902
  const existing = getRouteMatch(this.state, match.id);
903
903
  let lazyPromise = Promise.resolve();
904
904
  let componentsPromise = Promise.resolve();
@@ -924,7 +924,7 @@ class Router {
924
924
  fetchCount: match.fetchCount + 1
925
925
  })
926
926
  );
927
- lazyPromise = ((_a2 = route.lazyFn) == null ? void 0 : _a2.call(route).then((lazyRoute) => {
927
+ lazyPromise = ((_a = route.lazyFn) == null ? void 0 : _a.call(route).then((lazyRoute) => {
928
928
  Object.assign(route.options, lazyRoute.options);
929
929
  })) || Promise.resolve();
930
930
  componentsPromise = lazyPromise.then(
@@ -939,7 +939,7 @@ class Router {
939
939
  );
940
940
  await lazyPromise;
941
941
  checkLatest();
942
- loaderPromise = (_c = (_b2 = route.options).loader) == null ? void 0 : _c.call(_b2, loaderContext);
942
+ loaderPromise = (_c = (_b = route.options).loader) == null ? void 0 : _c.call(_b, loaderContext);
943
943
  matches[index] = match = updateMatch(
944
944
  match.id,
945
945
  (prev) => ({
@@ -1004,7 +1004,7 @@ class Router {
1004
1004
  };
1005
1005
  const fetchWithRedirectAndNotFound = async () => {
1006
1006
  try {
1007
- await fetch();
1007
+ await fetchAndResolveInLoaderLifetime();
1008
1008
  } catch (err) {
1009
1009
  checkLatest();
1010
1010
  handleRedirectAndNotFound(match, err);
@@ -1144,7 +1144,8 @@ class Router {
1144
1144
  if ((opts == null ? void 0 : opts.pending) && this.state.status !== "pending") {
1145
1145
  return false;
1146
1146
  }
1147
- const baseLocation = (opts == null ? void 0 : opts.pending) ? this.latestLocation : this.state.resolvedLocation;
1147
+ const pending = (opts == null ? void 0 : opts.pending) === void 0 ? !this.state.isLoading : opts.pending;
1148
+ const baseLocation = pending ? this.latestLocation : this.state.resolvedLocation;
1148
1149
  const match = matchPathname(this.basepath, baseLocation.pathname, {
1149
1150
  ...opts,
1150
1151
  to: next.pathname