@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.
@@ -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.state = {
176
- ...this.state,
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
- this.__store.setState((s) => ({
874
- ...s,
875
- [matchesKey]: s[matchesKey]?.map(
876
- (d) => d.id === id ? updater(d) : d
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
  };