react-router 6.12.2-pre.0 → 6.13.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,13 +1,40 @@
1
1
  # `react-router`
2
2
 
3
- ## 6.12.2-pre.0
3
+ ## 6.13.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Move [`React.startTransition`](https://react.dev/reference/react/startTransition) usage behind a [future flag](https://reactrouter.com/en/main/guides/api-development-strategy) to avoid issues with existing incompatible `Suspense` usages. We recommend folks adopting this flag to be better compatible with React concurrent mode, but if you run into issues you can continue without the use of `startTransition` until v7. Issues usually boils down to creating net-new promises during the render cycle, so if you run into issues you should either lift your promise creation out of the render cycle or put it behind a `useMemo`. ([#10596](https://github.com/remix-run/react-router/pull/10596))
8
+
9
+ Existing behavior will no longer include `React.startTransition`:
10
+
11
+ ```jsx
12
+ <BrowserRouter>
13
+ <Routes>{/*...*/}</Routes>
14
+ </BrowserRouter>
15
+
16
+ <RouterProvider router={router} />
17
+ ```
18
+
19
+ If you wish to enable `React.startTransition`, pass the future flag to your component:
20
+
21
+ ```jsx
22
+ <BrowserRouter future={{ v7_startTransition: true }}>
23
+ <Routes>{/*...*/}</Routes>
24
+ </BrowserRouter>
25
+
26
+ <RouterProvider router={router} future={{ v7_startTransition: true }}/>
27
+ ```
4
28
 
5
29
  ### Patch Changes
6
30
 
7
- - Work around webpack/terser `React.startTransition` minification bug in production mode ([`2f79bcef`](https://github.com/remix-run/react-router/commit/2f79bcef5f396943cf95d0d23fbd67df9b8e17a6))
31
+ - Work around webpack/terser `React.startTransition` minification bug in production mode ([#10588](https://github.com/remix-run/react-router/pull/10588))
8
32
 
9
33
  ## 6.12.1
10
34
 
35
+ > **Warning**
36
+ > Please use version `6.13.0` or later instead of `6.12.1`. This version suffers from a `webpack`/`terser` minification issue resulting in invalid minified code in your resulting production bundles which can cause issues in your application. See [#10579](https://github.com/remix-run/react-router/issues/10579) for more details.
37
+
11
38
  ### Patch Changes
12
39
 
13
40
  - Adjust feature detection of `React.startTransition` to fix webpack + react 17 compilation error ([#10569](https://github.com/remix-run/react-router/pull/10569))
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
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 } from "@remix-run/router";
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 type { AwaitProps, MemoryRouterProps, NavigateProps, OutletProps, RouteProps, PathRouteProps, LayoutRouteProps, IndexRouteProps, RouterProps, RoutesProps, RouterProviderProps } from "./lib/components";
3
+ import startTransitionImpl from "./lib/polyfills/start-transition";
4
+ import type { AwaitProps, MemoryRouterProps, NavigateProps, OutletProps, RouteProps, PathRouteProps, LayoutRouteProps, IndexRouteProps, RouterProps, RoutesProps, RouterProviderProps, FutureConfig } from "./lib/components";
4
5
  import { createRoutesFromChildren, renderMatches, Await, MemoryRouter, Navigate, Outlet, Route, Router, RouterProvider, Routes } from "./lib/components";
5
6
  import type { DataRouteMatch, DataRouteObject, IndexRouteObject, Navigator, NavigateOptions, NonIndexRouteObject, RouteMatch, RouteObject } from "./lib/context";
6
7
  import { DataRouterContext, DataRouterStateContext, LocationContext, NavigationContext, RouteContext } from "./lib/context";
@@ -9,17 +10,17 @@ import { useBlocker, useHref, useInRouterContext, useLocation, useMatch, useNavi
9
10
  declare type Hash = string;
10
11
  declare type Pathname = string;
11
12
  declare type Search = string;
12
- export type { ActionFunction, ActionFunctionArgs, AwaitProps, Blocker as unstable_Blocker, BlockerFunction as unstable_BlockerFunction, DataRouteMatch, DataRouteObject, Fetcher, 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, };
13
+ 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, };
13
14
  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, };
14
15
  declare function mapRouteProperties(route: RouteObject): Partial<RouteObject> & {
15
16
  hasErrorBoundary: boolean;
16
17
  };
17
18
  export declare function createMemoryRouter(routes: RouteObject[], opts?: {
18
19
  basename?: string;
19
- future?: Partial<Omit<FutureConfig, "v7_prependBasename">>;
20
+ future?: Partial<Omit<RouterFutureConfig, "v7_prependBasename">>;
20
21
  hydrationData?: HydrationState;
21
22
  initialEntries?: InitialEntry[];
22
23
  initialIndex?: number;
23
24
  }): RemixRouter;
24
25
  /** @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, useRoutesImpl as UNSAFE_useRoutesImpl, };
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, };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * React Router v6.12.2-pre.0
2
+ * React Router v6.13.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -27,6 +27,33 @@ 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
+
30
57
  // Create react-specific types from the agnostic types in @remix-run/router to
31
58
  // export from react-router
32
59
  const DataRouterContext = /*#__PURE__*/React.createContext(null);
@@ -821,39 +848,24 @@ function warningOnce(key, cond, message) {
821
848
  }
822
849
  }
823
850
 
824
- // Webpack + React 17 fails to compile on any of the following:
825
- // * import { startTransition } from "react"
826
- // * import * as React from from "react";
827
- // "startTransition" in React ? React.startTransition(() => setState()) : setState()
828
- // * import * as React from from "react";
829
- // "startTransition" in React ? React["startTransition"](() => setState()) : setState()
830
- //
831
- // Moving it to a constant such as the following solves the Webpack/React 17 issue:
832
- // * import * as React from from "react";
833
- // const START_TRANSITION = "startTransition";
834
- // START_TRANSITION in React ? React[START_TRANSITION](() => setState()) : setState()
835
- //
836
- // However, that introduces webpack/terser minification issues in production builds
837
- // in React 18 where minification/obfuscation ends up removing the call of
838
- // React.startTransition entirely from the first half of the ternary. Grabbing
839
- // this reference once up front resolves that issue.
840
- const START_TRANSITION = "startTransition";
841
- const startTransitionImpl = React[START_TRANSITION];
842
-
843
851
  /**
844
852
  * Given a Remix Router instance, render the appropriate UI
845
853
  */
846
854
  function RouterProvider(_ref) {
847
855
  let {
848
856
  fallbackElement,
849
- router
857
+ router,
858
+ future
850
859
  } = _ref;
851
860
  // Need to use a layout effect here so we are subscribed early enough to
852
861
  // pick up on any render-driven redirects/navigations (useEffect/<Navigate>)
853
862
  let [state, setStateImpl] = React.useState(router.state);
863
+ let {
864
+ v7_startTransition
865
+ } = future || {};
854
866
  let setState = React.useCallback(newState => {
855
- startTransitionImpl ? startTransitionImpl(() => setStateImpl(newState)) : setStateImpl(newState);
856
- }, [setStateImpl]);
867
+ v7_startTransition && startTransitionImpl ? startTransitionImpl(() => setStateImpl(newState)) : setStateImpl(newState);
868
+ }, [setStateImpl, v7_startTransition]);
857
869
  React.useLayoutEffect(() => router.subscribe(setState), [router, setState]);
858
870
  let navigator = React.useMemo(() => {
859
871
  return {
@@ -916,7 +928,8 @@ function MemoryRouter(_ref3) {
916
928
  basename,
917
929
  children,
918
930
  initialEntries,
919
- initialIndex
931
+ initialIndex,
932
+ future
920
933
  } = _ref3;
921
934
  let historyRef = React.useRef();
922
935
  if (historyRef.current == null) {
@@ -931,9 +944,12 @@ function MemoryRouter(_ref3) {
931
944
  action: history.action,
932
945
  location: history.location
933
946
  });
947
+ let {
948
+ v7_startTransition
949
+ } = future || {};
934
950
  let setState = React.useCallback(newState => {
935
- startTransitionImpl ? startTransitionImpl(() => setStateImpl(newState)) : setStateImpl(newState);
936
- }, [setStateImpl]);
951
+ v7_startTransition && startTransitionImpl ? startTransitionImpl(() => setStateImpl(newState)) : setStateImpl(newState);
952
+ }, [setStateImpl, v7_startTransition]);
937
953
  React.useLayoutEffect(() => history.listen(setState), [history, setState]);
938
954
  return /*#__PURE__*/React.createElement(Router, {
939
955
  basename: basename,
@@ -1306,5 +1322,5 @@ function createMemoryRouter(routes, opts) {
1306
1322
  }).initialize();
1307
1323
  }
1308
1324
 
1309
- 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 };
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 };
1310
1326
  //# sourceMappingURL=index.js.map