clear-react-router 2.1.5 → 2.1.6
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 +20 -21
- package/dist/types.d.ts +1 -1
- package/dist/utils/commitNavigation.d.ts +1 -1
- package/dist/utils/commitState.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -30,12 +30,13 @@ var useGlobalState = ({ subscribe, getState, setState }) => {
|
|
|
30
30
|
};
|
|
31
31
|
//#endregion
|
|
32
32
|
//#region utils/commitState.ts
|
|
33
|
-
var createCommitState = ({
|
|
34
|
-
routeItemDataState.setState({
|
|
33
|
+
var createCommitState = ({ statusState, loaderStateRef, loaderState, routeItemDataState }) => (nextLocation, routeItem) => {
|
|
34
|
+
if (!routeItem?.loader) routeItemDataState.setState({
|
|
35
35
|
routeItem,
|
|
36
36
|
location: nextLocation
|
|
37
37
|
});
|
|
38
|
-
|
|
38
|
+
const isError = loaderStateRef.value.loaderError || loaderStateRef.value.beforeLoadError;
|
|
39
|
+
statusState.setState(isError ? "error" : "active");
|
|
39
40
|
loaderState.setState(loaderStateRef.value);
|
|
40
41
|
if ((nextLocation.search ? `${nextLocation.pathname}${nextLocation.search}` : nextLocation.pathname) === window.location.pathname + window.location.search) return;
|
|
41
42
|
history.pushState(null, "", `${nextLocation.pathname}${nextLocation.search}`);
|
|
@@ -105,8 +106,8 @@ var RouterConfig = class {
|
|
|
105
106
|
var routerConfig = new RouterConfig();
|
|
106
107
|
//#endregion
|
|
107
108
|
//#region utils/commitNavigation.ts
|
|
108
|
-
var commitNavigation = (callback) => {
|
|
109
|
-
if (!routerConfig.isAnimated) return callback();
|
|
109
|
+
var commitNavigation = (callback, isCommited) => {
|
|
110
|
+
if (!routerConfig.isAnimated || isCommited) return callback();
|
|
110
111
|
try {
|
|
111
112
|
const transition = document.startViewTransition(callback);
|
|
112
113
|
transition.ready.catch(() => {});
|
|
@@ -217,7 +218,7 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
217
218
|
let interval = 0;
|
|
218
219
|
let abortController = null;
|
|
219
220
|
const { loaderState, loaderStateRef, statusState, contextState, loaderMap, routeItemDataState, scrollMapState } = routerState;
|
|
220
|
-
const
|
|
221
|
+
const commitState = createCommitState(routerState);
|
|
221
222
|
const isCacheItemFresh = createIsCacheItemFresh(loaderMap);
|
|
222
223
|
const createSignal = () => {
|
|
223
224
|
abortController?.abort();
|
|
@@ -262,19 +263,18 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
262
263
|
};
|
|
263
264
|
const prepareNavigation = (routeItem, location) => {
|
|
264
265
|
updateScrollMap(routeItemDataState, scrollMapState);
|
|
266
|
+
if (routeItem?.loader) routeItemDataState.setState({
|
|
267
|
+
routeItem,
|
|
268
|
+
location
|
|
269
|
+
});
|
|
265
270
|
const path = getPath(location);
|
|
266
271
|
if (routeItem?.optimistic && loaderMap.has(path)) {
|
|
267
|
-
routeItemDataState.setState({
|
|
268
|
-
routeItem,
|
|
269
|
-
location
|
|
270
|
-
});
|
|
271
272
|
statusState.setState("optimistic");
|
|
272
273
|
const currentLoaderState = loaderMap.get(path)?.state;
|
|
273
274
|
if (currentLoaderState) loaderState.setState(currentLoaderState);
|
|
274
|
-
|
|
275
|
-
const pendingShouldExist = routeItem?.loader && !isCacheItemFresh(path);
|
|
276
|
-
commitNavigation(() => statusState.setState(pendingShouldExist ? "pending" : "active"));
|
|
275
|
+
return;
|
|
277
276
|
}
|
|
277
|
+
if (routeItem?.loader && !isCacheItemFresh(path)) statusState.setState("pending");
|
|
278
278
|
};
|
|
279
279
|
const polling = (routeItem, nextLocation) => {
|
|
280
280
|
if (!routeItem?.pollingInterval) return;
|
|
@@ -330,7 +330,7 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
330
330
|
prepareNavigation(nextItem, nextLocation);
|
|
331
331
|
await loader(nextItem, nextLocation, seq);
|
|
332
332
|
if (seq !== navigationSeq) return;
|
|
333
|
-
commitNavigation(() =>
|
|
333
|
+
commitNavigation(() => commitState(nextLocation, nextItem));
|
|
334
334
|
await afterLoad(nextItem, params);
|
|
335
335
|
};
|
|
336
336
|
return navigate;
|
|
@@ -665,9 +665,6 @@ var useNavigation = () => {
|
|
|
665
665
|
}, [navigate]);
|
|
666
666
|
};
|
|
667
667
|
//#endregion
|
|
668
|
-
//#region hooks/useLoaderState.ts
|
|
669
|
-
var useLoaderState = router.hooks.useLoaderState;
|
|
670
|
-
//#endregion
|
|
671
668
|
//#region hooks/useApplyCustomAnimation.ts
|
|
672
669
|
var useApplyCustomAnimation = (animationDuration) => {
|
|
673
670
|
useEffect(() => {
|
|
@@ -781,7 +778,7 @@ var Router = ({ routes, defaultBeforeLoad, defaultAfterLoad, animationDuration,
|
|
|
781
778
|
const { useRouteItemData, useStatus } = router.hooks;
|
|
782
779
|
const [routeItemData] = useRouteItemData();
|
|
783
780
|
const [status] = useStatus();
|
|
784
|
-
const
|
|
781
|
+
const isError = status === "error";
|
|
785
782
|
const isLoading = status === "pending";
|
|
786
783
|
const isOptimistic = status === "optimistic";
|
|
787
784
|
useNavigation();
|
|
@@ -801,10 +798,9 @@ var Router = ({ routes, defaultBeforeLoad, defaultAfterLoad, animationDuration,
|
|
|
801
798
|
useSetInitialContext(initialContext);
|
|
802
799
|
usePreserveScroll(defaultScrollRestorationBehavior);
|
|
803
800
|
const { routeItem, location } = routeItemData;
|
|
804
|
-
|
|
805
|
-
if (!showErrorElement && isLoading) return renderElement(routeItemData?.routeItem?.loaderFallback || defaultLoaderFallback);
|
|
801
|
+
if (isLoading && !isError) return renderElement(routeItemData?.routeItem?.loaderFallback || defaultLoaderFallback);
|
|
806
802
|
if (!routeItem) return null;
|
|
807
|
-
if (
|
|
803
|
+
if (isError) return renderElement(routeItem.errorElement || defaultErrorElement);
|
|
808
804
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
809
805
|
style: { viewTransitionName: "page" },
|
|
810
806
|
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorBoundary, { children: renderElement(routeItem.element) }, location.pathname), optimisticSpinner && isOptimistic && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, {})]
|
|
@@ -923,6 +919,9 @@ var Link = ({ children, to, search = "", state, as = defaultAs, prefetch: linkPr
|
|
|
923
919
|
//#region hooks/useParams.ts
|
|
924
920
|
var useParams = router.hooks.useParams;
|
|
925
921
|
//#endregion
|
|
922
|
+
//#region hooks/useLoaderState.ts
|
|
923
|
+
var useLoaderState = router.hooks.useLoaderState;
|
|
924
|
+
//#endregion
|
|
926
925
|
//#region hooks/useInvalidate.ts
|
|
927
926
|
var useInvalidate = () => router.runtime.invalidate;
|
|
928
927
|
//#endregion
|
package/dist/types.d.ts
CHANGED
|
@@ -111,7 +111,7 @@ export type LoadingPromise = Promise<{
|
|
|
111
111
|
data: null;
|
|
112
112
|
error: unknown;
|
|
113
113
|
} | undefined>;
|
|
114
|
-
export type Status = 'idle' | 'pending' | 'active' | 'optimistic';
|
|
114
|
+
export type Status = 'idle' | 'pending' | 'active' | 'optimistic' | 'error';
|
|
115
115
|
export type ScrollMap = Record<string, [string, number][]>;
|
|
116
116
|
export type RouterState = {
|
|
117
117
|
routeItemDataState: Store<RouteItemData>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const commitNavigation: (callback: () => void) => void;
|
|
1
|
+
export declare const commitNavigation: (callback: () => void, isCommited?: boolean) => void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Location, RouteItem, RouterState } from '../types';
|
|
2
|
-
export declare const createCommitState: ({
|
|
2
|
+
export declare const createCommitState: ({ statusState, loaderStateRef, loaderState, routeItemDataState }: RouterState) => (nextLocation: Location, routeItem?: RouteItem) => void;
|