clear-react-router 2.5.0 → 2.5.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/README.md +6 -3
- package/dist/index.js +6 -2
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -856,7 +856,7 @@ const UserProfile = () => {
|
|
|
856
856
|
|
|
857
857
|
- Use `staleTime: Infinity` when data should stay fresh until it is explicitly invalidated, garbage-collected or evicted.
|
|
858
858
|
|
|
859
|
-
- The cache is bounded by `maxCacheSize` — once the limit is reached, the least recently used entry is evicted to make room for a new one, regardless of whether it's still fresh. This caps memory usage for apps with many high-cardinality dynamic routes (e.g. `/product/:id` across a large catalog). It defaults to a device-aware value (lower on mobile) and can be overridden on the `Router`:
|
|
859
|
+
- The cache is bounded by `maxCacheSize` — once the limit is reached, the least recently used entry is evicted to make room for a new one, regardless of whether it's still fresh. The currently active route's entry is never evicted. This caps memory usage for apps with many high-cardinality dynamic routes (e.g. `/product/:id` across a large catalog). It defaults to a device-aware value (lower on mobile) and can be overridden on the `Router`:
|
|
860
860
|
|
|
861
861
|
```tsx
|
|
862
862
|
<Router routes={routes} maxCacheSize={200} />
|
|
@@ -878,7 +878,8 @@ const CachePanel = () => {
|
|
|
878
878
|
<ul>
|
|
879
879
|
{entries.map(entry => (
|
|
880
880
|
<li key={entry.path}>
|
|
881
|
-
{entry.path} — {entry.reason ?? 'unknown'} —
|
|
881
|
+
{entry.path} — {entry.reason ?? 'unknown'} —{' '}
|
|
882
|
+
{entry.isCached ? (entry.isLoading ? 'revalidating' : 'cached') : 'loading'}
|
|
882
883
|
</li>
|
|
883
884
|
))}
|
|
884
885
|
</ul>
|
|
@@ -899,6 +900,7 @@ type CacheSnapshotEntry = {
|
|
|
899
900
|
reason?: CacheReason; // what wrote the entry last
|
|
900
901
|
gcExpiresAt: number | undefined; // GC deadline, if a GC timer is pending
|
|
901
902
|
gcDuration: number | undefined; // the route's gcTime, for progress display
|
|
903
|
+
isCached: boolean; // a loader result exists in memory (fresh or stale)
|
|
902
904
|
isLoading: boolean; // a loader for this path is currently running
|
|
903
905
|
};
|
|
904
906
|
|
|
@@ -908,7 +910,8 @@ type CacheSnapshot = CacheSnapshotEntry[];
|
|
|
908
910
|
Notes:
|
|
909
911
|
|
|
910
912
|
- The snapshot is a projection, not a second cache — changing it does nothing.
|
|
911
|
-
- Entries appear for in-flight first loads too (`data: undefined`, `isLoading: true`), so a devtool never misses a request.
|
|
913
|
+
- Entries appear for in-flight first loads too (`data: undefined`, `isCached: false`, `isLoading: true`), so a devtool never misses a request.
|
|
914
|
+
- A cached entry being revalidated has `isCached: true` and `isLoading: true`; read `data` to show the previous result while it refreshes.
|
|
912
915
|
- Mounting the hook refreshes the snapshot, so a panel opened after navigation still sees existing entries.
|
|
913
916
|
- `enableCacheSnapshot` is process-wide (the router is a singleton): if several `<Router>`s render with different values, the last rendered one wins. Enable it only when a consumer is actually mounted.
|
|
914
917
|
|
package/dist/index.js
CHANGED
|
@@ -541,11 +541,13 @@ var getRetry = (routeItem) => {
|
|
|
541
541
|
};
|
|
542
542
|
};
|
|
543
543
|
var createRevalidateCache = (routerState, syncCacheSnapshot) => {
|
|
544
|
-
const { loaderMap, loadingPromises, contextState } = routerState;
|
|
544
|
+
const { loaderMap, loadingPromises, contextState, routeDataState } = routerState;
|
|
545
545
|
const flightOwners = /* @__PURE__ */ new Map();
|
|
546
546
|
const evict = () => {
|
|
547
547
|
if (loaderMap.size <= routerConfig.maxCacheSize) return;
|
|
548
|
-
const
|
|
548
|
+
const { pathname, search = "" } = routeDataState.getState().location;
|
|
549
|
+
const currentPath = `${pathname}${search}`;
|
|
550
|
+
const oldestKey = [...loaderMap.keys()].find((key) => key !== currentPath);
|
|
549
551
|
if (oldestKey) {
|
|
550
552
|
loaderMap.delete(oldestKey);
|
|
551
553
|
syncCacheSnapshot();
|
|
@@ -672,6 +674,7 @@ var createCacheSnapshot = (loaderMap, loadingPromises) => {
|
|
|
672
674
|
reason: item.reason,
|
|
673
675
|
gcExpiresAt: item.gcExpiresAt,
|
|
674
676
|
gcDuration: item.gcDuration,
|
|
677
|
+
isCached: true,
|
|
675
678
|
isLoading: loadingPromises.has(path)
|
|
676
679
|
});
|
|
677
680
|
for (const path of loadingPromises.keys()) {
|
|
@@ -683,6 +686,7 @@ var createCacheSnapshot = (loaderMap, loadingPromises) => {
|
|
|
683
686
|
staleTime: routerConfig.defaultStaleTime ?? 0,
|
|
684
687
|
gcExpiresAt: void 0,
|
|
685
688
|
gcDuration: void 0,
|
|
689
|
+
isCached: false,
|
|
686
690
|
isLoading: true
|
|
687
691
|
});
|
|
688
692
|
}
|
package/dist/types.d.ts
CHANGED