@tanstack/react-router 1.72.1 → 1.73.1

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/react-router",
3
- "version": "1.72.1",
3
+ "version": "1.73.1",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -66,7 +66,7 @@
66
66
  "peerDependencies": {
67
67
  "react": ">=18",
68
68
  "react-dom": ">=18",
69
- "@tanstack/router-generator": "1.69.1"
69
+ "@tanstack/router-generator": "1.73.1"
70
70
  },
71
71
  "peerDependenciesMeta": {
72
72
  "@tanstack/router-generator": {
package/src/router.ts CHANGED
@@ -1791,7 +1791,7 @@ export class Router<
1791
1791
  this.__store.batch(() => {
1792
1792
  // this call breaks a route context of destination route after a redirect
1793
1793
  // we should be fine not eagerly calling this since we call it later
1794
- // this.cleanCache()
1794
+ // this.clearExpiredCache()
1795
1795
 
1796
1796
  // Match the routes
1797
1797
  pendingMatches = this.matchRoutes(next)
@@ -1869,7 +1869,7 @@ export class Router<
1869
1869
  ],
1870
1870
  }
1871
1871
  })
1872
- this.cleanCache()
1872
+ this.clearExpiredCache()
1873
1873
  })
1874
1874
 
1875
1875
  //
@@ -2562,31 +2562,47 @@ export class Router<
2562
2562
  return redirect
2563
2563
  }
2564
2564
 
2565
- cleanCache = () => {
2565
+ clearCache = (opts?: {
2566
+ filter?: (d: MakeRouteMatch<TRouteTree>) => boolean
2567
+ }) => {
2568
+ const filter = opts?.filter
2569
+ if (filter !== undefined) {
2570
+ this.__store.setState((s) => {
2571
+ return {
2572
+ ...s,
2573
+ cachedMatches: s.cachedMatches.filter((m) => !filter(m)),
2574
+ }
2575
+ })
2576
+ } else {
2577
+ this.__store.setState((s) => {
2578
+ return {
2579
+ ...s,
2580
+ cachedMatches: [],
2581
+ }
2582
+ })
2583
+ }
2584
+ }
2585
+
2586
+ clearExpiredCache = () => {
2566
2587
  // This is where all of the garbage collection magic happens
2567
- this.__store.setState((s) => {
2568
- return {
2569
- ...s,
2570
- cachedMatches: s.cachedMatches.filter((d) => {
2571
- const route = this.looseRoutesById[d.routeId]!
2588
+ const filter = (d: MakeRouteMatch<TRouteTree>) => {
2589
+ const route = this.looseRoutesById[d.routeId]!
2572
2590
 
2573
- if (!route.options.loader) {
2574
- return false
2575
- }
2591
+ if (!route.options.loader) {
2592
+ return true
2593
+ }
2576
2594
 
2577
- // If the route was preloaded, use the preloadGcTime
2578
- // otherwise, use the gcTime
2579
- const gcTime =
2580
- (d.preload
2581
- ? (route.options.preloadGcTime ??
2582
- this.options.defaultPreloadGcTime)
2583
- : (route.options.gcTime ?? this.options.defaultGcTime)) ??
2584
- 5 * 60 * 1000
2595
+ // If the route was preloaded, use the preloadGcTime
2596
+ // otherwise, use the gcTime
2597
+ const gcTime =
2598
+ (d.preload
2599
+ ? (route.options.preloadGcTime ?? this.options.defaultPreloadGcTime)
2600
+ : (route.options.gcTime ?? this.options.defaultGcTime)) ??
2601
+ 5 * 60 * 1000
2585
2602
 
2586
- return d.status !== 'error' && Date.now() - d.updatedAt < gcTime
2587
- }),
2588
- }
2589
- })
2603
+ return !(d.status !== 'error' && Date.now() - d.updatedAt < gcTime)
2604
+ }
2605
+ this.clearCache({ filter })
2590
2606
  }
2591
2607
 
2592
2608
  preloadRoute = async <