clear-react-router 2.0.4 → 2.0.5
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 +11 -1
- package/dist/index.js +4 -3
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -639,6 +639,15 @@ This also works for nested dynamic routes:
|
|
|
639
639
|
await invalidate('/post/[id]/comment/[id]');
|
|
640
640
|
```
|
|
641
641
|
|
|
642
|
+
#### Force revalidation
|
|
643
|
+
By default only paths that already exist in the cache are revalidated.
|
|
644
|
+
Pass `{ force: true }` to also revalidate the exact path(s) you passed, even if they were never cached:
|
|
645
|
+
|
|
646
|
+
```tsx
|
|
647
|
+
await invalidate('/about', { force: true });
|
|
648
|
+
await invalidate(['/about', '/post/10'], { force: true });
|
|
649
|
+
```
|
|
650
|
+
|
|
642
651
|
#### Including child routes
|
|
643
652
|
|
|
644
653
|
To revalidate routes together with their cached child routes, pass the `withChildren` option:
|
|
@@ -691,7 +700,8 @@ Each object represents a revalidated route, where `path` is the route pathname,
|
|
|
691
700
|
|
|
692
701
|
#### Notes
|
|
693
702
|
|
|
694
|
-
* **
|
|
703
|
+
* Without `force` option, **only routes that already have cached data** are revalidated.
|
|
704
|
+
* With `force: true`, the exact pathnames you pass are always revalidated (and stored in the cache).
|
|
695
705
|
* Cached data is cleared before the new loader starts.
|
|
696
706
|
* When used as an event handler, wrap the call in an arrow function:
|
|
697
707
|
|
package/dist/index.js
CHANGED
|
@@ -385,9 +385,10 @@ var createInvalidate = ({ routeItemDataState, loaderStateRef, loaderMap, current
|
|
|
385
385
|
const invalidateItem = async (pathname, options) => {
|
|
386
386
|
const routeItem = findRoute(pathname);
|
|
387
387
|
if (!routeItem) return [];
|
|
388
|
-
const
|
|
389
|
-
for (const [key] of loaderMap) if (comparePaths(routeItem, key))
|
|
390
|
-
|
|
388
|
+
const pathnameSet = /* @__PURE__ */ new Set();
|
|
389
|
+
for (const [key] of loaderMap) if (comparePaths(routeItem, key)) pathnameSet.add(key);
|
|
390
|
+
if (options?.force) pathnameSet.add(pathname);
|
|
391
|
+
const currentResults = await Promise.all([...pathnameSet].map((pathname) => invalidatePath(routeItem, pathname, options)));
|
|
391
392
|
if (!options?.withChildren || !routeItem.children?.length) return currentResults;
|
|
392
393
|
const childResults = await Promise.all(routeItem.children.map((child) => invalidateItem(`${pathname}${child.path}`, options)));
|
|
393
394
|
return [...currentResults, ...childResults.flat()];
|
package/dist/types.d.ts
CHANGED
|
@@ -157,6 +157,7 @@ export type RouterType = {
|
|
|
157
157
|
export type InvalidateOptions = {
|
|
158
158
|
withChildren?: boolean;
|
|
159
159
|
withBeforeLoad?: boolean;
|
|
160
|
+
force?: boolean;
|
|
160
161
|
};
|
|
161
162
|
export type RevalidateCache = (args: RevalidateCacheArgs) => LoadingPromise;
|
|
162
163
|
export type Options = Partial<{
|