react-router 6.13.0 → 6.14.0-pre.0

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # `react-router`
2
2
 
3
+ ## 6.14.0-pre.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Strip `basename` from locations provided to `unstable_useBlocker` functions to match `useLocation` ([#10573](https://github.com/remix-run/react-router/pull/10573))
8
+ - Fix `generatePath` when passed a numeric `0` value parameter ([#10612](https://github.com/remix-run/react-router/pull/10612))
9
+ - Fix `unstable_useBlocker` key issues in `StrictMode` ([#10573](https://github.com/remix-run/react-router/pull/10573))
10
+ - Fix `tsc --skipLibCheck:false` issues on React 17 ([#10622](https://github.com/remix-run/react-router/pull/10622))
11
+ - upgrade `typescript` to 5.1 ([#10581](https://github.com/remix-run/react-router/pull/10581))
12
+ - Updated dependencies:
13
+ - `@remix-run/router@1.7.0-pre.0`
14
+
3
15
  ## 6.13.0
4
16
 
5
17
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -1,15 +1,14 @@
1
1
  import type { ActionFunction, ActionFunctionArgs, Blocker, BlockerFunction, Fetcher, HydrationState, JsonFunction, LoaderFunction, LoaderFunctionArgs, Location, Navigation, Params, ParamParseKey, Path, PathMatch, PathPattern, RedirectFunction, RelativeRoutingType, Router as RemixRouter, ShouldRevalidateFunction, To, InitialEntry, LazyRouteFunction, FutureConfig as RouterFutureConfig } from "@remix-run/router";
2
2
  import { AbortedDeferredError, Action as NavigationType, createPath, defer, generatePath, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, resolvePath } from "@remix-run/router";
3
- import startTransitionImpl from "./lib/polyfills/start-transition";
4
3
  import type { AwaitProps, MemoryRouterProps, NavigateProps, OutletProps, RouteProps, PathRouteProps, LayoutRouteProps, IndexRouteProps, RouterProps, RoutesProps, RouterProviderProps, FutureConfig } from "./lib/components";
5
4
  import { createRoutesFromChildren, renderMatches, Await, MemoryRouter, Navigate, Outlet, Route, Router, RouterProvider, Routes } from "./lib/components";
6
5
  import type { DataRouteMatch, DataRouteObject, IndexRouteObject, Navigator, NavigateOptions, NonIndexRouteObject, RouteMatch, RouteObject } from "./lib/context";
7
6
  import { DataRouterContext, DataRouterStateContext, LocationContext, NavigationContext, RouteContext } from "./lib/context";
8
7
  import type { NavigateFunction } from "./lib/hooks";
9
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";
10
- declare type Hash = string;
11
- declare type Pathname = string;
12
- declare type Search = string;
9
+ type Hash = string;
10
+ type Pathname = string;
11
+ type Search = string;
13
12
  export type { ActionFunction, ActionFunctionArgs, AwaitProps, Blocker as unstable_Blocker, BlockerFunction as unstable_BlockerFunction, DataRouteMatch, DataRouteObject, Fetcher, FutureConfig, Hash, IndexRouteObject, IndexRouteProps, JsonFunction, LazyRouteFunction, LayoutRouteProps, LoaderFunction, LoaderFunctionArgs, Location, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, Navigation, Navigator, NonIndexRouteObject, OutletProps, Params, ParamParseKey, Path, PathMatch, Pathname, PathPattern, PathRouteProps, RedirectFunction, RelativeRoutingType, RouteMatch, RouteObject, RouteProps, RouterProps, RouterProviderProps, RoutesProps, Search, ShouldRevalidateFunction, To, };
14
13
  export { AbortedDeferredError, Await, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, RouterProvider, Routes, createPath, createRoutesFromChildren, createRoutesFromChildren as createRoutesFromElements, defer, isRouteErrorResponse, generatePath, json, matchPath, matchRoutes, parsePath, redirect, renderMatches, resolvePath, useActionData, useAsyncError, useAsyncValue, useBlocker as unstable_useBlocker, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes, };
15
14
  declare function mapRouteProperties(route: RouteObject): Partial<RouteObject> & {
@@ -23,4 +22,4 @@ export declare function createMemoryRouter(routes: RouteObject[], opts?: {
23
22
  initialIndex?: number;
24
23
  }): RemixRouter;
25
24
  /** @internal */
26
- 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, startTransitionImpl as UNSAFE_startTransitionImpl, };
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 v6.13.0
2
+ * React Router v6.14.0-pre.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -9,7 +9,7 @@
9
9
  * @license MIT
10
10
  */
11
11
  import * as React from 'react';
12
- import { UNSAFE_invariant, joinPaths, matchPath, UNSAFE_getPathContributingMatches, UNSAFE_warning, resolveTo, parsePath, matchRoutes, Action, isRouteErrorResponse, createMemoryHistory, stripBasename, AbortedDeferredError, createRouter } from '@remix-run/router';
12
+ import { UNSAFE_invariant, joinPaths, matchPath, UNSAFE_getPathContributingMatches, UNSAFE_warning, resolveTo, parsePath, matchRoutes, Action, IDLE_BLOCKER, stripBasename, isRouteErrorResponse, createMemoryHistory, AbortedDeferredError, createRouter } from '@remix-run/router';
13
13
  export { AbortedDeferredError, Action as NavigationType, createPath, defer, generatePath, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, resolvePath } from '@remix-run/router';
14
14
 
15
15
  function _extends() {
@@ -27,33 +27,6 @@ function _extends() {
27
27
  return _extends.apply(this, arguments);
28
28
  }
29
29
 
30
- /**
31
- Not a true "polyfill" since we guard via the feature flag at runtime,
32
- but close enough :)
33
-
34
- Webpack + React 17 fails to compile on any of the following because webpack
35
- complains that `startTransition` doesn't exist in `React`:
36
- * import { startTransition } from "react"
37
- * import * as React from from "react";
38
- "startTransition" in React ? React.startTransition(() => setState()) : setState()
39
- * import * as React from from "react";
40
- "startTransition" in React ? React["startTransition"](() => setState()) : setState()
41
-
42
- Moving it to a constant such as the following solves the Webpack/React 17 issue:
43
- * import * as React from from "react";
44
- const START_TRANSITION = "startTransition";
45
- START_TRANSITION in React ? React[START_TRANSITION](() => setState()) : setState()
46
-
47
- However, that introduces webpack/terser minification issues in production builds
48
- in React 18 where minification/obfuscation ends up removing the call of
49
- React.startTransition entirely from the first half of the ternary. Grabbing
50
- this exported reference once up front resolves that issue.
51
-
52
- See https://github.com/remix-run/react-router/issues/10579
53
- */
54
- const START_TRANSITION = "startTransition";
55
- var startTransitionImpl = React[START_TRANSITION];
56
-
57
30
  // Create react-specific types from the agnostic types in @remix-run/router to
58
31
  // export from react-router
59
32
  const DataRouterContext = /*#__PURE__*/React.createContext(null);
@@ -791,21 +764,48 @@ let blockerId = 0;
791
764
  */
792
765
  function useBlocker(shouldBlock) {
793
766
  let {
794
- router
767
+ router,
768
+ basename
795
769
  } = useDataRouterContext(DataRouterHook.UseBlocker);
796
770
  let state = useDataRouterState(DataRouterStateHook.UseBlocker);
797
- let [blockerKey] = React.useState(() => String(++blockerId));
798
- let blockerFunction = React.useCallback(args => {
799
- return typeof shouldBlock === "function" ? !!shouldBlock(args) : !!shouldBlock;
800
- }, [shouldBlock]);
801
- let blocker = router.getBlocker(blockerKey, blockerFunction);
771
+ let [blockerKey, setBlockerKey] = React.useState("");
772
+ let [blocker, setBlocker] = React.useState(IDLE_BLOCKER);
773
+ let blockerFunction = React.useCallback(arg => {
774
+ if (typeof shouldBlock !== "function") {
775
+ return !!shouldBlock;
776
+ }
777
+ if (basename === "/") {
778
+ return shouldBlock(arg);
779
+ }
802
780
 
803
- // Cleanup on unmount
804
- React.useEffect(() => () => router.deleteBlocker(blockerKey), [router, blockerKey]);
781
+ // If they provided us a function and we've got an active basename, strip
782
+ // it from the locations we expose to the user to match the behavior of
783
+ // useLocation
784
+ let {
785
+ currentLocation,
786
+ nextLocation,
787
+ historyAction
788
+ } = arg;
789
+ return shouldBlock({
790
+ currentLocation: _extends({}, currentLocation, {
791
+ pathname: stripBasename(currentLocation.pathname, basename) || currentLocation.pathname
792
+ }),
793
+ nextLocation: _extends({}, nextLocation, {
794
+ pathname: stripBasename(nextLocation.pathname, basename) || nextLocation.pathname
795
+ }),
796
+ historyAction
797
+ });
798
+ }, [basename, shouldBlock]);
799
+ React.useEffect(() => {
800
+ let key = String(++blockerId);
801
+ setBlocker(router.getBlocker(key, blockerFunction));
802
+ setBlockerKey(key);
803
+ return () => router.deleteBlocker(key);
804
+ }, [router, setBlocker, setBlockerKey, blockerFunction]);
805
805
 
806
806
  // Prefer the blocker from state since DataRouterContext is memoized so this
807
807
  // ensures we update on blocker state updates
808
- return state.blockers.get(blockerKey) || blocker;
808
+ return blockerKey && state.blockers.has(blockerKey) ? state.blockers.get(blockerKey) : blocker;
809
809
  }
810
810
 
811
811
  /**
@@ -848,6 +848,30 @@ function warningOnce(key, cond, message) {
848
848
  }
849
849
  }
850
850
 
851
+ /**
852
+ Webpack + React 17 fails to compile on any of the following because webpack
853
+ complains that `startTransition` doesn't exist in `React`:
854
+ * import { startTransition } from "react"
855
+ * import * as React from from "react";
856
+ "startTransition" in React ? React.startTransition(() => setState()) : setState()
857
+ * import * as React from from "react";
858
+ "startTransition" in React ? React["startTransition"](() => setState()) : setState()
859
+
860
+ Moving it to a constant such as the following solves the Webpack/React 17 issue:
861
+ * import * as React from from "react";
862
+ const START_TRANSITION = "startTransition";
863
+ START_TRANSITION in React ? React[START_TRANSITION](() => setState()) : setState()
864
+
865
+ However, that introduces webpack/terser minification issues in production builds
866
+ in React 18 where minification/obfuscation ends up removing the call of
867
+ React.startTransition entirely from the first half of the ternary. Grabbing
868
+ this exported reference once up front resolves that issue.
869
+
870
+ See https://github.com/remix-run/react-router/issues/10579
871
+ */
872
+ const START_TRANSITION = "startTransition";
873
+ const startTransitionImpl = React[START_TRANSITION];
874
+
851
875
  /**
852
876
  * Given a Remix Router instance, render the appropriate UI
853
877
  */
@@ -1322,5 +1346,5 @@ function createMemoryRouter(routes, opts) {
1322
1346
  }).initialize();
1323
1347
  }
1324
1348
 
1325
- 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, startTransitionImpl as UNSAFE_startTransitionImpl, 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 };
1349
+ 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 };
1326
1350
  //# sourceMappingURL=index.js.map