react-router 0.0.0-experimental-e192105b → 0.0.0-experimental-178bc9ee
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/CHANGELOG.md +17 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +74 -17
- package/dist/index.js.map +1 -1
- package/dist/lib/components.d.ts +4 -0
- package/dist/lib/context.d.ts +4 -0
- package/dist/lib/hooks.d.ts +2 -2
- package/dist/main.js +1 -1
- package/dist/react-router.development.js +70 -16
- package/dist/react-router.development.js.map +1 -1
- package/dist/react-router.production.min.js +2 -2
- package/dist/react-router.production.min.js.map +1 -1
- package/dist/umd/react-router.development.js +86 -29
- package/dist/umd/react-router.development.js.map +1 -1
- package/dist/umd/react-router.production.min.js +2 -2
- package/dist/umd/react-router.production.min.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* React Router v0.0.0-experimental-
|
|
2
|
+
* React Router v0.0.0-experimental-178bc9ee
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -234,7 +234,7 @@
|
|
|
234
234
|
let {
|
|
235
235
|
pathname: locationPathname
|
|
236
236
|
} = useLocation();
|
|
237
|
-
let routePathnamesJson = JSON.stringify(router.
|
|
237
|
+
let routePathnamesJson = JSON.stringify(router.UNSAFE_getResolveToMatches(matches));
|
|
238
238
|
let activeRef = React__namespace.useRef(false);
|
|
239
239
|
useIsomorphicLayoutEffect(() => {
|
|
240
240
|
activeRef.current = true;
|
|
@@ -323,10 +323,7 @@
|
|
|
323
323
|
let {
|
|
324
324
|
pathname: locationPathname
|
|
325
325
|
} = useLocation();
|
|
326
|
-
|
|
327
|
-
// Use the full pathname for the leaf match so we include splat values
|
|
328
|
-
// for "." links
|
|
329
|
-
let routePathnamesJson = JSON.stringify(router.UNSAFE_getPathContributingMatches(matches).map((match, idx) => idx === matches.length - 1 ? match.pathname : match.pathnameBase));
|
|
326
|
+
let routePathnamesJson = JSON.stringify(router.UNSAFE_getResolveToMatches(matches));
|
|
330
327
|
return React__namespace.useMemo(() => router.resolveTo(to, JSON.parse(routePathnamesJson), locationPathname, relative === "path"), [to, routePathnamesJson, locationPathname, relative]);
|
|
331
328
|
}
|
|
332
329
|
|
|
@@ -343,7 +340,7 @@
|
|
|
343
340
|
}
|
|
344
341
|
|
|
345
342
|
// Internal implementation with accept optional param for RouterProvider usage
|
|
346
|
-
function useRoutesImpl(routes, locationArg, dataRouterState) {
|
|
343
|
+
function useRoutesImpl(routes, locationArg, dataRouterState, future) {
|
|
347
344
|
!useInRouterContext() ? router.UNSAFE_invariant(false, // TODO: This error is probably because they somehow have 2 versions of the
|
|
348
345
|
// router loaded. We can help them understand how to avoid that.
|
|
349
346
|
"useRoutes() may be used only in the context of a <Router> component.") : void 0;
|
|
@@ -409,7 +406,7 @@
|
|
|
409
406
|
pathnameBase: match.pathnameBase === "/" ? parentPathnameBase : router.joinPaths([parentPathnameBase,
|
|
410
407
|
// Re-encode pathnames that were decoded inside matchRoutes
|
|
411
408
|
navigator.encodeLocation ? navigator.encodeLocation(match.pathnameBase).pathname : match.pathnameBase])
|
|
412
|
-
})), parentMatches, dataRouterState);
|
|
409
|
+
})), parentMatches, dataRouterState, future);
|
|
413
410
|
|
|
414
411
|
// When a user passes in a `locationArg`, the associated routes need to
|
|
415
412
|
// be wrapped in a new `LocationContext.Provider` in order for `useLocation`
|
|
@@ -531,7 +528,7 @@
|
|
|
531
528
|
value: routeContext
|
|
532
529
|
}, children);
|
|
533
530
|
}
|
|
534
|
-
function _renderMatches(matches, parentMatches, dataRouterState) {
|
|
531
|
+
function _renderMatches(matches, parentMatches, dataRouterState, future) {
|
|
535
532
|
var _dataRouterState2;
|
|
536
533
|
if (parentMatches === void 0) {
|
|
537
534
|
parentMatches = [];
|
|
@@ -539,6 +536,9 @@
|
|
|
539
536
|
if (dataRouterState === void 0) {
|
|
540
537
|
dataRouterState = null;
|
|
541
538
|
}
|
|
539
|
+
if (future === void 0) {
|
|
540
|
+
future = null;
|
|
541
|
+
}
|
|
542
542
|
if (matches == null) {
|
|
543
543
|
var _dataRouterState;
|
|
544
544
|
if ((_dataRouterState = dataRouterState) != null && _dataRouterState.errors) {
|
|
@@ -558,18 +558,58 @@
|
|
|
558
558
|
!(errorIndex >= 0) ? router.UNSAFE_invariant(false, "Could not find a matching route for errors on route IDs: " + Object.keys(errors).join(",")) : void 0;
|
|
559
559
|
renderedMatches = renderedMatches.slice(0, Math.min(renderedMatches.length, errorIndex + 1));
|
|
560
560
|
}
|
|
561
|
+
|
|
562
|
+
// If we're in a partial hydration mode, detect if we need to render down to
|
|
563
|
+
// a given Fallback while we load the rest of the hydration data
|
|
564
|
+
let renderFallback = false;
|
|
565
|
+
let fallbackIndex = -1;
|
|
566
|
+
if (dataRouterState && future && future.v7_partialHydration) {
|
|
567
|
+
for (let i = 0; i < renderedMatches.length; i++) {
|
|
568
|
+
let match = renderedMatches[i];
|
|
569
|
+
// Track the deepest fallback up until the first route without data
|
|
570
|
+
if (match.route.Fallback || match.route.fallbackElement) {
|
|
571
|
+
fallbackIndex = i;
|
|
572
|
+
}
|
|
573
|
+
if (match.route.loader && match.route.id && dataRouterState.loaderData[match.route.id] === undefined) {
|
|
574
|
+
// We found the first route without data, flag that we need to render
|
|
575
|
+
// a fallback and render up until the appropriate fallback
|
|
576
|
+
renderFallback = true;
|
|
577
|
+
if (fallbackIndex >= 0) {
|
|
578
|
+
renderedMatches = renderedMatches.slice(0, fallbackIndex + 1);
|
|
579
|
+
} else {
|
|
580
|
+
renderedMatches = [renderedMatches[0]];
|
|
581
|
+
}
|
|
582
|
+
break;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
561
586
|
return renderedMatches.reduceRight((outlet, match, index) => {
|
|
562
|
-
|
|
563
|
-
|
|
587
|
+
// Only data routers handle errors/fallbacks
|
|
588
|
+
let error;
|
|
589
|
+
let fallback = false;
|
|
564
590
|
let errorElement = null;
|
|
591
|
+
let fallbackElement = null;
|
|
565
592
|
if (dataRouterState) {
|
|
593
|
+
error = errors && match.route.id ? errors[match.route.id] : null;
|
|
566
594
|
errorElement = match.route.errorElement || defaultErrorElement;
|
|
595
|
+
if (renderFallback) {
|
|
596
|
+
if (fallbackIndex < 0 && index === 0) {
|
|
597
|
+
warningOnce("route-fallback", false, "No `Fallback` element provided to render during initial hydration");
|
|
598
|
+
fallback = true;
|
|
599
|
+
fallbackElement = null;
|
|
600
|
+
} else if (fallbackIndex === index) {
|
|
601
|
+
fallback = true;
|
|
602
|
+
fallbackElement = match.route.fallbackElement || null;
|
|
603
|
+
}
|
|
604
|
+
}
|
|
567
605
|
}
|
|
568
606
|
let matches = parentMatches.concat(renderedMatches.slice(0, index + 1));
|
|
569
607
|
let getChildren = () => {
|
|
570
608
|
let children;
|
|
571
609
|
if (error) {
|
|
572
610
|
children = errorElement;
|
|
611
|
+
} else if (fallback) {
|
|
612
|
+
children = fallbackElement;
|
|
573
613
|
} else if (match.route.Component) {
|
|
574
614
|
// Note: This is a de-optimized path since React won't re-use the
|
|
575
615
|
// ReactElement since it's identity changes with each new
|
|
@@ -723,9 +763,8 @@
|
|
|
723
763
|
*/
|
|
724
764
|
function useActionData() {
|
|
725
765
|
let state = useDataRouterState(DataRouterStateHook.UseActionData);
|
|
726
|
-
let
|
|
727
|
-
|
|
728
|
-
return Object.values((state == null ? void 0 : state.actionData) || {})[0];
|
|
766
|
+
let routeId = useCurrentRouteId(DataRouterStateHook.UseLoaderData);
|
|
767
|
+
return state.actionData ? state.actionData[routeId] : undefined;
|
|
729
768
|
}
|
|
730
769
|
|
|
731
770
|
/**
|
|
@@ -899,10 +938,10 @@
|
|
|
899
938
|
function RouterProvider(_ref) {
|
|
900
939
|
let {
|
|
901
940
|
fallbackElement,
|
|
902
|
-
router,
|
|
941
|
+
router: router$1,
|
|
903
942
|
future
|
|
904
943
|
} = _ref;
|
|
905
|
-
let [state, setStateImpl] = React__namespace.useState(router.state);
|
|
944
|
+
let [state, setStateImpl] = React__namespace.useState(router$1.state);
|
|
906
945
|
let {
|
|
907
946
|
v7_startTransition
|
|
908
947
|
} = future || {};
|
|
@@ -916,30 +955,35 @@
|
|
|
916
955
|
|
|
917
956
|
// Need to use a layout effect here so we are subscribed early enough to
|
|
918
957
|
// pick up on any render-driven redirects/navigations (useEffect/<Navigate>)
|
|
919
|
-
React__namespace.useLayoutEffect(() => router.subscribe(setState), [router, setState]);
|
|
958
|
+
React__namespace.useLayoutEffect(() => router$1.subscribe(setState), [router$1, setState]);
|
|
959
|
+
React__namespace.useEffect(() => {
|
|
960
|
+
router.UNSAFE_warning(fallbackElement == null || !router$1.future.v7_partialHydration, "`<RouterProvider fallbackElement>` is deprecated when using `v7_partialHydration`") ;
|
|
961
|
+
// Only log this once on initial mount
|
|
962
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
963
|
+
}, []);
|
|
920
964
|
let navigator = React__namespace.useMemo(() => {
|
|
921
965
|
return {
|
|
922
|
-
createHref: router.createHref,
|
|
923
|
-
encodeLocation: router.encodeLocation,
|
|
924
|
-
go: n => router.navigate(n),
|
|
925
|
-
push: (to, state, opts) => router.navigate(to, {
|
|
966
|
+
createHref: router$1.createHref,
|
|
967
|
+
encodeLocation: router$1.encodeLocation,
|
|
968
|
+
go: n => router$1.navigate(n),
|
|
969
|
+
push: (to, state, opts) => router$1.navigate(to, {
|
|
926
970
|
state,
|
|
927
971
|
preventScrollReset: opts == null ? void 0 : opts.preventScrollReset
|
|
928
972
|
}),
|
|
929
|
-
replace: (to, state, opts) => router.navigate(to, {
|
|
973
|
+
replace: (to, state, opts) => router$1.navigate(to, {
|
|
930
974
|
replace: true,
|
|
931
975
|
state,
|
|
932
976
|
preventScrollReset: opts == null ? void 0 : opts.preventScrollReset
|
|
933
977
|
})
|
|
934
978
|
};
|
|
935
|
-
}, [router]);
|
|
936
|
-
let basename = router.basename || "/";
|
|
979
|
+
}, [router$1]);
|
|
980
|
+
let basename = router$1.basename || "/";
|
|
937
981
|
let dataRouterContext = React__namespace.useMemo(() => ({
|
|
938
|
-
router,
|
|
982
|
+
router: router$1,
|
|
939
983
|
navigator,
|
|
940
984
|
static: false,
|
|
941
985
|
basename
|
|
942
|
-
}), [router, navigator, basename]);
|
|
986
|
+
}), [router$1, navigator, basename]);
|
|
943
987
|
|
|
944
988
|
// The fragment and {null} here are important! We need them to keep React 18's
|
|
945
989
|
// useId happy when we are server-rendering since we may have a <script> here
|
|
@@ -957,16 +1001,18 @@
|
|
|
957
1001
|
navigationType: state.historyAction,
|
|
958
1002
|
navigator: navigator
|
|
959
1003
|
}, state.initialized ? /*#__PURE__*/React__namespace.createElement(DataRoutes, {
|
|
960
|
-
routes: router.routes,
|
|
1004
|
+
routes: router$1.routes,
|
|
1005
|
+
future: router$1.future,
|
|
961
1006
|
state: state
|
|
962
1007
|
}) : fallbackElement))), null);
|
|
963
1008
|
}
|
|
964
1009
|
function DataRoutes(_ref2) {
|
|
965
1010
|
let {
|
|
966
1011
|
routes,
|
|
1012
|
+
future,
|
|
967
1013
|
state
|
|
968
1014
|
} = _ref2;
|
|
969
|
-
return useRoutesImpl(routes, undefined, state);
|
|
1015
|
+
return useRoutesImpl(routes, undefined, state, future);
|
|
970
1016
|
}
|
|
971
1017
|
/**
|
|
972
1018
|
* A `<Router>` that stores all entries in memory.
|
|
@@ -1039,7 +1085,7 @@
|
|
|
1039
1085
|
|
|
1040
1086
|
// Resolve the path outside of the effect so that when effects run twice in
|
|
1041
1087
|
// StrictMode they navigate to the same place
|
|
1042
|
-
let path = router.resolveTo(to, router.
|
|
1088
|
+
let path = router.resolveTo(to, router.UNSAFE_getResolveToMatches(matches), locationPathname, relative === "path");
|
|
1043
1089
|
let jsonPath = JSON.stringify(path);
|
|
1044
1090
|
React__namespace.useEffect(() => navigate(JSON.parse(jsonPath), {
|
|
1045
1091
|
replace,
|
|
@@ -1343,6 +1389,17 @@
|
|
|
1343
1389
|
Component: undefined
|
|
1344
1390
|
});
|
|
1345
1391
|
}
|
|
1392
|
+
if (route.Fallback) {
|
|
1393
|
+
{
|
|
1394
|
+
if (route.fallbackElement) {
|
|
1395
|
+
router.UNSAFE_warning(false, "You should not include both `Fallback` and `fallbackElement` on your route - " + "`Fallback` will be used.") ;
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
Object.assign(updates, {
|
|
1399
|
+
fallbackElement: /*#__PURE__*/React__namespace.createElement(route.Fallback),
|
|
1400
|
+
Fallback: undefined
|
|
1401
|
+
});
|
|
1402
|
+
}
|
|
1346
1403
|
if (route.ErrorBoundary) {
|
|
1347
1404
|
{
|
|
1348
1405
|
if (route.errorElement) {
|