@tanstack/router-core 1.161.1 → 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.
@@ -41,6 +41,10 @@ function getLocationChangeInfo(routerState) {
41
41
  const hashChanged = fromLocation?.hash !== toLocation.hash;
42
42
  return { fromLocation, toLocation, pathChanged, hrefChanged, hashChanged };
43
43
  }
44
+ function filterRedirectedCachedMatches(matches) {
45
+ const filtered = matches.filter((d) => d.status !== "redirected");
46
+ return filtered.length === matches.length ? matches : filtered;
47
+ }
44
48
  function createServerStore(initialState) {
45
49
  const store = {
46
50
  state: initialState,
@@ -131,16 +135,7 @@ class RouterCore {
131
135
  getInitialRouterState(this.latestLocation)
132
136
  );
133
137
  } else {
134
- this.__store = new Store(getInitialRouterState(this.latestLocation), {
135
- onUpdate: () => {
136
- this.__store.state = {
137
- ...this.state,
138
- cachedMatches: this.state.cachedMatches.filter(
139
- (d) => !["redirected"].includes(d.status)
140
- )
141
- };
142
- }
143
- });
138
+ this.__store = new Store(getInitialRouterState(this.latestLocation));
144
139
  setupScrollRestoration(this);
145
140
  }
146
141
  }
@@ -170,10 +165,10 @@ class RouterCore {
170
165
  needsLocationUpdate = true;
171
166
  }
172
167
  if (needsLocationUpdate && this.__store) {
173
- this.__store.state = {
174
- ...this.state,
168
+ this.__store.setState((s) => ({
169
+ ...s,
175
170
  location: this.latestLocation
176
- };
171
+ }));
177
172
  }
178
173
  if (typeof window !== "undefined" && "CSS" in window && typeof window.CSS?.supports === "function") {
179
174
  this.isViewTransitionTypesSupported = window.CSS.supports(
@@ -767,7 +762,7 @@ class RouterCore {
767
762
  cachedMatches: [
768
763
  ...s.cachedMatches,
769
764
  ...exitingMatches.filter(
770
- (d) => d.status !== "error" && d.status !== "notFound"
765
+ (d) => d.status !== "error" && d.status !== "notFound" && d.status !== "redirected"
771
766
  )
772
767
  ]
773
768
  };
@@ -868,12 +863,21 @@ class RouterCore {
868
863
  this.startTransition(() => {
869
864
  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" : "";
870
865
  if (matchesKey) {
871
- this.__store.setState((s) => ({
872
- ...s,
873
- [matchesKey]: s[matchesKey]?.map(
874
- (d) => d.id === id ? updater(d) : d
875
- )
876
- }));
866
+ if (matchesKey === "cachedMatches") {
867
+ this.__store.setState((s) => ({
868
+ ...s,
869
+ cachedMatches: filterRedirectedCachedMatches(
870
+ s.cachedMatches.map((d) => d.id === id ? updater(d) : d)
871
+ )
872
+ }));
873
+ } else {
874
+ this.__store.setState((s) => ({
875
+ ...s,
876
+ [matchesKey]: s[matchesKey]?.map(
877
+ (d) => d.id === id ? updater(d) : d
878
+ )
879
+ }));
880
+ }
877
881
  }
878
882
  });
879
883
  };