react-router 0.0.0-experimental-7110596b → 0.0.0-experimental-f92aa2e1
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.d.ts +2 -2
- package/dist/index.js +33 -8
- package/dist/index.js.map +1 -1
- package/dist/main.js +1 -1
- package/dist/react-router.development.js +32 -8
- 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 +37 -11
- 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
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { createRoutesFromChildren, renderMatches, Await, MemoryRouter, Navigate,
|
|
|
5
5
|
import type { DataRouteMatch, DataRouteObject, IndexRouteObject, Navigator, NavigateOptions, NonIndexRouteObject, RouteMatch, RouteObject } from "./lib/context";
|
|
6
6
|
import { DataRouterContext, DataRouterStateContext, LocationContext, NavigationContext, RouteContext } from "./lib/context";
|
|
7
7
|
import type { NavigateFunction } from "./lib/hooks";
|
|
8
|
-
import { useBlocker, useHref, useInRouterContext, useLocation, useMatch, useNavigationType, useNavigate, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes, useActionData, useAsyncError, useAsyncValue, useRouteId, useLoaderData, useMatches, useNavigation, useRevalidator, useRouteError, useRouteLoaderData } from "./lib/hooks";
|
|
8
|
+
import { useBlocker, useHref, useInRouterContext, useLocation, useMatch, useNavigationType, useNavigate, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes, useActionData, useAsyncError, useAsyncValue, useRouteId, useLoaderData, useMatches, useNavigation, useRevalidator, useRouteError, useRouteLoaderData, useRoutesImpl } from "./lib/hooks";
|
|
9
9
|
declare type Hash = string;
|
|
10
10
|
declare type Pathname = string;
|
|
11
11
|
declare type Search = string;
|
|
@@ -22,4 +22,4 @@ export declare function createMemoryRouter(routes: RouteObject[], opts?: {
|
|
|
22
22
|
initialIndex?: number;
|
|
23
23
|
}): RemixRouter;
|
|
24
24
|
/** @internal */
|
|
25
|
-
export { NavigationContext as UNSAFE_NavigationContext, LocationContext as UNSAFE_LocationContext, RouteContext as UNSAFE_RouteContext, DataRouterContext as UNSAFE_DataRouterContext, DataRouterStateContext as UNSAFE_DataRouterStateContext, mapRouteProperties as UNSAFE_mapRouteProperties, useRouteId as UNSAFE_useRouteId, };
|
|
25
|
+
export { NavigationContext as UNSAFE_NavigationContext, LocationContext as UNSAFE_LocationContext, RouteContext as UNSAFE_RouteContext, DataRouterContext as UNSAFE_DataRouterContext, DataRouterStateContext as UNSAFE_DataRouterStateContext, 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 v0.0.0-experimental-
|
|
2
|
+
* React Router v0.0.0-experimental-f92aa2e1
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -171,12 +171,26 @@ function useMatch(pattern) {
|
|
|
171
171
|
* The interface for the navigate() function returned from useNavigate().
|
|
172
172
|
*/
|
|
173
173
|
|
|
174
|
+
const navigateEffectWarning = "You should call navigate() in a React.useEffect(), not when " + "your component is first rendered."; // Mute warnings for calls to useNavigate in SSR environments
|
|
175
|
+
|
|
176
|
+
function useIsomorphicLayoutEffect(cb) {
|
|
177
|
+
let isStatic = React.useContext(NavigationContext).static;
|
|
178
|
+
|
|
179
|
+
if (!isStatic) {
|
|
180
|
+
// We should be able to get rid of this once react 18.3 is released
|
|
181
|
+
// See: https://github.com/facebook/react/pull/26395
|
|
182
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
183
|
+
React.useLayoutEffect(cb);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
174
186
|
/**
|
|
175
187
|
* Returns an imperative method for changing the location. Used by <Link>s, but
|
|
176
188
|
* may also be used by other elements to change the location.
|
|
177
189
|
*
|
|
178
190
|
* @see https://reactrouter.com/hooks/use-navigate
|
|
179
191
|
*/
|
|
192
|
+
|
|
193
|
+
|
|
180
194
|
function useNavigate() {
|
|
181
195
|
let isDataRouter = React.useContext(DataRouterContext) != null; // Conditional usage is OK here because the usage of a data router is static
|
|
182
196
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
@@ -200,7 +214,7 @@ function useNavigateUnstable() {
|
|
|
200
214
|
} = useLocation();
|
|
201
215
|
let routePathnamesJson = JSON.stringify(UNSAFE_getPathContributingMatches(matches).map(match => match.pathnameBase));
|
|
202
216
|
let activeRef = React.useRef(false);
|
|
203
|
-
|
|
217
|
+
useIsomorphicLayoutEffect(() => {
|
|
204
218
|
activeRef.current = true;
|
|
205
219
|
});
|
|
206
220
|
let navigate = React.useCallback(function (to, options) {
|
|
@@ -208,7 +222,9 @@ function useNavigateUnstable() {
|
|
|
208
222
|
options = {};
|
|
209
223
|
}
|
|
210
224
|
|
|
211
|
-
process.env.NODE_ENV !== "production" ? UNSAFE_warning(activeRef.current,
|
|
225
|
+
process.env.NODE_ENV !== "production" ? UNSAFE_warning(activeRef.current, navigateEffectWarning) : void 0; // Short circuit here since if this happens on first render the navigate
|
|
226
|
+
// is useless because we haven't wired up our history listener yet
|
|
227
|
+
|
|
212
228
|
if (!activeRef.current) return;
|
|
213
229
|
|
|
214
230
|
if (typeof to === "number") {
|
|
@@ -803,11 +819,20 @@ function useNavigateStable() {
|
|
|
803
819
|
router
|
|
804
820
|
} = useDataRouterContext(DataRouterHook.UseNavigateStable);
|
|
805
821
|
let id = useCurrentRouteId(DataRouterStateHook.UseNavigateStable);
|
|
822
|
+
let activeRef = React.useRef(false);
|
|
823
|
+
useIsomorphicLayoutEffect(() => {
|
|
824
|
+
activeRef.current = true;
|
|
825
|
+
});
|
|
806
826
|
let navigate = React.useCallback(function (to, options) {
|
|
807
827
|
if (options === void 0) {
|
|
808
828
|
options = {};
|
|
809
829
|
}
|
|
810
830
|
|
|
831
|
+
process.env.NODE_ENV !== "production" ? UNSAFE_warning(activeRef.current, navigateEffectWarning) : void 0; // Short circuit here since if this happens on first render the navigate
|
|
832
|
+
// is useless because we haven't wired up our router subscriber yet
|
|
833
|
+
|
|
834
|
+
if (!activeRef.current) return;
|
|
835
|
+
|
|
811
836
|
if (typeof to === "number") {
|
|
812
837
|
router.navigate(to);
|
|
813
838
|
} else {
|
|
@@ -885,16 +910,16 @@ function RouterProvider(_ref) {
|
|
|
885
910
|
navigationType: router.state.historyAction,
|
|
886
911
|
navigator: navigator
|
|
887
912
|
}, router.state.initialized ? /*#__PURE__*/React.createElement(DataRoutes, {
|
|
888
|
-
routes: router.routes
|
|
913
|
+
routes: router.routes,
|
|
914
|
+
state: state
|
|
889
915
|
}) : fallbackElement))), null);
|
|
890
916
|
}
|
|
891
917
|
|
|
892
918
|
function DataRoutes(_ref2) {
|
|
893
919
|
let {
|
|
894
|
-
routes
|
|
920
|
+
routes,
|
|
921
|
+
state
|
|
895
922
|
} = _ref2;
|
|
896
|
-
let state = React.useContext(DataRouterStateContext);
|
|
897
|
-
!state ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "No Router state available for DataRoutes") : UNSAFE_invariant(false) : void 0;
|
|
898
923
|
return useRoutesImpl(routes, undefined, state);
|
|
899
924
|
}
|
|
900
925
|
|
|
@@ -1333,5 +1358,5 @@ function createMemoryRouter(routes, opts) {
|
|
|
1333
1358
|
}).initialize();
|
|
1334
1359
|
} ///////////////////////////////////////////////////////////////////////////////
|
|
1335
1360
|
|
|
1336
|
-
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, 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 };
|
|
1361
|
+
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 };
|
|
1337
1362
|
//# sourceMappingURL=index.js.map
|