react-router 6.17.0-pre.1 → 6.17.0-pre.2
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 +6 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +22 -147
- package/dist/index.js.map +1 -1
- package/dist/lib/components.d.ts +0 -12
- package/dist/lib/context.d.ts +0 -8
- package/dist/main.js +1 -1
- package/dist/react-router.development.js +8 -124
- 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 +21 -147
- 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 +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# `react-router`
|
|
2
2
|
|
|
3
|
+
## 6.17.0-pre.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Export a separate `RouterProvider` from `react-router-dom` with `startViewTransition` support ([#10928](https://github.com/remix-run/react-router/pull/10928))
|
|
8
|
+
|
|
3
9
|
## 6.17.0-pre.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { AbortedDeferredError, Action as NavigationType, createPath, defer, gene
|
|
|
3
3
|
import type { AwaitProps, FutureConfig, IndexRouteProps, LayoutRouteProps, MemoryRouterProps, NavigateProps, OutletProps, PathRouteProps, RouteProps, RouterProps, RouterProviderProps, RoutesProps } from "./lib/components";
|
|
4
4
|
import { Await, MemoryRouter, Navigate, Outlet, Route, Router, RouterProvider, Routes, createRoutesFromChildren, renderMatches } from "./lib/components";
|
|
5
5
|
import type { DataRouteMatch, DataRouteObject, IndexRouteObject, NavigateOptions, Navigator, NonIndexRouteObject, RouteMatch, RouteObject } from "./lib/context";
|
|
6
|
-
import { DataRouterContext, DataRouterStateContext, LocationContext, NavigationContext, RouteContext
|
|
6
|
+
import { DataRouterContext, DataRouterStateContext, LocationContext, NavigationContext, RouteContext } from "./lib/context";
|
|
7
7
|
import type { NavigateFunction } from "./lib/hooks";
|
|
8
8
|
import { useActionData, useAsyncError, useAsyncValue, useBlocker, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteId, useRouteLoaderData, useRoutes, useRoutesImpl } from "./lib/hooks";
|
|
9
9
|
type Hash = string;
|
|
@@ -22,4 +22,4 @@ export declare function createMemoryRouter(routes: RouteObject[], opts?: {
|
|
|
22
22
|
initialIndex?: number;
|
|
23
23
|
}): RemixRouter;
|
|
24
24
|
/** @internal */
|
|
25
|
-
export { DataRouterContext as UNSAFE_DataRouterContext, DataRouterStateContext as UNSAFE_DataRouterStateContext, LocationContext as UNSAFE_LocationContext, NavigationContext as UNSAFE_NavigationContext, RouteContext as UNSAFE_RouteContext,
|
|
25
|
+
export { DataRouterContext as UNSAFE_DataRouterContext, DataRouterStateContext as UNSAFE_DataRouterStateContext, LocationContext as UNSAFE_LocationContext, NavigationContext as UNSAFE_NavigationContext, RouteContext as UNSAFE_RouteContext, mapRouteProperties as UNSAFE_mapRouteProperties, useRouteId as UNSAFE_useRouteId, useRoutesImpl as UNSAFE_useRoutesImpl, };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* React Router v6.17.0-pre.
|
|
2
|
+
* React Router v6.17.0-pre.2
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -37,12 +37,6 @@ const DataRouterStateContext = /*#__PURE__*/React.createContext(null);
|
|
|
37
37
|
if (process.env.NODE_ENV !== "production") {
|
|
38
38
|
DataRouterStateContext.displayName = "DataRouterState";
|
|
39
39
|
}
|
|
40
|
-
const ViewTransitionContext = /*#__PURE__*/React.createContext({
|
|
41
|
-
isTransitioning: false
|
|
42
|
-
});
|
|
43
|
-
if (process.env.NODE_ENV !== "production") {
|
|
44
|
-
ViewTransitionContext.displayName = "ViewTransition";
|
|
45
|
-
}
|
|
46
40
|
const AwaitContext = /*#__PURE__*/React.createContext(null);
|
|
47
41
|
if (process.env.NODE_ENV !== "production") {
|
|
48
42
|
AwaitContext.displayName = "Await";
|
|
@@ -873,36 +867,6 @@ function warningOnce(key, cond, message) {
|
|
|
873
867
|
*/
|
|
874
868
|
const START_TRANSITION = "startTransition";
|
|
875
869
|
const startTransitionImpl = React[START_TRANSITION];
|
|
876
|
-
function startTransitionSafe(cb) {
|
|
877
|
-
if (startTransitionImpl) {
|
|
878
|
-
startTransitionImpl(cb);
|
|
879
|
-
} else {
|
|
880
|
-
cb();
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
class Deferred {
|
|
884
|
-
// @ts-expect-error - no initializer
|
|
885
|
-
|
|
886
|
-
// @ts-expect-error - no initializer
|
|
887
|
-
|
|
888
|
-
constructor() {
|
|
889
|
-
this.status = "pending";
|
|
890
|
-
this.promise = new Promise((resolve, reject) => {
|
|
891
|
-
this.resolve = value => {
|
|
892
|
-
if (this.status === "pending") {
|
|
893
|
-
this.status = "resolved";
|
|
894
|
-
resolve(value);
|
|
895
|
-
}
|
|
896
|
-
};
|
|
897
|
-
this.reject = reason => {
|
|
898
|
-
if (this.status === "pending") {
|
|
899
|
-
this.status = "rejected";
|
|
900
|
-
reject(reason);
|
|
901
|
-
}
|
|
902
|
-
};
|
|
903
|
-
});
|
|
904
|
-
}
|
|
905
|
-
}
|
|
906
870
|
|
|
907
871
|
/**
|
|
908
872
|
* Given a Remix Router instance, render the appropriate UI
|
|
@@ -914,107 +878,20 @@ function RouterProvider(_ref) {
|
|
|
914
878
|
future
|
|
915
879
|
} = _ref;
|
|
916
880
|
let [state, setStateImpl] = React.useState(router.state);
|
|
917
|
-
let [pendingState, setPendingState] = React.useState();
|
|
918
|
-
let [vtContext, setVtContext] = React.useState({
|
|
919
|
-
isTransitioning: false
|
|
920
|
-
});
|
|
921
|
-
let [renderDfd, setRenderDfd] = React.useState();
|
|
922
|
-
let [transition, setTransition] = React.useState();
|
|
923
|
-
let [interruption, setInterruption] = React.useState();
|
|
924
881
|
let {
|
|
925
882
|
v7_startTransition
|
|
926
883
|
} = future || {};
|
|
927
|
-
let
|
|
928
|
-
if (v7_startTransition) {
|
|
929
|
-
|
|
930
|
-
} else {
|
|
931
|
-
cb();
|
|
932
|
-
}
|
|
933
|
-
}, [v7_startTransition]);
|
|
934
|
-
let setState = React.useCallback((newState, _ref2) => {
|
|
935
|
-
let {
|
|
936
|
-
unstable_viewTransitionOpts: viewTransitionOpts
|
|
937
|
-
} = _ref2;
|
|
938
|
-
if (!viewTransitionOpts || router.window == null || typeof router.window.document.startViewTransition !== "function") {
|
|
939
|
-
// Mid-navigation state update, or startViewTransition isn't available
|
|
940
|
-
optInStartTransition(() => setStateImpl(newState));
|
|
941
|
-
} else if (transition && renderDfd) {
|
|
942
|
-
// Interrupting an in-progress transition, cancel and let everything flush
|
|
943
|
-
// out, and then kick off a new transition from the interruption state
|
|
944
|
-
renderDfd.resolve();
|
|
945
|
-
transition.skipTransition();
|
|
946
|
-
setInterruption({
|
|
947
|
-
state: newState,
|
|
948
|
-
currentLocation: viewTransitionOpts.currentLocation,
|
|
949
|
-
nextLocation: viewTransitionOpts.nextLocation
|
|
950
|
-
});
|
|
884
|
+
let setState = React.useCallback(newState => {
|
|
885
|
+
if (v7_startTransition && startTransitionImpl) {
|
|
886
|
+
startTransitionImpl(() => setStateImpl(newState));
|
|
951
887
|
} else {
|
|
952
|
-
|
|
953
|
-
setPendingState(newState);
|
|
954
|
-
setVtContext({
|
|
955
|
-
isTransitioning: true,
|
|
956
|
-
currentLocation: viewTransitionOpts.currentLocation,
|
|
957
|
-
nextLocation: viewTransitionOpts.nextLocation
|
|
958
|
-
});
|
|
888
|
+
setStateImpl(newState);
|
|
959
889
|
}
|
|
960
|
-
}, [
|
|
890
|
+
}, [setStateImpl, v7_startTransition]);
|
|
961
891
|
|
|
962
892
|
// Need to use a layout effect here so we are subscribed early enough to
|
|
963
893
|
// pick up on any render-driven redirects/navigations (useEffect/<Navigate>)
|
|
964
894
|
React.useLayoutEffect(() => router.subscribe(setState), [router, setState]);
|
|
965
|
-
|
|
966
|
-
// When we start a view transition, create a Deferred we can use for the
|
|
967
|
-
// eventual "completed" render
|
|
968
|
-
React.useEffect(() => {
|
|
969
|
-
if (vtContext.isTransitioning) {
|
|
970
|
-
setRenderDfd(new Deferred());
|
|
971
|
-
}
|
|
972
|
-
}, [vtContext.isTransitioning]);
|
|
973
|
-
|
|
974
|
-
// Once the deferred is created, kick off startViewTransition() to update the
|
|
975
|
-
// DOM and then wait on the Deferred to resolve (indicating the DOM update has
|
|
976
|
-
// happened)
|
|
977
|
-
React.useEffect(() => {
|
|
978
|
-
if (renderDfd && pendingState && router.window) {
|
|
979
|
-
let newState = pendingState;
|
|
980
|
-
let renderPromise = renderDfd.promise;
|
|
981
|
-
let transition = router.window.document.startViewTransition(async () => {
|
|
982
|
-
optInStartTransition(() => setStateImpl(newState));
|
|
983
|
-
await renderPromise;
|
|
984
|
-
});
|
|
985
|
-
transition.finished.finally(() => {
|
|
986
|
-
setRenderDfd(undefined);
|
|
987
|
-
setTransition(undefined);
|
|
988
|
-
setPendingState(undefined);
|
|
989
|
-
setVtContext({
|
|
990
|
-
isTransitioning: false
|
|
991
|
-
});
|
|
992
|
-
});
|
|
993
|
-
setTransition(transition);
|
|
994
|
-
}
|
|
995
|
-
}, [optInStartTransition, pendingState, renderDfd, router.window]);
|
|
996
|
-
|
|
997
|
-
// When the new location finally renders and is committed to the DOM, this
|
|
998
|
-
// effect will run to resolve the transition
|
|
999
|
-
React.useEffect(() => {
|
|
1000
|
-
if (renderDfd && pendingState && state.location.key === pendingState.location.key) {
|
|
1001
|
-
renderDfd.resolve();
|
|
1002
|
-
}
|
|
1003
|
-
}, [renderDfd, transition, state.location, pendingState]);
|
|
1004
|
-
|
|
1005
|
-
// If we get interrupted with a new navigation during a transition, we skip
|
|
1006
|
-
// the active transition, let it cleanup, then kick it off again here
|
|
1007
|
-
React.useEffect(() => {
|
|
1008
|
-
if (!vtContext.isTransitioning && interruption) {
|
|
1009
|
-
setPendingState(interruption.state);
|
|
1010
|
-
setVtContext({
|
|
1011
|
-
isTransitioning: true,
|
|
1012
|
-
currentLocation: interruption.currentLocation,
|
|
1013
|
-
nextLocation: interruption.nextLocation
|
|
1014
|
-
});
|
|
1015
|
-
setInterruption(undefined);
|
|
1016
|
-
}
|
|
1017
|
-
}, [vtContext.isTransitioning, interruption]);
|
|
1018
895
|
let navigator = React.useMemo(() => {
|
|
1019
896
|
return {
|
|
1020
897
|
createHref: router.createHref,
|
|
@@ -1049,8 +926,6 @@ function RouterProvider(_ref) {
|
|
|
1049
926
|
value: dataRouterContext
|
|
1050
927
|
}, /*#__PURE__*/React.createElement(DataRouterStateContext.Provider, {
|
|
1051
928
|
value: state
|
|
1052
|
-
}, /*#__PURE__*/React.createElement(ViewTransitionContext.Provider, {
|
|
1053
|
-
value: vtContext
|
|
1054
929
|
}, /*#__PURE__*/React.createElement(Router, {
|
|
1055
930
|
basename: basename,
|
|
1056
931
|
location: state.location,
|
|
@@ -1059,13 +934,13 @@ function RouterProvider(_ref) {
|
|
|
1059
934
|
}, state.initialized ? /*#__PURE__*/React.createElement(DataRoutes, {
|
|
1060
935
|
routes: router.routes,
|
|
1061
936
|
state: state
|
|
1062
|
-
}) : fallbackElement)))
|
|
937
|
+
}) : fallbackElement))), null);
|
|
1063
938
|
}
|
|
1064
|
-
function DataRoutes(
|
|
939
|
+
function DataRoutes(_ref2) {
|
|
1065
940
|
let {
|
|
1066
941
|
routes,
|
|
1067
942
|
state
|
|
1068
|
-
} =
|
|
943
|
+
} = _ref2;
|
|
1069
944
|
return useRoutesImpl(routes, undefined, state);
|
|
1070
945
|
}
|
|
1071
946
|
/**
|
|
@@ -1073,14 +948,14 @@ function DataRoutes(_ref3) {
|
|
|
1073
948
|
*
|
|
1074
949
|
* @see https://reactrouter.com/router-components/memory-router
|
|
1075
950
|
*/
|
|
1076
|
-
function MemoryRouter(
|
|
951
|
+
function MemoryRouter(_ref3) {
|
|
1077
952
|
let {
|
|
1078
953
|
basename,
|
|
1079
954
|
children,
|
|
1080
955
|
initialEntries,
|
|
1081
956
|
initialIndex,
|
|
1082
957
|
future
|
|
1083
|
-
} =
|
|
958
|
+
} = _ref3;
|
|
1084
959
|
let historyRef = React.useRef();
|
|
1085
960
|
if (historyRef.current == null) {
|
|
1086
961
|
historyRef.current = createMemoryHistory({
|
|
@@ -1118,13 +993,13 @@ function MemoryRouter(_ref4) {
|
|
|
1118
993
|
*
|
|
1119
994
|
* @see https://reactrouter.com/components/navigate
|
|
1120
995
|
*/
|
|
1121
|
-
function Navigate(
|
|
996
|
+
function Navigate(_ref4) {
|
|
1122
997
|
let {
|
|
1123
998
|
to,
|
|
1124
999
|
replace,
|
|
1125
1000
|
state,
|
|
1126
1001
|
relative
|
|
1127
|
-
} =
|
|
1002
|
+
} = _ref4;
|
|
1128
1003
|
!useInRouterContext() ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, // TODO: This error is probably because they somehow have 2 versions of
|
|
1129
1004
|
// the router loaded. We can help them understand how to avoid that.
|
|
1130
1005
|
"<Navigate> may be used only in the context of a <Router> component.") : UNSAFE_invariant(false) : void 0;
|
|
@@ -1173,7 +1048,7 @@ function Route(_props) {
|
|
|
1173
1048
|
*
|
|
1174
1049
|
* @see https://reactrouter.com/router-components/router
|
|
1175
1050
|
*/
|
|
1176
|
-
function Router(
|
|
1051
|
+
function Router(_ref5) {
|
|
1177
1052
|
let {
|
|
1178
1053
|
basename: basenameProp = "/",
|
|
1179
1054
|
children = null,
|
|
@@ -1181,7 +1056,7 @@ function Router(_ref6) {
|
|
|
1181
1056
|
navigationType = Action.Pop,
|
|
1182
1057
|
navigator,
|
|
1183
1058
|
static: staticProp = false
|
|
1184
|
-
} =
|
|
1059
|
+
} = _ref5;
|
|
1185
1060
|
!!useInRouterContext() ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "You cannot render a <Router> inside another <Router>." + " You should never have more than one in your app.") : UNSAFE_invariant(false) : void 0;
|
|
1186
1061
|
|
|
1187
1062
|
// Preserve trailing slashes on basename, so we can let the user control
|
|
@@ -1235,23 +1110,23 @@ function Router(_ref6) {
|
|
|
1235
1110
|
*
|
|
1236
1111
|
* @see https://reactrouter.com/components/routes
|
|
1237
1112
|
*/
|
|
1238
|
-
function Routes(
|
|
1113
|
+
function Routes(_ref6) {
|
|
1239
1114
|
let {
|
|
1240
1115
|
children,
|
|
1241
1116
|
location
|
|
1242
|
-
} =
|
|
1117
|
+
} = _ref6;
|
|
1243
1118
|
return useRoutes(createRoutesFromChildren(children), location);
|
|
1244
1119
|
}
|
|
1245
1120
|
/**
|
|
1246
1121
|
* Component to use for rendering lazily loaded data from returning defer()
|
|
1247
1122
|
* in a loader function
|
|
1248
1123
|
*/
|
|
1249
|
-
function Await(
|
|
1124
|
+
function Await(_ref7) {
|
|
1250
1125
|
let {
|
|
1251
1126
|
children,
|
|
1252
1127
|
errorElement,
|
|
1253
1128
|
resolve
|
|
1254
|
-
} =
|
|
1129
|
+
} = _ref7;
|
|
1255
1130
|
return /*#__PURE__*/React.createElement(AwaitErrorBoundary, {
|
|
1256
1131
|
resolve: resolve,
|
|
1257
1132
|
errorElement: errorElement
|
|
@@ -1356,10 +1231,10 @@ class AwaitErrorBoundary extends React.Component {
|
|
|
1356
1231
|
* @private
|
|
1357
1232
|
* Indirection to leverage useAsyncValue for a render-prop API on `<Await>`
|
|
1358
1233
|
*/
|
|
1359
|
-
function ResolveAwait(
|
|
1234
|
+
function ResolveAwait(_ref8) {
|
|
1360
1235
|
let {
|
|
1361
1236
|
children
|
|
1362
|
-
} =
|
|
1237
|
+
} = _ref8;
|
|
1363
1238
|
let data = useAsyncValue();
|
|
1364
1239
|
let toRender = typeof children === "function" ? children(data) : children;
|
|
1365
1240
|
return /*#__PURE__*/React.createElement(React.Fragment, null, toRender);
|
|
@@ -1472,5 +1347,5 @@ function createMemoryRouter(routes, opts) {
|
|
|
1472
1347
|
}).initialize();
|
|
1473
1348
|
}
|
|
1474
1349
|
|
|
1475
|
-
export { Await, MemoryRouter, Navigate, Outlet, Route, Router, RouterProvider, Routes, DataRouterContext as UNSAFE_DataRouterContext, DataRouterStateContext as UNSAFE_DataRouterStateContext, LocationContext as UNSAFE_LocationContext, NavigationContext as UNSAFE_NavigationContext, RouteContext as UNSAFE_RouteContext,
|
|
1350
|
+
export { Await, MemoryRouter, Navigate, Outlet, Route, Router, RouterProvider, Routes, DataRouterContext as UNSAFE_DataRouterContext, DataRouterStateContext as UNSAFE_DataRouterStateContext, LocationContext as UNSAFE_LocationContext, NavigationContext as UNSAFE_NavigationContext, RouteContext as UNSAFE_RouteContext, mapRouteProperties as UNSAFE_mapRouteProperties, useRouteId as UNSAFE_useRouteId, useRoutesImpl as UNSAFE_useRoutesImpl, createMemoryRouter, createRoutesFromChildren, createRoutesFromChildren as createRoutesFromElements, renderMatches, useBlocker as unstable_useBlocker, useActionData, useAsyncError, useAsyncValue, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes };
|
|
1476
1351
|
//# sourceMappingURL=index.js.map
|