clear-react-router 2.3.1 → 2.3.2
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 +1 -1
- package/dist/index.js +28 -14
- package/dist/runtime/revalidateCache.d.ts +1 -1
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -86,7 +86,7 @@ Normalizes route configuration. Extracts dynamic params, builds nested paths.
|
|
|
86
86
|
| `staleTime` | `number \| undefined` | Time in milliseconds before cached loader data is considered stale. Overrides Router.defaultStaleTime. If neither value is provided, cached data never expires |
|
|
87
87
|
| `gcTime` | `number \| undefined` | How long, in milliseconds, an unused cache entry is kept in memory after you navigate away, before it's garbage-collected |
|
|
88
88
|
| `actions` | `({ params, context, searchParams, setContext, location }) => Record<string, (data: Record<string, unknown>) => unknown \| Promise<unknown>>` | Defines route actions for data mutations. |
|
|
89
|
-
| `pollingInterval` | `number \| undefined` | Polling interval (in milliseconds) for automatically revalidating data while the route is active |
|
|
89
|
+
| `pollingInterval` | `number \| undefined` | Polling interval (in milliseconds) for automatically revalidating data while the route is active. Each tick refetches unconditionally, ignoring `staleTime` |
|
|
90
90
|
| `scrollRestoration` | `boolean \| string[] \| undefined` | Restore scroll position when navigating back to this route. `true` restores the window scroll; a string array restores scroll inside specific scrollable elements, matched by their `id` |
|
|
91
91
|
| `scrollRestorationBehavior` | `'auto' \| 'smooth' \| 'instant'` | Scroll restoration behavior |
|
|
92
92
|
|
package/dist/index.js
CHANGED
|
@@ -275,13 +275,15 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
275
275
|
});
|
|
276
276
|
};
|
|
277
277
|
const commitOptimisticState = (routeItem, location, path) => {
|
|
278
|
-
commitNavigation(() => routeItemDataState.setState({
|
|
279
|
-
routeItem,
|
|
280
|
-
location,
|
|
281
|
-
status: "optimistic"
|
|
282
|
-
}));
|
|
283
278
|
const currentLoaderState = loaderMap.get(path)?.state;
|
|
284
|
-
|
|
279
|
+
commitNavigation(() => {
|
|
280
|
+
routeItemDataState.setState({
|
|
281
|
+
routeItem,
|
|
282
|
+
location,
|
|
283
|
+
status: "optimistic"
|
|
284
|
+
});
|
|
285
|
+
if (currentLoaderState) loaderState.setState(currentLoaderState);
|
|
286
|
+
});
|
|
285
287
|
};
|
|
286
288
|
const commitPendingState = (routeItem, location) => {
|
|
287
289
|
commitNavigation(() => routeItemDataState.setState({
|
|
@@ -305,11 +307,22 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
305
307
|
pollingController?.abort();
|
|
306
308
|
pollingController = new AbortController();
|
|
307
309
|
const signal = pollingController.signal;
|
|
308
|
-
interval = window.setInterval(() =>
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
310
|
+
interval = window.setInterval(async () => {
|
|
311
|
+
const result = await revalidateCache({
|
|
312
|
+
routeItem,
|
|
313
|
+
location: nextLocation,
|
|
314
|
+
signal,
|
|
315
|
+
force: true
|
|
316
|
+
});
|
|
317
|
+
if (!result || signal.aborted) return;
|
|
318
|
+
const { location: currentLocation } = routeItemDataState.getState();
|
|
319
|
+
if (`${currentLocation.pathname}${currentLocation.search ?? ""}` !== getPath(nextLocation)) return;
|
|
320
|
+
loaderState.setState({
|
|
321
|
+
data: result.data,
|
|
322
|
+
loaderError: result.error,
|
|
323
|
+
beforeLoadError: null
|
|
324
|
+
});
|
|
325
|
+
}, routeItem.pollingInterval);
|
|
313
326
|
};
|
|
314
327
|
const getLoaderDurationPromise = (routeItem, nextLocation) => {
|
|
315
328
|
const minLoaderDuration = routeItem?.minLoaderDuration ?? routerConfig.defaultMinLoaderDuration ?? 0;
|
|
@@ -490,7 +503,7 @@ var createRevalidateCache = (routerState) => {
|
|
|
490
503
|
}
|
|
491
504
|
return item;
|
|
492
505
|
};
|
|
493
|
-
const revalidateCache = async ({ routeItem, location, signal }, retried = 0) => {
|
|
506
|
+
const revalidateCache = async ({ routeItem, location, signal, force }, retried = 0) => {
|
|
494
507
|
if (!routeItem?.loader) return;
|
|
495
508
|
const isCacheItemFresh = createIsCacheItemFresh(loaderMap);
|
|
496
509
|
const { pathname, search = "" } = location;
|
|
@@ -506,7 +519,7 @@ var createRevalidateCache = (routerState) => {
|
|
|
506
519
|
return loadingPromises.get(path);
|
|
507
520
|
}
|
|
508
521
|
}
|
|
509
|
-
if (isCacheItemFresh(path)) {
|
|
522
|
+
if (!force && isCacheItemFresh(path)) {
|
|
510
523
|
const item = moveItemToLastPosition(path);
|
|
511
524
|
if (!item?.state) return void 0;
|
|
512
525
|
return item.state.loaderError ? {
|
|
@@ -558,7 +571,8 @@ var createRevalidateCache = (routerState) => {
|
|
|
558
571
|
return revalidateCache({
|
|
559
572
|
routeItem,
|
|
560
573
|
location,
|
|
561
|
-
signal
|
|
574
|
+
signal,
|
|
575
|
+
force
|
|
562
576
|
}, retried + 1);
|
|
563
577
|
} else return {
|
|
564
578
|
data: null,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { LoadingPromise, RevalidateCacheArgs, RouterState } from '../types';
|
|
2
|
-
export declare const createRevalidateCache: (routerState: RouterState) => ({ routeItem, location, signal }: RevalidateCacheArgs, retried?: number) => LoadingPromise;
|
|
2
|
+
export declare const createRevalidateCache: (routerState: RouterState) => ({ routeItem, location, signal, force }: RevalidateCacheArgs, retried?: number) => LoadingPromise;
|
package/dist/types.d.ts
CHANGED