@tanstack/react-router 1.86.0 → 1.87.0

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.
@@ -763,16 +763,19 @@ class Router {
763
763
  let updated;
764
764
  const isPending = (_a = this.state.pendingMatches) == null ? void 0 : _a.find((d) => d.id === id);
765
765
  const isMatched = this.state.matches.find((d) => d.id === id);
766
- const matchesKey = isPending ? "pendingMatches" : isMatched ? "matches" : "cachedMatches";
767
- this.__store.setState((s) => {
768
- var _a2;
769
- return {
770
- ...s,
771
- [matchesKey]: (_a2 = s[matchesKey]) == null ? void 0 : _a2.map(
772
- (d) => d.id === id ? updated = updater(d) : d
773
- )
774
- };
775
- });
766
+ const isCached = this.state.cachedMatches.find((d) => d.id === id);
767
+ const matchesKey = isPending ? "pendingMatches" : isMatched ? "matches" : isCached ? "cachedMatches" : "";
768
+ if (matchesKey) {
769
+ this.__store.setState((s) => {
770
+ var _a2;
771
+ return {
772
+ ...s,
773
+ [matchesKey]: (_a2 = s[matchesKey]) == null ? void 0 : _a2.map(
774
+ (d) => d.id === id ? updated = updater(d) : d
775
+ )
776
+ };
777
+ });
778
+ }
776
779
  return updated;
777
780
  };
778
781
  this.getMatch = (matchId) => {
@@ -785,7 +788,7 @@ class Router {
785
788
  this.loadMatches = async ({
786
789
  location,
787
790
  matches,
788
- preload,
791
+ preload: allPreload,
789
792
  onReady,
790
793
  updateMatch = this.updateMatch
791
794
  }) => {
@@ -797,6 +800,9 @@ class Router {
797
800
  await (onReady == null ? void 0 : onReady());
798
801
  }
799
802
  };
803
+ const resolvePreload = (matchId) => {
804
+ return !!(allPreload && !this.state.matches.find((d) => d.id === matchId));
805
+ };
800
806
  if (!this.isServer && !this.state.matches.length) {
801
807
  triggerOnReady();
802
808
  }
@@ -872,7 +878,7 @@ class Router {
872
878
  const parentMatchId = (_a = matches[index - 1]) == null ? void 0 : _a.id;
873
879
  const route = this.looseRoutesById[routeId];
874
880
  const pendingMs = route.options.pendingMs ?? this.options.defaultPendingMs;
875
- const shouldPending = !!(onReady && !this.isServer && !preload && (route.options.loader || route.options.beforeLoad) && typeof pendingMs === "number" && pendingMs !== Infinity && (route.options.pendingComponent ?? this.options.defaultPendingComponent));
881
+ const shouldPending = !!(onReady && !this.isServer && !resolvePreload(matchId) && (route.options.loader || route.options.beforeLoad) && typeof pendingMs === "number" && pendingMs !== Infinity && (route.options.pendingComponent ?? this.options.defaultPendingComponent));
876
882
  if (
877
883
  // If we are in the middle of a load, either of these will be present
878
884
  // (not to be confused with `loadPromise`, which is always defined)
@@ -928,11 +934,12 @@ class Router {
928
934
  }
929
935
  }));
930
936
  const { search, params, context, cause } = this.getMatch(matchId);
937
+ const preload = resolvePreload(matchId);
931
938
  const beforeLoadFnContext = {
932
939
  search,
933
940
  abortController,
934
941
  params,
935
- preload: !!preload,
942
+ preload,
936
943
  context,
937
944
  location,
938
945
  navigate: (opts) => this.navigate({ ...opts, _fromLocation: location }),
@@ -1000,20 +1007,22 @@ class Router {
1000
1007
  context,
1001
1008
  cause
1002
1009
  } = this.getMatch(matchId);
1010
+ const preload2 = resolvePreload(matchId);
1003
1011
  return {
1004
1012
  params,
1005
1013
  deps: loaderDeps,
1006
- preload: !!preload,
1014
+ preload: !!preload2,
1007
1015
  parentMatchPromise,
1008
1016
  abortController,
1009
1017
  context,
1010
1018
  location,
1011
1019
  navigate: (opts) => this.navigate({ ...opts, _fromLocation: location }),
1012
- cause: preload ? "preload" : cause,
1020
+ cause: preload2 ? "preload" : cause,
1013
1021
  route
1014
1022
  };
1015
1023
  };
1016
1024
  const age = Date.now() - this.getMatch(matchId).updatedAt;
1025
+ const preload = resolvePreload(matchId);
1017
1026
  const staleAge = preload ? route.options.preloadStaleTime ?? this.options.defaultPreloadStaleTime ?? 3e4 : route.options.staleTime ?? this.options.defaultStaleTime ?? 0;
1018
1027
  const shouldReloadOption = route.options.shouldReload;
1019
1028
  const shouldReload = typeof shouldReloadOption === "function" ? shouldReloadOption(getLoaderContext()) : shouldReloadOption;
@@ -1082,6 +1091,8 @@ class Router {
1082
1091
  loaderData
1083
1092
  });
1084
1093
  const meta = headFnContent == null ? void 0 : headFnContent.meta;
1094
+ const links = headFnContent == null ? void 0 : headFnContent.links;
1095
+ const scripts = headFnContent == null ? void 0 : headFnContent.scripts;
1085
1096
  const headers = (_f = (_e = route.options).headers) == null ? void 0 : _f.call(_e, {
1086
1097
  loaderData
1087
1098
  });
@@ -1093,6 +1104,8 @@ class Router {
1093
1104
  updatedAt: Date.now(),
1094
1105
  loaderData,
1095
1106
  meta,
1107
+ links,
1108
+ scripts,
1096
1109
  headers
1097
1110
  }));
1098
1111
  } catch (e) {
@@ -1165,7 +1178,7 @@ class Router {
1165
1178
  await triggerOnReady();
1166
1179
  } catch (err) {
1167
1180
  if (redirects.isRedirect(err) || notFound.isNotFound(err)) {
1168
- if (notFound.isNotFound(err) && !preload) {
1181
+ if (notFound.isNotFound(err) && !allPreload) {
1169
1182
  await triggerOnReady();
1170
1183
  }
1171
1184
  throw err;
@@ -1241,16 +1254,18 @@ class Router {
1241
1254
  preload: true,
1242
1255
  dest: opts
1243
1256
  });
1244
- const loadedMatchIds = Object.fromEntries(
1245
- [
1246
- ...this.state.matches,
1247
- ...this.state.pendingMatches ?? [],
1248
- ...this.state.cachedMatches
1249
- ].map((d) => [d.id, true])
1257
+ const activeMatchIds = new Set(
1258
+ [...this.state.matches, ...this.state.pendingMatches ?? []].map(
1259
+ (d) => d.id
1260
+ )
1250
1261
  );
1262
+ const loadedMatchIds = /* @__PURE__ */ new Set([
1263
+ ...activeMatchIds,
1264
+ ...this.state.cachedMatches.map((d) => d.id)
1265
+ ]);
1251
1266
  this.__store.batch(() => {
1252
1267
  matches.forEach((match) => {
1253
- if (!loadedMatchIds[match.id]) {
1268
+ if (!loadedMatchIds.has(match.id)) {
1254
1269
  this.__store.setState((s) => ({
1255
1270
  ...s,
1256
1271
  cachedMatches: [...s.cachedMatches, match]
@@ -1258,11 +1273,6 @@ class Router {
1258
1273
  }
1259
1274
  });
1260
1275
  });
1261
- const activeMatchIds = new Set(
1262
- [...this.state.matches, ...this.state.pendingMatches ?? []].map(
1263
- (d) => d.id
1264
- )
1265
- );
1266
1276
  try {
1267
1277
  matches = await this.loadMatches({
1268
1278
  matches,