@tanstack/router-core 1.131.3 → 1.131.5

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.
@@ -217,13 +217,8 @@ class RouterCore {
217
217
  const match = this.getMatch(id);
218
218
  if (!match) return;
219
219
  match.abortController.abort();
220
- this.updateMatch(id, (prev) => {
221
- clearTimeout(prev.pendingTimeout);
222
- return {
223
- ...prev,
224
- pendingTimeout: void 0
225
- };
226
- });
220
+ match._nonReactive.pendingTimeout = void 0;
221
+ clearTimeout(match._nonReactive.pendingTimeout);
227
222
  };
228
223
  this.cancelMatches = () => {
229
224
  var _a;
@@ -274,13 +269,9 @@ class RouterCore {
274
269
  params: nextParams ?? {},
275
270
  parseCache: this.parsePathnameCache
276
271
  }).interpolatedPath;
277
- const destRoutes = this.matchRoutes(
278
- interpolatedNextTo,
279
- {},
280
- {
281
- _buildLocation: true
282
- }
283
- ).map((d) => this.looseRoutesById[d.routeId]);
272
+ const destRoutes = this.matchRoutes(interpolatedNextTo, void 0, {
273
+ _buildLocation: true
274
+ }).map((d) => this.looseRoutesById[d.routeId]);
284
275
  if (Object.keys(nextParams).length > 0) {
285
276
  destRoutes.map((route) => {
286
277
  var _a2;
@@ -743,20 +734,20 @@ class RouterCore {
743
734
  }
744
735
  }
745
736
  }
746
- (_a = match.beforeLoadPromise) == null ? void 0 : _a.resolve();
747
- (_b = match.loaderPromise) == null ? void 0 : _b.resolve();
737
+ (_a = match._nonReactive.beforeLoadPromise) == null ? void 0 : _a.resolve();
738
+ (_b = match._nonReactive.loaderPromise) == null ? void 0 : _b.resolve();
739
+ match._nonReactive.beforeLoadPromise = void 0;
740
+ match._nonReactive.loaderPromise = void 0;
748
741
  updateMatch(match.id, (prev) => ({
749
742
  ...prev,
750
743
  status: isRedirect(err) ? "redirected" : isNotFound(err) ? "notFound" : "error",
751
744
  isFetching: false,
752
- error: err,
753
- beforeLoadPromise: void 0,
754
- loaderPromise: void 0
745
+ error: err
755
746
  }));
756
747
  if (!err.routeId) {
757
748
  err.routeId = match.routeId;
758
749
  }
759
- (_c = match.loadPromise) == null ? void 0 : _c.resolve();
750
+ (_c = match._nonReactive.loadPromise) == null ? void 0 : _c.resolve();
760
751
  if (isRedirect(err)) {
761
752
  rendered = true;
762
753
  err.options._fromLocation = location;
@@ -773,7 +764,7 @@ class RouterCore {
773
764
  };
774
765
  const shouldSkipLoader = (matchId) => {
775
766
  const match = this.getMatch(matchId);
776
- if (!this.isServer && match._dehydrated) {
767
+ if (!this.isServer && match._nonReactive.dehydrated) {
777
768
  return true;
778
769
  }
779
770
  if (this.isServer) {
@@ -807,16 +798,16 @@ class RouterCore {
807
798
  }
808
799
  updateMatch(matchId, (prev) => {
809
800
  var _a3, _b3;
810
- (_a3 = prev.beforeLoadPromise) == null ? void 0 : _a3.resolve();
811
- (_b3 = prev.loadPromise) == null ? void 0 : _b3.resolve();
801
+ (_a3 = prev._nonReactive.beforeLoadPromise) == null ? void 0 : _a3.resolve();
802
+ prev._nonReactive.beforeLoadPromise = void 0;
803
+ (_b3 = prev._nonReactive.loadPromise) == null ? void 0 : _b3.resolve();
812
804
  return {
813
805
  ...prev,
814
806
  error: err,
815
807
  status: "error",
816
808
  isFetching: false,
817
809
  updatedAt: Date.now(),
818
- abortController: new AbortController(),
819
- beforeLoadPromise: void 0
810
+ abortController: new AbortController()
820
811
  };
821
812
  });
822
813
  };
@@ -873,10 +864,7 @@ class RouterCore {
873
864
  }
874
865
  }
875
866
  }
876
- updateMatch(matchId, (prev) => ({
877
- ...prev,
878
- ssr
879
- }));
867
+ existingMatch.ssr = ssr;
880
868
  }
881
869
  if (shouldSkipLoader(matchId)) {
882
870
  continue;
@@ -884,26 +872,24 @@ class RouterCore {
884
872
  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)));
885
873
  let executeBeforeLoad = true;
886
874
  const setupPendingTimeout = () => {
887
- if (shouldPending && this.getMatch(matchId).pendingTimeout === void 0) {
875
+ const match = this.getMatch(matchId);
876
+ if (shouldPending && match._nonReactive.pendingTimeout === void 0) {
888
877
  const pendingTimeout = setTimeout(() => {
889
878
  try {
890
879
  triggerOnReady();
891
880
  } catch {
892
881
  }
893
882
  }, pendingMs);
894
- updateMatch(matchId, (prev) => ({
895
- ...prev,
896
- pendingTimeout
897
- }));
883
+ match._nonReactive.pendingTimeout = pendingTimeout;
898
884
  }
899
885
  };
900
886
  if (
901
887
  // If we are in the middle of a load, either of these will be present
902
888
  // (not to be confused with `loadPromise`, which is always defined)
903
- existingMatch.beforeLoadPromise || existingMatch.loaderPromise
889
+ existingMatch._nonReactive.beforeLoadPromise || existingMatch._nonReactive.loaderPromise
904
890
  ) {
905
891
  setupPendingTimeout();
906
- await existingMatch.beforeLoadPromise;
892
+ await existingMatch._nonReactive.beforeLoadPromise;
907
893
  const match = this.getMatch(matchId);
908
894
  if (match.status === "error") {
909
895
  executeBeforeLoad = true;
@@ -913,15 +899,11 @@ class RouterCore {
913
899
  }
914
900
  if (executeBeforeLoad) {
915
901
  try {
916
- updateMatch(matchId, (prev) => {
917
- const prevLoadPromise = prev.loadPromise;
918
- return {
919
- ...prev,
920
- loadPromise: createControlledPromise(() => {
921
- prevLoadPromise == null ? void 0 : prevLoadPromise.resolve();
922
- }),
923
- beforeLoadPromise: createControlledPromise()
924
- };
902
+ const match = this.getMatch(matchId);
903
+ match._nonReactive.beforeLoadPromise = createControlledPromise();
904
+ const prevLoadPromise = match._nonReactive.loadPromise;
905
+ match._nonReactive.loadPromise = createControlledPromise(() => {
906
+ prevLoadPromise == null ? void 0 : prevLoadPromise.resolve();
925
907
  });
926
908
  const { paramsError, searchError } = this.getMatch(matchId);
927
909
  if (paramsError) {
@@ -932,7 +914,7 @@ class RouterCore {
932
914
  }
933
915
  setupPendingTimeout();
934
916
  const abortController = new AbortController();
935
- const parentMatchContext = (parentMatch == null ? void 0 : parentMatch.context) ?? this.options.context ?? {};
917
+ const parentMatchContext = (parentMatch == null ? void 0 : parentMatch.context) ?? this.options.context ?? void 0;
936
918
  updateMatch(matchId, (prev) => ({
937
919
  ...prev,
938
920
  isFetching: "beforeLoad",
@@ -978,10 +960,10 @@ class RouterCore {
978
960
  }
979
961
  updateMatch(matchId, (prev) => {
980
962
  var _a2;
981
- (_a2 = prev.beforeLoadPromise) == null ? void 0 : _a2.resolve();
963
+ (_a2 = prev._nonReactive.beforeLoadPromise) == null ? void 0 : _a2.resolve();
964
+ prev._nonReactive.beforeLoadPromise = void 0;
982
965
  return {
983
966
  ...prev,
984
- beforeLoadPromise: void 0,
985
967
  isFetching: false
986
968
  };
987
969
  });
@@ -992,11 +974,12 @@ class RouterCore {
992
974
  validResolvedMatches.forEach(({ id: matchId, routeId }, index) => {
993
975
  matchPromises.push(
994
976
  (async () => {
977
+ var _a2, _b2;
995
978
  let loaderShouldRunAsync = false;
996
979
  let loaderIsRunningAsync = false;
997
980
  const route = this.looseRoutesById[routeId];
998
981
  const executeHead = async () => {
999
- var _a2, _b2, _c2, _d2, _e, _f;
982
+ var _a3, _b3, _c2, _d2, _e, _f;
1000
983
  const match = this.getMatch(matchId);
1001
984
  if (!match) {
1002
985
  return;
@@ -1007,7 +990,7 @@ class RouterCore {
1007
990
  params: match.params,
1008
991
  loaderData: match.loaderData
1009
992
  };
1010
- const headFnContent = await ((_b2 = (_a2 = route.options).head) == null ? void 0 : _b2.call(_a2, assetContext));
993
+ const headFnContent = await ((_b3 = (_a3 = route.options).head) == null ? void 0 : _b3.call(_a3, assetContext));
1011
994
  const meta = headFnContent == null ? void 0 : headFnContent.meta;
1012
995
  const links = headFnContent == null ? void 0 : headFnContent.links;
1013
996
  const headScripts = headFnContent == null ? void 0 : headFnContent.scripts;
@@ -1025,8 +1008,8 @@ class RouterCore {
1025
1008
  };
1026
1009
  const potentialPendingMinPromise = async () => {
1027
1010
  const latestMatch = this.getMatch(matchId);
1028
- if (latestMatch.minPendingPromise) {
1029
- await latestMatch.minPendingPromise;
1011
+ if (latestMatch._nonReactive.minPendingPromise) {
1012
+ await latestMatch._nonReactive.minPendingPromise;
1030
1013
  }
1031
1014
  };
1032
1015
  const prevMatch = this.getMatch(matchId);
@@ -1039,11 +1022,11 @@ class RouterCore {
1039
1022
  }));
1040
1023
  return this.getMatch(matchId);
1041
1024
  }
1042
- } else if (prevMatch.loaderPromise) {
1025
+ } else if (prevMatch._nonReactive.loaderPromise) {
1043
1026
  if (prevMatch.status === "success" && !sync && !prevMatch.preload) {
1044
1027
  return this.getMatch(matchId);
1045
1028
  }
1046
- await prevMatch.loaderPromise;
1029
+ await prevMatch._nonReactive.loaderPromise;
1047
1030
  const match = this.getMatch(matchId);
1048
1031
  if (match.error) {
1049
1032
  handleRedirectAndNotFound(match, match.error);
@@ -1077,13 +1060,15 @@ class RouterCore {
1077
1060
  const staleAge = preload ? route.options.preloadStaleTime ?? this.options.defaultPreloadStaleTime ?? 3e4 : route.options.staleTime ?? this.options.defaultStaleTime ?? 0;
1078
1061
  const shouldReloadOption = route.options.shouldReload;
1079
1062
  const shouldReload = typeof shouldReloadOption === "function" ? shouldReloadOption(getLoaderContext()) : shouldReloadOption;
1080
- updateMatch(matchId, (prev) => ({
1081
- ...prev,
1082
- loaderPromise: createControlledPromise(),
1083
- preload: !!preload && !this.state.matches.some((d) => d.id === matchId)
1084
- }));
1063
+ updateMatch(matchId, (prev) => {
1064
+ prev._nonReactive.loaderPromise = createControlledPromise();
1065
+ return {
1066
+ ...prev,
1067
+ preload: !!preload && !this.state.matches.some((d) => d.id === matchId)
1068
+ };
1069
+ });
1085
1070
  const runLoader = async () => {
1086
- var _a2, _b2, _c2, _d2;
1071
+ var _a3, _b3, _c2, _d2;
1087
1072
  try {
1088
1073
  try {
1089
1074
  if (!this.isServer || this.isServer && this.getMatch(matchId).ssr === true) {
@@ -1093,7 +1078,7 @@ class RouterCore {
1093
1078
  ...prev,
1094
1079
  isFetching: "loader"
1095
1080
  }));
1096
- const loaderData = await ((_b2 = (_a2 = route.options).loader) == null ? void 0 : _b2.call(_a2, getLoaderContext()));
1081
+ const loaderData = await ((_b3 = (_a3 = route.options).loader) == null ? void 0 : _b3.call(_a3, getLoaderContext()));
1097
1082
  handleRedirectAndNotFound(
1098
1083
  this.getMatch(matchId),
1099
1084
  loaderData
@@ -1138,11 +1123,13 @@ class RouterCore {
1138
1123
  }
1139
1124
  } catch (err) {
1140
1125
  const head = await executeHead();
1141
- updateMatch(matchId, (prev) => ({
1142
- ...prev,
1143
- loaderPromise: void 0,
1144
- ...head
1145
- }));
1126
+ updateMatch(matchId, (prev) => {
1127
+ prev._nonReactive.loaderPromise = void 0;
1128
+ return {
1129
+ ...prev,
1130
+ ...head
1131
+ };
1132
+ });
1146
1133
  handleRedirectAndNotFound(this.getMatch(matchId), err);
1147
1134
  }
1148
1135
  };
@@ -1152,15 +1139,13 @@ class RouterCore {
1152
1139
  } else if (loaderShouldRunAsync && !sync) {
1153
1140
  loaderIsRunningAsync = true;
1154
1141
  (async () => {
1142
+ var _a3, _b3;
1155
1143
  try {
1156
1144
  await runLoader();
1157
- const { loaderPromise, loadPromise } = this.getMatch(matchId);
1158
- loaderPromise == null ? void 0 : loaderPromise.resolve();
1159
- loadPromise == null ? void 0 : loadPromise.resolve();
1160
- updateMatch(matchId, (prev) => ({
1161
- ...prev,
1162
- loaderPromise: void 0
1163
- }));
1145
+ const match = this.getMatch(matchId);
1146
+ (_a3 = match._nonReactive.loaderPromise) == null ? void 0 : _a3.resolve();
1147
+ (_b3 = match._nonReactive.loadPromise) == null ? void 0 : _b3.resolve();
1148
+ match._nonReactive.loaderPromise = void 0;
1164
1149
  } catch (err) {
1165
1150
  if (isRedirect(err)) {
1166
1151
  await this.navigate(err.options);
@@ -1178,19 +1163,20 @@ class RouterCore {
1178
1163
  }
1179
1164
  }
1180
1165
  if (!loaderIsRunningAsync) {
1181
- const { loaderPromise, loadPromise } = this.getMatch(matchId);
1182
- loaderPromise == null ? void 0 : loaderPromise.resolve();
1183
- loadPromise == null ? void 0 : loadPromise.resolve();
1166
+ const match = this.getMatch(matchId);
1167
+ (_a2 = match._nonReactive.loaderPromise) == null ? void 0 : _a2.resolve();
1168
+ (_b2 = match._nonReactive.loadPromise) == null ? void 0 : _b2.resolve();
1184
1169
  }
1185
1170
  updateMatch(matchId, (prev) => {
1186
- clearTimeout(prev.pendingTimeout);
1171
+ clearTimeout(prev._nonReactive.pendingTimeout);
1172
+ prev._nonReactive.pendingTimeout = void 0;
1173
+ if (!loaderIsRunningAsync)
1174
+ prev._nonReactive.loaderPromise = void 0;
1175
+ prev._nonReactive.dehydrated = void 0;
1187
1176
  return {
1188
1177
  ...prev,
1189
1178
  isFetching: loaderIsRunningAsync ? prev.isFetching : false,
1190
- loaderPromise: loaderIsRunningAsync ? prev.loaderPromise : void 0,
1191
- invalid: false,
1192
- pendingTimeout: void 0,
1193
- _dehydrated: void 0
1179
+ invalid: false
1194
1180
  };
1195
1181
  });
1196
1182
  return this.getMatch(matchId);
@@ -1222,7 +1208,7 @@ class RouterCore {
1222
1208
  return {
1223
1209
  ...d,
1224
1210
  invalid: true,
1225
- ...(opts == null ? void 0 : opts.forcePending) || d.status === "error" ? { status: "pending", error: void 0 } : {}
1211
+ ...(opts == null ? void 0 : opts.forcePending) || d.status === "error" ? { status: "pending", error: void 0 } : void 0
1226
1212
  };
1227
1213
  }
1228
1214
  return d;
@@ -1525,7 +1511,7 @@ class RouterCore {
1525
1511
  const matches = [];
1526
1512
  const getParentContext = (parentMatch) => {
1527
1513
  const parentMatchId = parentMatch == null ? void 0 : parentMatch.id;
1528
- const parentContext = !parentMatchId ? this.options.context ?? {} : parentMatch.context ?? this.options.context ?? {};
1514
+ const parentContext = !parentMatchId ? this.options.context ?? void 0 : parentMatch.context ?? this.options.context ?? void 0;
1529
1515
  return parentContext;
1530
1516
  };
1531
1517
  matchedRoutes.forEach((route, index) => {
@@ -1533,9 +1519,9 @@ class RouterCore {
1533
1519
  const parentMatch = matches[index - 1];
1534
1520
  const [preMatchSearch, strictMatchSearch, searchError] = (() => {
1535
1521
  const parentSearch = (parentMatch == null ? void 0 : parentMatch.search) ?? next.search;
1536
- const parentStrictSearch = (parentMatch == null ? void 0 : parentMatch._strictSearch) ?? {};
1522
+ const parentStrictSearch = (parentMatch == null ? void 0 : parentMatch._strictSearch) ?? void 0;
1537
1523
  try {
1538
- const strictSearch = validateSearch(route.options.validateSearch, { ...parentSearch }) ?? {};
1524
+ const strictSearch = validateSearch(route.options.validateSearch, { ...parentSearch }) ?? void 0;
1539
1525
  return [
1540
1526
  {
1541
1527
  ...parentSearch,
@@ -1605,7 +1591,10 @@ class RouterCore {
1605
1591
  isFetching: false,
1606
1592
  error: void 0,
1607
1593
  paramsError: parseErrors[index],
1608
- __routeContext: {},
1594
+ __routeContext: void 0,
1595
+ _nonReactive: {
1596
+ loadPromise: createControlledPromise()
1597
+ },
1609
1598
  __beforeLoadContext: void 0,
1610
1599
  context: {},
1611
1600
  abortController: new AbortController(),
@@ -1619,7 +1608,6 @@ class RouterCore {
1619
1608
  headScripts: void 0,
1620
1609
  meta: void 0,
1621
1610
  staticData: route.options.staticData || {},
1622
- loadPromise: createControlledPromise(),
1623
1611
  fullPath: route.fullPath
1624
1612
  };
1625
1613
  }
@@ -1636,25 +1624,26 @@ class RouterCore {
1636
1624
  matches.push(match);
1637
1625
  });
1638
1626
  matches.forEach((match, index) => {
1639
- var _a2, _b;
1640
1627
  const route = this.looseRoutesById[match.routeId];
1641
1628
  const existingMatch = this.getMatch(match.id);
1642
1629
  if (!existingMatch && (opts == null ? void 0 : opts._buildLocation) !== true) {
1643
1630
  const parentMatch = matches[index - 1];
1644
1631
  const parentContext = getParentContext(parentMatch);
1645
- const contextFnContext = {
1646
- deps: match.loaderDeps,
1647
- params: match.params,
1648
- context: parentContext,
1649
- location: next,
1650
- navigate: (opts2) => this.navigate({ ...opts2, _fromLocation: next }),
1651
- buildLocation: this.buildLocation,
1652
- cause: match.cause,
1653
- abortController: match.abortController,
1654
- preload: !!match.preload,
1655
- matches
1656
- };
1657
- match.__routeContext = ((_b = (_a2 = route.options).context) == null ? void 0 : _b.call(_a2, contextFnContext)) ?? {};
1632
+ if (route.options.context) {
1633
+ const contextFnContext = {
1634
+ deps: match.loaderDeps,
1635
+ params: match.params,
1636
+ context: parentContext ?? {},
1637
+ location: next,
1638
+ navigate: (opts2) => this.navigate({ ...opts2, _fromLocation: next }),
1639
+ buildLocation: this.buildLocation,
1640
+ cause: match.cause,
1641
+ abortController: match.abortController,
1642
+ preload: !!match.preload,
1643
+ matches
1644
+ };
1645
+ match.__routeContext = route.options.context(contextFnContext) ?? void 0;
1646
+ }
1658
1647
  match.context = {
1659
1648
  ...parentContext,
1660
1649
  ...match.__routeContext,
@@ -1961,7 +1950,7 @@ function applySearchMiddleware({
1961
1950
  try {
1962
1951
  const validatedSearch = {
1963
1952
  ...result,
1964
- ...validateSearch(route.options.validateSearch, result) ?? {}
1953
+ ...validateSearch(route.options.validateSearch, result) ?? void 0
1965
1954
  };
1966
1955
  return validatedSearch;
1967
1956
  } catch {