clear-react-router 2.1.9 → 2.2.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 +48 -9
- package/dist/components/Link.d.ts +2 -2
- package/dist/hooks/useNavigate.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +83 -48
- package/dist/types.d.ts +7 -3
- package/dist/utils/commitState.d.ts +8 -2
- package/dist/utils/utils.d.ts +2 -1
- package/package.json +1 -1
- package/dist/cell.d.ts +0 -6
package/README.md
CHANGED
|
@@ -81,6 +81,7 @@ Normalizes route configuration. Extracts dynamic params, builds nested paths.
|
|
|
81
81
|
| `optimistic` | `boolean \| undefined` | Instant navigation using stale data while fresh data is loaded in the background |
|
|
82
82
|
| `errorElement` | `ReactElement \| () => ReactElement` | Error fallback for the route. Overrides the global `defaultErrorElement` set in `Router` |
|
|
83
83
|
| `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 |
|
|
84
|
+
| `gcTime` | `number \| undefined` | How long, in milliseconds, an unused cache entry is kept in memory after you navigate away, before it's garbage-collected |
|
|
84
85
|
| `actions` | `({ params, context, invalidate, setContext }) => Record<string, (formData: FormData) => unknown \| Promise<unknown>>` | Defines route actions for data mutations. Actions receive `FormData`, can update context via `setContext`, and can invalidate cached loader data using the router-provided `invalidate` |
|
|
85
86
|
| `pollingInterval` | `number \| undefined` | Polling interval (in milliseconds) for automatically revalidating data while the route is active |
|
|
86
87
|
| `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` |
|
|
@@ -110,9 +111,11 @@ Before load arguments (see [`redirect`](#redirect) for details on programmatic r
|
|
|
110
111
|
`loader` additionally receives:
|
|
111
112
|
```ts
|
|
112
113
|
{
|
|
113
|
-
signal: AbortSignal;
|
|
114
|
+
signal: AbortSignal; // Aborted if a newer navigation supersedes this one — pass to fetch() to cancel in-flight requests
|
|
114
115
|
}
|
|
115
116
|
```
|
|
117
|
+
> **Note:** `gcTime` is independent from `staleTime` — `staleTime` controls when cached data is considered outdated (and needs a refetch), while `gcTime` controls how long the cache entry stays in memory at all once you leave that route. Data can be fresh and still get garbage-collected, or stale and still linger in memory, depending on which you set. The timer starts only when you navigate away from the route and is cancelled if you come back before it fires — it isn't affected by prefetching. This is mainly useful for routes with heavy or fast-changing data (large tables, dashboards with charts) that you don't want lingering in memory indefinitely, even when `maxCacheSize` hasn't been reached yet.
|
|
118
|
+
If a route is both `optimistic` and has `gcTime` set, keep in mind the cached snapshot can disappear while you're relying on it for an instant render — combine the two deliberately, not by default.
|
|
116
119
|
|
|
117
120
|
### `Link`
|
|
118
121
|
|
|
@@ -121,7 +124,7 @@ Component for client-side navigation with prefetch support, active state detecti
|
|
|
121
124
|
| Prop | Type | Default | Description |
|
|
122
125
|
|------|------|---------|-------------|
|
|
123
126
|
| `to` | `string` | required | Target path |
|
|
124
|
-
| `search` | `string \| undefined` | `undefined` | Query string appended to the target path |
|
|
127
|
+
| `search` | `string \| Record<string, string \| number \| boolean \| null \| undefined> \| undefined` | `undefined` | Query string or object appended to the target path |
|
|
125
128
|
| `state` | `unknown` | `undefined` | Arbitrary value attached to the navigation entry |
|
|
126
129
|
| `as` | `(props: ElementProps<T>, state: { isActive: boolean; isPending: boolean }) => ReactElement` | renders `<a>` | Render function for using a custom element/component instead of the default <a>. Receives the props to spread onto your element (href, ref, event handlers, className, style, children) as the first argument, and `{ isActive, isPending }` as a separate second argument — kept separate so these values are never accidentally forwarded to the DOM |
|
|
127
130
|
| `exact` | `boolean` | `false` | When `false`, the link is also considered active if the current URL starts with `to` (useful for nested routes) |
|
|
@@ -235,8 +238,8 @@ import { Button } from '@mui/material';
|
|
|
235
238
|
Dashboard
|
|
236
239
|
</Link>
|
|
237
240
|
|
|
238
|
-
// With dynamic style
|
|
239
|
-
<Link to=
|
|
241
|
+
// With dynamic style and search object
|
|
242
|
+
<Link to={{ pathname: '/profile', search: { user: 'John Doe' } }} style={({ isActive }) => ({ fontWeight: isActive ? 'bold' : 'normal' })}>
|
|
240
243
|
Profile
|
|
241
244
|
</Link>
|
|
242
245
|
|
|
@@ -538,16 +541,16 @@ const App = () => <Router routes={routes} errorBoundary={ErrorBoundary} />
|
|
|
538
541
|
|
|
539
542
|
### `useNavigate()`
|
|
540
543
|
|
|
541
|
-
Returns function to navigate programmatically. Accepts a string (pathname
|
|
544
|
+
Returns a function to navigate programmatically. Accepts a string (pathname, optionally with a `?query`), a `NavigationLocation` object, or `-1` to go back.
|
|
542
545
|
|
|
543
546
|
```tsx
|
|
544
|
-
type
|
|
547
|
+
type NavigationLocation = { pathname: string; search?: string | Record<string, string | number | boolean | null | undefined>; state?: unknown }
|
|
545
548
|
|
|
546
549
|
const navigate = useNavigate();
|
|
547
550
|
|
|
548
|
-
navigate('/about');
|
|
549
|
-
navigate({ pathname: '/user/123', state: { from: 'home' } });
|
|
550
|
-
navigate(-1);
|
|
551
|
+
navigate('/about'); // string
|
|
552
|
+
navigate({ pathname: '/user/123', search: { user: 'Jane Doe' }, state: { from: 'home' } }); // NavigationLocation
|
|
553
|
+
navigate(-1); // go back
|
|
551
554
|
```
|
|
552
555
|
|
|
553
556
|
**Note:** Navigation state can be accessed via `useLocation()`:
|
|
@@ -870,6 +873,42 @@ import { lazy } from 'clear-react-router';
|
|
|
870
873
|
fallback: () => <div>Loading...</div>,
|
|
871
874
|
}
|
|
872
875
|
```
|
|
876
|
+
|
|
877
|
+
## Deferred data (React 19 `use()`)
|
|
878
|
+
|
|
879
|
+
`loader` can return a value containing unresolved promises — the router doesn't await
|
|
880
|
+
anything beyond what your `loader` itself awaits. This lets you unblock navigation on
|
|
881
|
+
fast data while slow data streams in separately:
|
|
882
|
+
|
|
883
|
+
```tsx
|
|
884
|
+
{
|
|
885
|
+
path: '/about',
|
|
886
|
+
loader: async () => {
|
|
887
|
+
const fast = await fetchFast();
|
|
888
|
+
const slow = fetchSlow(); // not awaited — passed through as a promise
|
|
889
|
+
return { fast, slow };
|
|
890
|
+
},
|
|
891
|
+
}
|
|
892
|
+
```
|
|
893
|
+
|
|
894
|
+
```tsx
|
|
895
|
+
const Slow = () => {
|
|
896
|
+
const { data } = useLoaderState<{ slow: Promise<string> }>();
|
|
897
|
+
return use(data.slow);
|
|
898
|
+
};
|
|
899
|
+
|
|
900
|
+
const About = () => (
|
|
901
|
+
<Suspense fallback={<Skeleton />}>
|
|
902
|
+
<Slow />
|
|
903
|
+
</Suspense>
|
|
904
|
+
);
|
|
905
|
+
```
|
|
906
|
+
|
|
907
|
+
> Wrap deferred parts in their own `ErrorBoundary` — a rejected promise passed to `use()`
|
|
908
|
+
> is not caught by the route's `errorElement`. Also set `staleTime` generously enough to
|
|
909
|
+
> outlast your slowest deferred request, or a fast repeat visit may trigger a redundant
|
|
910
|
+
> refetch while the previous one is still resolving.
|
|
911
|
+
|
|
873
912
|
## Animations
|
|
874
913
|
|
|
875
914
|
Clear Router supports smooth page transitions using the native View Transitions API. When animations are enabled, the router waits for all data to load before starting the transition, ensuring a jank-free experience.
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { type CSSProperties, ReactNode, ReactElement } from 'react';
|
|
2
|
-
import { ElementProps, RouterProps } from '../types';
|
|
2
|
+
import { ElementProps, RouterProps, SearchObject } from '../types';
|
|
3
3
|
type ElementState = {
|
|
4
4
|
isActive: boolean;
|
|
5
5
|
isPending: boolean;
|
|
6
6
|
};
|
|
7
7
|
type LinkProps<T extends HTMLElement = HTMLAnchorElement> = {
|
|
8
8
|
to: string;
|
|
9
|
-
search?: string;
|
|
9
|
+
search?: string | SearchObject;
|
|
10
10
|
state?: unknown;
|
|
11
11
|
children?: ReactNode;
|
|
12
12
|
as?: (props: ElementProps<T>, state: ElementState) => ReactElement;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useNavigate: () => (arg: import("..").
|
|
1
|
+
export declare const useNavigate: () => (arg: import("..").NavigationLocation | string | -1) => Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -13,4 +13,4 @@ export { useSearchParams } from './hooks/useSearchParams';
|
|
|
13
13
|
export { useSubmitAction } from './hooks/useSubmitAction';
|
|
14
14
|
export { createRouter } from './creators/createRouter';
|
|
15
15
|
export { lazy } from './utils/lazy';
|
|
16
|
-
export type { RouteItem, BlockerState, Location, RouterProps, ElementProps } from './types';
|
|
16
|
+
export type { RouteItem, BlockerState, Location, RouterProps, ElementProps, NavigationLocation } from './types';
|
package/dist/index.js
CHANGED
|
@@ -30,16 +30,16 @@ var useGlobalState = ({ subscribe, getState, setState }) => {
|
|
|
30
30
|
};
|
|
31
31
|
//#endregion
|
|
32
32
|
//#region utils/commitState.ts
|
|
33
|
-
var createCommitState = ({
|
|
34
|
-
const isError =
|
|
33
|
+
var createCommitState = ({ loaderState, routeItemDataState }) => ({ routeItem, loaderStateValue, location }) => {
|
|
34
|
+
const isError = loaderStateValue.loaderError || loaderStateValue.beforeLoadError;
|
|
35
35
|
routeItemDataState.setState({
|
|
36
36
|
routeItem,
|
|
37
|
-
location
|
|
37
|
+
location,
|
|
38
38
|
status: isError ? "error" : "active"
|
|
39
39
|
});
|
|
40
|
-
loaderState.setState(
|
|
41
|
-
if ((
|
|
42
|
-
history.pushState(null, "", `${
|
|
40
|
+
loaderState.setState(loaderStateValue);
|
|
41
|
+
if ((location.search ? `${location.pathname}${location.search}` : location.pathname) === window.location.pathname + window.location.search) return;
|
|
42
|
+
history.pushState(null, "", `${location.pathname}${location.search}`);
|
|
43
43
|
};
|
|
44
44
|
//#endregion
|
|
45
45
|
//#region constants.ts
|
|
@@ -209,6 +209,14 @@ var restoreScroll = (scrollMap, pathname, behavior) => {
|
|
|
209
209
|
});
|
|
210
210
|
});
|
|
211
211
|
};
|
|
212
|
+
var formatSearchObject = (searchObject) => {
|
|
213
|
+
const params = new URLSearchParams();
|
|
214
|
+
Object.entries(searchObject).forEach(([key, value]) => {
|
|
215
|
+
if (value !== void 0 && value !== null) params.set(key, String(value));
|
|
216
|
+
});
|
|
217
|
+
const result = params.toString();
|
|
218
|
+
return result ? `?${result}` : "";
|
|
219
|
+
};
|
|
212
220
|
var findRoute = (pathname, includeAll) => {
|
|
213
221
|
if (includeAll) return routerConfig.routes.find((el) => el.path === "*" || comparePaths(el, pathname));
|
|
214
222
|
return routerConfig.routes.find((el) => comparePaths(el, pathname));
|
|
@@ -219,7 +227,7 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
219
227
|
let navigationSeq = 0;
|
|
220
228
|
let interval = 0;
|
|
221
229
|
let abortController = null;
|
|
222
|
-
const { loaderState,
|
|
230
|
+
const { loaderState, contextState, loaderMap, routeItemDataState, scrollMapState, blockerState, blockedTargetState } = routerState;
|
|
223
231
|
const commitState = createCommitState(routerState);
|
|
224
232
|
const isCacheItemFresh = createIsCacheItemFresh(loaderMap);
|
|
225
233
|
const createSignal = () => {
|
|
@@ -233,7 +241,6 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
233
241
|
setContext: contextState.setState
|
|
234
242
|
});
|
|
235
243
|
const routeResolve = (location) => {
|
|
236
|
-
loaderStateRef.set(EMPTY_LOADER_STATE);
|
|
237
244
|
const nextItem = findRoute(location.pathname, true);
|
|
238
245
|
return {
|
|
239
246
|
nextItem,
|
|
@@ -249,22 +256,33 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
249
256
|
redirect,
|
|
250
257
|
...getPartialLoaderArgs(contextState, nextLocation, routeItem)
|
|
251
258
|
});
|
|
252
|
-
|
|
253
|
-
...prev,
|
|
254
|
-
beforeLoadError: null
|
|
255
|
-
}));
|
|
259
|
+
return null;
|
|
256
260
|
} catch (error) {
|
|
257
|
-
|
|
258
|
-
...prev,
|
|
259
|
-
beforeLoadError: error
|
|
260
|
-
}));
|
|
261
|
+
return error;
|
|
261
262
|
}
|
|
262
263
|
};
|
|
263
|
-
|
|
264
|
-
if (
|
|
264
|
+
let error = null;
|
|
265
|
+
if (defaultBeforeLoad) error = await runBeforeLoad(defaultBeforeLoad);
|
|
266
|
+
if (routeItem?.beforeLoad && !error) error = await runBeforeLoad(routeItem?.beforeLoad);
|
|
267
|
+
return error;
|
|
268
|
+
};
|
|
269
|
+
const createGcTimeout = () => {
|
|
270
|
+
const { routeItem, location } = routeItemDataState.getState();
|
|
271
|
+
if (!routeItem?.gcTime) return;
|
|
272
|
+
const path = `${location.pathname}${location.search}`;
|
|
273
|
+
const currentLoaderEntry = loaderMap.get(path);
|
|
274
|
+
if (!currentLoaderEntry) return;
|
|
275
|
+
if (currentLoaderEntry.gcTimeout) window.clearTimeout(currentLoaderEntry?.gcTimeout);
|
|
276
|
+
const gcTimeout = window.setTimeout(() => loaderMap.delete(path), routeItem.gcTime);
|
|
277
|
+
loaderMap.set(path, {
|
|
278
|
+
...currentLoaderEntry,
|
|
279
|
+
gcTimeout
|
|
280
|
+
});
|
|
265
281
|
};
|
|
266
|
-
const prepareNavigation = (routeItem, location) => {
|
|
282
|
+
const prepareNavigation = (routeItem, location, hasError) => {
|
|
267
283
|
updateScrollMap(routeItemDataState, scrollMapState);
|
|
284
|
+
createGcTimeout();
|
|
285
|
+
if (hasError) return;
|
|
268
286
|
const path = getPath(location);
|
|
269
287
|
if (routeItem?.optimistic && loaderMap.has(path)) {
|
|
270
288
|
commitNavigation(() => routeItemDataState.setState({
|
|
@@ -293,7 +311,7 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
293
311
|
};
|
|
294
312
|
const getLoaderDurationPromise = (routeItem, nextLocation) => {
|
|
295
313
|
const minLoaderDuration = routeItem?.minLoaderDuration ?? routerConfig.defaultMinLoaderDuration ?? 0;
|
|
296
|
-
return minLoaderDuration && !isCacheItemFresh(getPath(nextLocation)) ? sleep(minLoaderDuration) : Promise.resolve;
|
|
314
|
+
return minLoaderDuration && !isCacheItemFresh(getPath(nextLocation)) ? sleep(minLoaderDuration) : Promise.resolve();
|
|
297
315
|
};
|
|
298
316
|
const loader = async (routeItem, nextLocation, seq) => {
|
|
299
317
|
if (!routeItem?.loader) return;
|
|
@@ -304,13 +322,9 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
304
322
|
location: nextLocation,
|
|
305
323
|
signal
|
|
306
324
|
}), getLoaderDurationPromise(routeItem, nextLocation)]);
|
|
307
|
-
if (result) loaderStateRef.set((prev) => ({
|
|
308
|
-
...prev,
|
|
309
|
-
data: result.data,
|
|
310
|
-
loaderError: result.error
|
|
311
|
-
}));
|
|
312
325
|
if (seq !== navigationSeq) return;
|
|
313
326
|
polling(routeItem, nextLocation);
|
|
327
|
+
return result;
|
|
314
328
|
};
|
|
315
329
|
const afterLoad = async (routeItem, params) => {
|
|
316
330
|
const { defaultAfterLoad } = routerConfig;
|
|
@@ -331,6 +345,17 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
331
345
|
}
|
|
332
346
|
return false;
|
|
333
347
|
};
|
|
348
|
+
const clearCurrentGcTimeout = (routeItem, location) => {
|
|
349
|
+
const path = `${location.pathname}${location.search}`;
|
|
350
|
+
if (!routeItem?.gcTime) return;
|
|
351
|
+
const currentLoaderEntry = loaderMap.get(path);
|
|
352
|
+
if (!currentLoaderEntry?.gcTimeout) return;
|
|
353
|
+
window.clearTimeout(currentLoaderEntry.gcTimeout);
|
|
354
|
+
loaderMap.set(path, {
|
|
355
|
+
...currentLoaderEntry,
|
|
356
|
+
gcTimeout: void 0
|
|
357
|
+
});
|
|
358
|
+
};
|
|
334
359
|
const navigate = async (rawLocation) => {
|
|
335
360
|
const nextLocation = {
|
|
336
361
|
...rawLocation,
|
|
@@ -340,12 +365,26 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
340
365
|
navigationSeq = navigationSeq + 1;
|
|
341
366
|
const seq = navigationSeq;
|
|
342
367
|
const { nextItem, params } = routeResolve(nextLocation);
|
|
343
|
-
await beforeLoad(nextItem, nextLocation);
|
|
368
|
+
const beforeLoadError = await beforeLoad(nextItem, nextLocation);
|
|
344
369
|
if (seq !== navigationSeq) return;
|
|
345
|
-
prepareNavigation(nextItem, nextLocation);
|
|
346
|
-
|
|
370
|
+
prepareNavigation(nextItem, nextLocation, !!beforeLoadError);
|
|
371
|
+
const result = beforeLoadError ? {
|
|
372
|
+
data: null,
|
|
373
|
+
error: null,
|
|
374
|
+
beforeLoadError
|
|
375
|
+
} : await loader(nextItem, nextLocation, seq);
|
|
347
376
|
if (seq !== navigationSeq) return;
|
|
348
|
-
|
|
377
|
+
const loaderStateValue = {
|
|
378
|
+
data: result?.data,
|
|
379
|
+
loaderError: result?.error ?? null,
|
|
380
|
+
beforeLoadError
|
|
381
|
+
};
|
|
382
|
+
commitNavigation(() => commitState({
|
|
383
|
+
location: nextLocation,
|
|
384
|
+
routeItem: nextItem,
|
|
385
|
+
loaderStateValue
|
|
386
|
+
}));
|
|
387
|
+
clearCurrentGcTimeout(nextItem, nextLocation);
|
|
349
388
|
await afterLoad(nextItem, params);
|
|
350
389
|
};
|
|
351
390
|
return navigate;
|
|
@@ -516,20 +555,6 @@ var createRevalidateCache = (routerState) => {
|
|
|
516
555
|
return revalidateCache;
|
|
517
556
|
};
|
|
518
557
|
//#endregion
|
|
519
|
-
//#region cell.ts
|
|
520
|
-
var Cell = class {
|
|
521
|
-
constructor(_value) {
|
|
522
|
-
_defineProperty(this, "_value", void 0);
|
|
523
|
-
this._value = _value;
|
|
524
|
-
}
|
|
525
|
-
get value() {
|
|
526
|
-
return this._value;
|
|
527
|
-
}
|
|
528
|
-
set(action) {
|
|
529
|
-
this._value = typeof action === "function" ? action(this._value) : action;
|
|
530
|
-
}
|
|
531
|
-
};
|
|
532
|
-
//#endregion
|
|
533
558
|
//#region creators/createRouterInstance.ts
|
|
534
559
|
var createRouterInstance = () => {
|
|
535
560
|
const routerState = {
|
|
@@ -542,7 +567,6 @@ var createRouterInstance = () => {
|
|
|
542
567
|
contextState: create({}),
|
|
543
568
|
blockerState: create("unblocked"),
|
|
544
569
|
loaderState: create(EMPTY_LOADER_STATE),
|
|
545
|
-
loaderStateRef: new Cell(EMPTY_LOADER_STATE),
|
|
546
570
|
blockedTargetState: create(null),
|
|
547
571
|
loaderMap: /* @__PURE__ */ new Map(),
|
|
548
572
|
loadingPromises: /* @__PURE__ */ new Map()
|
|
@@ -591,8 +615,18 @@ var createRouterInstance = () => {
|
|
|
591
615
|
return async (arg) => {
|
|
592
616
|
if (arg === -1) return history.go(arg);
|
|
593
617
|
if (typeof arg === "string") {
|
|
594
|
-
|
|
595
|
-
|
|
618
|
+
const [pathname, search = ""] = arg.split("?");
|
|
619
|
+
if (pathname !== location.pathname || search !== location.search) await navigate({
|
|
620
|
+
pathname,
|
|
621
|
+
search
|
|
622
|
+
});
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
const search = typeof arg.search === "object" ? formatSearchObject(arg.search) : arg.search;
|
|
626
|
+
await navigate({
|
|
627
|
+
...arg,
|
|
628
|
+
search
|
|
629
|
+
});
|
|
596
630
|
};
|
|
597
631
|
},
|
|
598
632
|
useAction: (action, options = {}) => {
|
|
@@ -839,12 +873,13 @@ var Link = ({ children, to, search = "", state, as = defaultAs, prefetch: linkPr
|
|
|
839
873
|
const { defaultPrefetch: configPrefetch, defaultHoverPrefetchDelay: configPrefetchDelay } = routerConfig;
|
|
840
874
|
const prefetch = linkPrefetch || configPrefetch;
|
|
841
875
|
const prefetchDelay = hoverPrefetchDelay ?? configPrefetchDelay;
|
|
876
|
+
const searchString = typeof search === "object" ? formatSearchObject(search) : search;
|
|
842
877
|
const location = useMemo(() => ({
|
|
843
878
|
pathname: to,
|
|
844
|
-
search,
|
|
879
|
+
search: searchString,
|
|
845
880
|
state
|
|
846
881
|
}), [
|
|
847
|
-
|
|
882
|
+
searchString,
|
|
848
883
|
state,
|
|
849
884
|
to
|
|
850
885
|
]);
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ComponentType, type CSSProperties, Dispatch, MouseEvent, ReactElement, ReactNode, Ref, SetStateAction } from 'react';
|
|
2
2
|
import { Store, useGlobalState } from './create';
|
|
3
|
-
import { Cell } from './cell';
|
|
4
3
|
export declare const LAZY_MARKER: unique symbol;
|
|
5
4
|
export type LazyComponent = {
|
|
6
5
|
readonly [LAZY_MARKER]: true;
|
|
@@ -31,6 +30,7 @@ export type ClientRouteItem = {
|
|
|
31
30
|
fallback?: RenderElement;
|
|
32
31
|
children?: ClientRouteItem[];
|
|
33
32
|
staleTime?: number;
|
|
33
|
+
gcTime?: number;
|
|
34
34
|
optimistic?: boolean;
|
|
35
35
|
pollingInterval?: number;
|
|
36
36
|
retry?: Retry;
|
|
@@ -106,6 +106,7 @@ export type LoaderStateItem = {
|
|
|
106
106
|
state: LoaderState;
|
|
107
107
|
timestamp: number;
|
|
108
108
|
staleTime: number | undefined;
|
|
109
|
+
gcTimeout?: number;
|
|
109
110
|
};
|
|
110
111
|
export type LoadingPromise = Promise<{
|
|
111
112
|
data: unknown;
|
|
@@ -122,7 +123,6 @@ export type RouterState = {
|
|
|
122
123
|
blockerState: Store<BlockerState>;
|
|
123
124
|
loaderState: Store<LoaderState>;
|
|
124
125
|
blockedTargetState: Store<Location | null>;
|
|
125
|
-
loaderStateRef: Cell<LoaderState>;
|
|
126
126
|
loaderMap: Map<string, LoaderStateItem>;
|
|
127
127
|
loadingPromises: Map<string, LoadingPromise>;
|
|
128
128
|
};
|
|
@@ -140,7 +140,7 @@ export type RouterType = {
|
|
|
140
140
|
useContextState(): ReturnType<typeof useGlobalState<Record<string, unknown>>>;
|
|
141
141
|
useLoaderState<T>(): LoaderState<T>;
|
|
142
142
|
useParams<T>(): T;
|
|
143
|
-
useNavigate(): (arg:
|
|
143
|
+
useNavigate(): (arg: NavigationLocation | string | -1) => Promise<void>;
|
|
144
144
|
useAction(action: string, options?: Options): (arg: FormData) => Promise<{
|
|
145
145
|
data: unknown;
|
|
146
146
|
error: Error | null;
|
|
@@ -172,4 +172,8 @@ export type ElementProps<T extends HTMLElement = HTMLElement> = {
|
|
|
172
172
|
onMouseLeave(event: MouseEvent): void;
|
|
173
173
|
children?: ReactNode;
|
|
174
174
|
};
|
|
175
|
+
export type SearchObject = Record<string, string | number | boolean | null | undefined>;
|
|
176
|
+
export type NavigationLocation = Omit<Location, 'search'> & {
|
|
177
|
+
search?: string | SearchObject;
|
|
178
|
+
};
|
|
175
179
|
export {};
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
import { Location, RouteItem, RouterState } from '../types';
|
|
2
|
-
|
|
1
|
+
import { LoaderState, Location, RouteItem, RouterState } from '../types';
|
|
2
|
+
type CommitState = {
|
|
3
|
+
location: Location;
|
|
4
|
+
loaderStateValue: LoaderState;
|
|
5
|
+
routeItem?: RouteItem;
|
|
6
|
+
};
|
|
7
|
+
export declare const createCommitState: ({ loaderState, routeItemDataState }: RouterState) => ({ routeItem, loaderStateValue, location }: CommitState) => void;
|
|
8
|
+
export {};
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Location, RouteItem, RouteItemData, RouterState, ScrollMap, ScrollRestorationBehavior } from '../types';
|
|
2
1
|
import { Store } from '../create';
|
|
2
|
+
import { Location, RouteItem, RouteItemData, RouterState, ScrollMap, ScrollRestorationBehavior, SearchObject } from '../types';
|
|
3
3
|
export declare const getParams: (location: Location, routeItem?: RouteItem) => Record<string, string>;
|
|
4
4
|
export declare const parseWindowLocation: (location: typeof window.location) => Location;
|
|
5
5
|
export declare const comparePaths: (route: RouteItem, pathname: string) => boolean;
|
|
@@ -15,3 +15,4 @@ export declare const getPartialLoaderArgs: (contextState: RouterState["contextSt
|
|
|
15
15
|
export declare const isVerticalScroll: (el: Element | null) => boolean;
|
|
16
16
|
export declare const updateScrollMap: (routeItemDataState: Store<RouteItemData>, scrollMapState: Store<ScrollMap>) => void;
|
|
17
17
|
export declare const restoreScroll: (scrollMap: ScrollMap, pathname: string, behavior: ScrollRestorationBehavior) => void;
|
|
18
|
+
export declare const formatSearchObject: (searchObject: SearchObject) => string;
|
package/package.json
CHANGED