clear-react-router 2.0.0 → 2.0.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/index.js CHANGED
@@ -113,8 +113,8 @@ var createCommitNavigation = (navigationExecutor, routeItemDataState) => (nextLo
113
113
  };
114
114
  //#endregion
115
115
  //#region utils/isCacheItemFresh.ts
116
- var createIsCacheItemFresh = (loaderMap) => (pathname, search) => {
117
- const item = loaderMap.get(`${pathname}${search}`);
116
+ var createIsCacheItemFresh = (loaderMap) => (path) => {
117
+ const item = loaderMap.get(path);
118
118
  if (item === void 0) return false;
119
119
  const resolvedStaleTime = item.staleTime ?? routerConfig.defaultStaleTime;
120
120
  if (resolvedStaleTime === void 0) return true;
@@ -272,26 +272,28 @@ var createNavigate = (routerState, revalidateCache) => {
272
272
  [prevPathname]: scrollPosition
273
273
  };
274
274
  });
275
- if (routeItem?.optimistic && loaderMap.has(location.pathname)) {
275
+ const path = `${location.pathname}${location.search}`;
276
+ if (routeItem?.optimistic && loaderMap.has(path)) {
276
277
  routeItemDataState.setState({
277
278
  routeItem,
278
279
  location
279
280
  });
280
- const currentLoaderState = loaderMap.get(location.pathname)?.state;
281
+ const currentLoaderState = loaderMap.get(path)?.state;
281
282
  if (currentLoaderState) loaderStateRef.set(currentLoaderState);
282
283
  } else {
283
- const pendingShouldExist = routeItem?.loader && !isCacheItemFresh(location.pathname, location.search);
284
+ const pendingShouldExist = routeItem?.loader && !isCacheItemFresh(path);
284
285
  pendingState.setState(pendingShouldExist ? {
285
286
  routeItem,
286
287
  location
287
288
  } : void 0);
288
289
  }
289
290
  };
290
- const afterEachLoad = (routeItem, location) => {
291
+ const polling = (routeItem, location) => {
291
292
  if (!routeItem?.pollingInterval) return;
292
293
  interval = window.setInterval(() => revalidateCache({
293
294
  routeItem,
294
- pathname: location.pathname
295
+ pathname: location.pathname,
296
+ search: location.search
295
297
  }), routeItem.pollingInterval);
296
298
  };
297
299
  const loader = async (routeItem, location) => {
@@ -302,7 +304,7 @@ var createNavigate = (routerState, revalidateCache) => {
302
304
  pathname: location.pathname,
303
305
  search: location.search
304
306
  });
305
- afterEachLoad(routeItem, location);
307
+ polling(routeItem, location);
306
308
  };
307
309
  const afterLoad = async (routeItem, params) => {
308
310
  const { defaultAfterLoad } = routerConfig;
@@ -430,9 +432,10 @@ var createRevalidateCache = (routerState) => {
430
432
  if (!routeItem?.loader) return;
431
433
  const isCacheItemFresh = createIsCacheItemFresh(loaderMap);
432
434
  removeFirstStaleItem();
433
- if (loadingPromises.has(pathname)) return loadingPromises.get(`${pathname}${search}`);
434
- if (isCacheItemFresh(pathname, search)) {
435
- const item = loaderMap.get(`${pathname}${search}`);
435
+ const path = `${pathname}${search}`;
436
+ if (loadingPromises.has(path)) return loadingPromises.get(path);
437
+ if (isCacheItemFresh(path)) {
438
+ const item = loaderMap.get(path);
436
439
  if (item?.state) loaderStateRef.set(item.state);
437
440
  return;
438
441
  }
@@ -454,7 +457,7 @@ var createRevalidateCache = (routerState) => {
454
457
  data: result,
455
458
  loaderError: null
456
459
  }));
457
- loaderMap.set(`${pathname}${search}`, {
460
+ loaderMap.set(path, {
458
461
  state: loaderStateRef.value,
459
462
  timestamp: Date.now(),
460
463
  staleTime: routeItem.staleTime
@@ -466,7 +469,7 @@ var createRevalidateCache = (routerState) => {
466
469
  } catch (error) {
467
470
  const retry = getRetry(routeItem);
468
471
  if (retry && retry.count > retried) {
469
- loadingPromises.delete(`${pathname}${search}`);
472
+ loadingPromises.delete(path);
470
473
  if (retry.delay) await sleep(retry.delay);
471
474
  await revalidateCache({
472
475
  routeItem,
@@ -489,10 +492,10 @@ var createRevalidateCache = (routerState) => {
489
492
  };
490
493
  }
491
494
  } finally {
492
- loadingPromises.delete(`${pathname}${search}`);
495
+ loadingPromises.delete(path);
493
496
  }
494
497
  })();
495
- loadingPromises.set(`${pathname}${search}`, promise);
498
+ loadingPromises.set(path, promise);
496
499
  return promise;
497
500
  };
498
501
  return revalidateCache;
package/dist/types.d.ts CHANGED
@@ -147,7 +147,7 @@ export type InvalidateOptions = {
147
147
  withChildren?: boolean;
148
148
  withBeforeLoad?: boolean;
149
149
  };
150
- export type RevalidateCache = ({ routeItem, pathname, }: RevalidateCacheArgs) => Promise<{
150
+ export type RevalidateCache = (args: RevalidateCacheArgs) => Promise<{
151
151
  data: unknown;
152
152
  error: unknown;
153
153
  }>;
@@ -1,2 +1,2 @@
1
1
  import { LoaderStateItem } from '../types';
2
- export declare const createIsCacheItemFresh: (loaderMap: Map<string, LoaderStateItem>) => (pathname: string, search?: string) => boolean;
2
+ export declare const createIsCacheItemFresh: (loaderMap: Map<string, LoaderStateItem>) => (path: string) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clear-react-router",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "A lightweight, type-safe routing library for React applications",
5
5
  "author": "Andrew Bubnov",
6
6
  "scripts": {