@tanstack/router-core 1.130.2 → 1.130.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/router-core",
3
- "version": "1.130.2",
3
+ "version": "1.130.6",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
package/src/router.ts CHANGED
@@ -661,7 +661,7 @@ export type GetMatchFn = (matchId: string) => AnyRouteMatch | undefined
661
661
  export type UpdateMatchFn = (
662
662
  id: string,
663
663
  updater: (match: AnyRouteMatch) => AnyRouteMatch,
664
- ) => AnyRouteMatch
664
+ ) => void
665
665
 
666
666
  export type LoadRouteChunkFn = (route: AnyRoute) => Promise<Array<void>>
667
667
 
@@ -2052,37 +2052,29 @@ export class RouterCore<
2052
2052
  }
2053
2053
 
2054
2054
  updateMatch: UpdateMatchFn = (id, updater) => {
2055
- let updated!: AnyRouteMatch
2056
- const isPending = this.state.pendingMatches?.find((d) => d.id === id)
2057
- const isMatched = this.state.matches.find((d) => d.id === id)
2058
- const isCached = this.state.cachedMatches.find((d) => d.id === id)
2059
-
2060
- const matchesKey = isPending
2055
+ const matchesKey = this.state.pendingMatches?.some((d) => d.id === id)
2061
2056
  ? 'pendingMatches'
2062
- : isMatched
2057
+ : this.state.matches.some((d) => d.id === id)
2063
2058
  ? 'matches'
2064
- : isCached
2059
+ : this.state.cachedMatches.some((d) => d.id === id)
2065
2060
  ? 'cachedMatches'
2066
2061
  : ''
2067
2062
 
2068
2063
  if (matchesKey) {
2069
2064
  this.__store.setState((s) => ({
2070
2065
  ...s,
2071
- [matchesKey]: s[matchesKey]?.map((d) =>
2072
- d.id === id ? (updated = updater(d)) : d,
2073
- ),
2066
+ [matchesKey]: s[matchesKey]?.map((d) => (d.id === id ? updater(d) : d)),
2074
2067
  }))
2075
2068
  }
2076
-
2077
- return updated
2078
2069
  }
2079
2070
 
2080
2071
  getMatch: GetMatchFn = (matchId: string) => {
2081
- return [
2082
- ...this.state.cachedMatches,
2083
- ...(this.state.pendingMatches ?? []),
2084
- ...this.state.matches,
2085
- ].find((d) => d.id === matchId)
2072
+ const findFn = (d: { id: string }) => d.id === matchId
2073
+ return (
2074
+ this.state.cachedMatches.find(findFn) ??
2075
+ this.state.pendingMatches?.find(findFn) ??
2076
+ this.state.matches.find(findFn)
2077
+ )
2086
2078
  }
2087
2079
 
2088
2080
  loadMatches = async ({
@@ -2867,7 +2859,11 @@ export class RouterCore<
2867
2859
  : (route.options.gcTime ?? this.options.defaultGcTime)) ??
2868
2860
  5 * 60 * 1000
2869
2861
 
2870
- return !(d.status !== 'error' && Date.now() - d.updatedAt < gcTime)
2862
+ const isError = d.status === 'error'
2863
+ if (isError) return true
2864
+
2865
+ const isStale = Date.now() - d.updatedAt >= gcTime
2866
+ return isStale
2871
2867
  }
2872
2868
  this.clearCache({ filter })
2873
2869
  }