@tanstack/router-core 1.160.0 → 1.161.3
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 +25 -21
- 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 +25 -21
- package/dist/esm/router.js.map +1 -1
- package/package.json +2 -2
- package/src/router.ts +37 -22
package/dist/cjs/router.cjs
CHANGED
|
@@ -43,6 +43,10 @@ function getLocationChangeInfo(routerState) {
|
|
|
43
43
|
const hashChanged = fromLocation?.hash !== toLocation.hash;
|
|
44
44
|
return { fromLocation, toLocation, pathChanged, hrefChanged, hashChanged };
|
|
45
45
|
}
|
|
46
|
+
function filterRedirectedCachedMatches(matches) {
|
|
47
|
+
const filtered = matches.filter((d) => d.status !== "redirected");
|
|
48
|
+
return filtered.length === matches.length ? matches : filtered;
|
|
49
|
+
}
|
|
46
50
|
function createServerStore(initialState) {
|
|
47
51
|
const store2 = {
|
|
48
52
|
state: initialState,
|
|
@@ -133,16 +137,7 @@ class RouterCore {
|
|
|
133
137
|
getInitialRouterState(this.latestLocation)
|
|
134
138
|
);
|
|
135
139
|
} else {
|
|
136
|
-
this.__store = new store.Store(getInitialRouterState(this.latestLocation)
|
|
137
|
-
onUpdate: () => {
|
|
138
|
-
this.__store.state = {
|
|
139
|
-
...this.state,
|
|
140
|
-
cachedMatches: this.state.cachedMatches.filter(
|
|
141
|
-
(d) => !["redirected"].includes(d.status)
|
|
142
|
-
)
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
});
|
|
140
|
+
this.__store = new store.Store(getInitialRouterState(this.latestLocation));
|
|
146
141
|
scrollRestoration.setupScrollRestoration(this);
|
|
147
142
|
}
|
|
148
143
|
}
|
|
@@ -172,10 +167,10 @@ class RouterCore {
|
|
|
172
167
|
needsLocationUpdate = true;
|
|
173
168
|
}
|
|
174
169
|
if (needsLocationUpdate && this.__store) {
|
|
175
|
-
this.__store.
|
|
176
|
-
...
|
|
170
|
+
this.__store.setState((s) => ({
|
|
171
|
+
...s,
|
|
177
172
|
location: this.latestLocation
|
|
178
|
-
};
|
|
173
|
+
}));
|
|
179
174
|
}
|
|
180
175
|
if (typeof window !== "undefined" && "CSS" in window && typeof window.CSS?.supports === "function") {
|
|
181
176
|
this.isViewTransitionTypesSupported = window.CSS.supports(
|
|
@@ -769,7 +764,7 @@ class RouterCore {
|
|
|
769
764
|
cachedMatches: [
|
|
770
765
|
...s.cachedMatches,
|
|
771
766
|
...exitingMatches.filter(
|
|
772
|
-
(d) => d.status !== "error" && d.status !== "notFound"
|
|
767
|
+
(d) => d.status !== "error" && d.status !== "notFound" && d.status !== "redirected"
|
|
773
768
|
)
|
|
774
769
|
]
|
|
775
770
|
};
|
|
@@ -870,12 +865,21 @@ class RouterCore {
|
|
|
870
865
|
this.startTransition(() => {
|
|
871
866
|
const matchesKey = this.state.pendingMatches?.some((d) => d.id === id) ? "pendingMatches" : this.state.matches.some((d) => d.id === id) ? "matches" : this.state.cachedMatches.some((d) => d.id === id) ? "cachedMatches" : "";
|
|
872
867
|
if (matchesKey) {
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
868
|
+
if (matchesKey === "cachedMatches") {
|
|
869
|
+
this.__store.setState((s) => ({
|
|
870
|
+
...s,
|
|
871
|
+
cachedMatches: filterRedirectedCachedMatches(
|
|
872
|
+
s.cachedMatches.map((d) => d.id === id ? updater(d) : d)
|
|
873
|
+
)
|
|
874
|
+
}));
|
|
875
|
+
} else {
|
|
876
|
+
this.__store.setState((s) => ({
|
|
877
|
+
...s,
|
|
878
|
+
[matchesKey]: s[matchesKey]?.map(
|
|
879
|
+
(d) => d.id === id ? updater(d) : d
|
|
880
|
+
)
|
|
881
|
+
}));
|
|
882
|
+
}
|
|
879
883
|
}
|
|
880
884
|
});
|
|
881
885
|
};
|
|
@@ -971,7 +975,7 @@ class RouterCore {
|
|
|
971
975
|
};
|
|
972
976
|
this.loadRouteChunk = loadMatches.loadRouteChunk;
|
|
973
977
|
this.preloadRoute = async (opts) => {
|
|
974
|
-
const next = this.buildLocation(opts);
|
|
978
|
+
const next = opts._builtLocation ?? this.buildLocation(opts);
|
|
975
979
|
let matches = this.matchRoutes(next, {
|
|
976
980
|
throwOnError: true,
|
|
977
981
|
preload: true,
|