@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/dist/cjs/router.cjs +29 -15
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +4 -1
- package/dist/esm/router.d.ts +4 -1
- package/dist/esm/router.js +29 -15
- package/dist/esm/router.js.map +1 -1
- package/package.json +2 -2
- package/src/router.ts +39 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-router",
|
|
3
|
-
"version": "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
|
+
"@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.
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
2568
|
-
|
|
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
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2591
|
+
if (!route.options.loader) {
|
|
2592
|
+
return true
|
|
2593
|
+
}
|
|
2576
2594
|
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
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
|
-
|
|
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 <
|