@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.
- package/dist/cjs/router.cjs +38 -28
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +1 -1
- package/dist/esm/router.d.ts +1 -1
- package/dist/esm/router.js +38 -28
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/router.ts +44 -25
package/dist/cjs/router.d.cts
CHANGED
|
@@ -541,7 +541,7 @@ export declare class Router<in out TRouteTree extends AnyRoute, in out TTrailing
|
|
|
541
541
|
startViewTransition: (fn: () => Promise<void>) => void;
|
|
542
542
|
updateMatch: (id: string, updater: (match: AnyRouteMatch) => AnyRouteMatch) => AnyRouteMatch;
|
|
543
543
|
getMatch: (matchId: string) => import('./Matches.cjs').RouteMatch<any, any, any, any, any, any, any> | undefined;
|
|
544
|
-
loadMatches: ({ location, matches, preload, onReady, updateMatch, }: {
|
|
544
|
+
loadMatches: ({ location, matches, preload: allPreload, onReady, updateMatch, }: {
|
|
545
545
|
location: ParsedLocation;
|
|
546
546
|
matches: Array<AnyRouteMatch>;
|
|
547
547
|
preload?: boolean;
|
package/dist/esm/router.d.ts
CHANGED
|
@@ -541,7 +541,7 @@ export declare class Router<in out TRouteTree extends AnyRoute, in out TTrailing
|
|
|
541
541
|
startViewTransition: (fn: () => Promise<void>) => void;
|
|
542
542
|
updateMatch: (id: string, updater: (match: AnyRouteMatch) => AnyRouteMatch) => AnyRouteMatch;
|
|
543
543
|
getMatch: (matchId: string) => import('./Matches.js').RouteMatch<any, any, any, any, any, any, any> | undefined;
|
|
544
|
-
loadMatches: ({ location, matches, preload, onReady, updateMatch, }: {
|
|
544
|
+
loadMatches: ({ location, matches, preload: allPreload, onReady, updateMatch, }: {
|
|
545
545
|
location: ParsedLocation;
|
|
546
546
|
matches: Array<AnyRouteMatch>;
|
|
547
547
|
preload?: boolean;
|
package/dist/esm/router.js
CHANGED
|
@@ -761,16 +761,19 @@ class Router {
|
|
|
761
761
|
let updated;
|
|
762
762
|
const isPending = (_a = this.state.pendingMatches) == null ? void 0 : _a.find((d) => d.id === id);
|
|
763
763
|
const isMatched = this.state.matches.find((d) => d.id === id);
|
|
764
|
-
const
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
764
|
+
const isCached = this.state.cachedMatches.find((d) => d.id === id);
|
|
765
|
+
const matchesKey = isPending ? "pendingMatches" : isMatched ? "matches" : isCached ? "cachedMatches" : "";
|
|
766
|
+
if (matchesKey) {
|
|
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
|
+
});
|
|
776
|
+
}
|
|
774
777
|
return updated;
|
|
775
778
|
};
|
|
776
779
|
this.getMatch = (matchId) => {
|
|
@@ -783,7 +786,7 @@ class Router {
|
|
|
783
786
|
this.loadMatches = async ({
|
|
784
787
|
location,
|
|
785
788
|
matches,
|
|
786
|
-
preload,
|
|
789
|
+
preload: allPreload,
|
|
787
790
|
onReady,
|
|
788
791
|
updateMatch = this.updateMatch
|
|
789
792
|
}) => {
|
|
@@ -795,6 +798,9 @@ class Router {
|
|
|
795
798
|
await (onReady == null ? void 0 : onReady());
|
|
796
799
|
}
|
|
797
800
|
};
|
|
801
|
+
const resolvePreload = (matchId) => {
|
|
802
|
+
return !!(allPreload && !this.state.matches.find((d) => d.id === matchId));
|
|
803
|
+
};
|
|
798
804
|
if (!this.isServer && !this.state.matches.length) {
|
|
799
805
|
triggerOnReady();
|
|
800
806
|
}
|
|
@@ -870,7 +876,7 @@ class Router {
|
|
|
870
876
|
const parentMatchId = (_a = matches[index - 1]) == null ? void 0 : _a.id;
|
|
871
877
|
const route = this.looseRoutesById[routeId];
|
|
872
878
|
const pendingMs = route.options.pendingMs ?? this.options.defaultPendingMs;
|
|
873
|
-
const shouldPending = !!(onReady && !this.isServer && !
|
|
879
|
+
const shouldPending = !!(onReady && !this.isServer && !resolvePreload(matchId) && (route.options.loader || route.options.beforeLoad) && typeof pendingMs === "number" && pendingMs !== Infinity && (route.options.pendingComponent ?? this.options.defaultPendingComponent));
|
|
874
880
|
if (
|
|
875
881
|
// If we are in the middle of a load, either of these will be present
|
|
876
882
|
// (not to be confused with `loadPromise`, which is always defined)
|
|
@@ -926,11 +932,12 @@ class Router {
|
|
|
926
932
|
}
|
|
927
933
|
}));
|
|
928
934
|
const { search, params, context, cause } = this.getMatch(matchId);
|
|
935
|
+
const preload = resolvePreload(matchId);
|
|
929
936
|
const beforeLoadFnContext = {
|
|
930
937
|
search,
|
|
931
938
|
abortController,
|
|
932
939
|
params,
|
|
933
|
-
preload
|
|
940
|
+
preload,
|
|
934
941
|
context,
|
|
935
942
|
location,
|
|
936
943
|
navigate: (opts) => this.navigate({ ...opts, _fromLocation: location }),
|
|
@@ -998,20 +1005,22 @@ class Router {
|
|
|
998
1005
|
context,
|
|
999
1006
|
cause
|
|
1000
1007
|
} = this.getMatch(matchId);
|
|
1008
|
+
const preload2 = resolvePreload(matchId);
|
|
1001
1009
|
return {
|
|
1002
1010
|
params,
|
|
1003
1011
|
deps: loaderDeps,
|
|
1004
|
-
preload: !!
|
|
1012
|
+
preload: !!preload2,
|
|
1005
1013
|
parentMatchPromise,
|
|
1006
1014
|
abortController,
|
|
1007
1015
|
context,
|
|
1008
1016
|
location,
|
|
1009
1017
|
navigate: (opts) => this.navigate({ ...opts, _fromLocation: location }),
|
|
1010
|
-
cause:
|
|
1018
|
+
cause: preload2 ? "preload" : cause,
|
|
1011
1019
|
route
|
|
1012
1020
|
};
|
|
1013
1021
|
};
|
|
1014
1022
|
const age = Date.now() - this.getMatch(matchId).updatedAt;
|
|
1023
|
+
const preload = resolvePreload(matchId);
|
|
1015
1024
|
const staleAge = preload ? route.options.preloadStaleTime ?? this.options.defaultPreloadStaleTime ?? 3e4 : route.options.staleTime ?? this.options.defaultStaleTime ?? 0;
|
|
1016
1025
|
const shouldReloadOption = route.options.shouldReload;
|
|
1017
1026
|
const shouldReload = typeof shouldReloadOption === "function" ? shouldReloadOption(getLoaderContext()) : shouldReloadOption;
|
|
@@ -1080,6 +1089,8 @@ class Router {
|
|
|
1080
1089
|
loaderData
|
|
1081
1090
|
});
|
|
1082
1091
|
const meta = headFnContent == null ? void 0 : headFnContent.meta;
|
|
1092
|
+
const links = headFnContent == null ? void 0 : headFnContent.links;
|
|
1093
|
+
const scripts = headFnContent == null ? void 0 : headFnContent.scripts;
|
|
1083
1094
|
const headers = (_f = (_e = route.options).headers) == null ? void 0 : _f.call(_e, {
|
|
1084
1095
|
loaderData
|
|
1085
1096
|
});
|
|
@@ -1091,6 +1102,8 @@ class Router {
|
|
|
1091
1102
|
updatedAt: Date.now(),
|
|
1092
1103
|
loaderData,
|
|
1093
1104
|
meta,
|
|
1105
|
+
links,
|
|
1106
|
+
scripts,
|
|
1094
1107
|
headers
|
|
1095
1108
|
}));
|
|
1096
1109
|
} catch (e) {
|
|
@@ -1163,7 +1176,7 @@ class Router {
|
|
|
1163
1176
|
await triggerOnReady();
|
|
1164
1177
|
} catch (err) {
|
|
1165
1178
|
if (isRedirect(err) || isNotFound(err)) {
|
|
1166
|
-
if (isNotFound(err) && !
|
|
1179
|
+
if (isNotFound(err) && !allPreload) {
|
|
1167
1180
|
await triggerOnReady();
|
|
1168
1181
|
}
|
|
1169
1182
|
throw err;
|
|
@@ -1239,16 +1252,18 @@ class Router {
|
|
|
1239
1252
|
preload: true,
|
|
1240
1253
|
dest: opts
|
|
1241
1254
|
});
|
|
1242
|
-
const
|
|
1243
|
-
[
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
...this.state.cachedMatches
|
|
1247
|
-
].map((d) => [d.id, true])
|
|
1255
|
+
const activeMatchIds = new Set(
|
|
1256
|
+
[...this.state.matches, ...this.state.pendingMatches ?? []].map(
|
|
1257
|
+
(d) => d.id
|
|
1258
|
+
)
|
|
1248
1259
|
);
|
|
1260
|
+
const loadedMatchIds = /* @__PURE__ */ new Set([
|
|
1261
|
+
...activeMatchIds,
|
|
1262
|
+
...this.state.cachedMatches.map((d) => d.id)
|
|
1263
|
+
]);
|
|
1249
1264
|
this.__store.batch(() => {
|
|
1250
1265
|
matches.forEach((match) => {
|
|
1251
|
-
if (!loadedMatchIds
|
|
1266
|
+
if (!loadedMatchIds.has(match.id)) {
|
|
1252
1267
|
this.__store.setState((s) => ({
|
|
1253
1268
|
...s,
|
|
1254
1269
|
cachedMatches: [...s.cachedMatches, match]
|
|
@@ -1256,11 +1271,6 @@ class Router {
|
|
|
1256
1271
|
}
|
|
1257
1272
|
});
|
|
1258
1273
|
});
|
|
1259
|
-
const activeMatchIds = new Set(
|
|
1260
|
-
[...this.state.matches, ...this.state.pendingMatches ?? []].map(
|
|
1261
|
-
(d) => d.id
|
|
1262
|
-
)
|
|
1263
|
-
);
|
|
1264
1274
|
try {
|
|
1265
1275
|
matches = await this.loadMatches({
|
|
1266
1276
|
matches,
|