react-router 6.8.2 → 6.9.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,113 @@
1
1
  # `react-router`
2
2
 
3
+ ## 6.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - React Router now supports an alternative way to define your route `element` and `errorElement` fields as React Components instead of React Elements. You can instead pass a React Component to the new `Component` and `ErrorBoundary` fields if you choose. There is no functional difference between the two, so use whichever approach you prefer 😀. You shouldn't be defining both, but if you do `Component`/`ErrorBoundary` will "win". ([#10045](https://github.com/remix-run/react-router/pull/10045))
8
+
9
+ **Example JSON Syntax**
10
+
11
+ ```jsx
12
+ // Both of these work the same:
13
+ const elementRoutes = [{
14
+ path: '/',
15
+ element: <Home />,
16
+ errorElement: <HomeError />,
17
+ }]
18
+
19
+ const componentRoutes = [{
20
+ path: '/',
21
+ Component: Home,
22
+ ErrorBoundary: HomeError,
23
+ }]
24
+
25
+ function Home() { ... }
26
+ function HomeError() { ... }
27
+ ```
28
+
29
+ **Example JSX Syntax**
30
+
31
+ ```jsx
32
+ // Both of these work the same:
33
+ const elementRoutes = createRoutesFromElements(
34
+ <Route path='/' element={<Home />} errorElement={<HomeError /> } />
35
+ );
36
+
37
+ const componentRoutes = createRoutesFromElements(
38
+ <Route path='/' Component={Home} ErrorBoundary={HomeError} />
39
+ );
40
+
41
+ function Home() { ... }
42
+ function HomeError() { ... }
43
+ ```
44
+
45
+ - **Introducing Lazy Route Modules!** ([#10045](https://github.com/remix-run/react-router/pull/10045))
46
+
47
+ In order to keep your application bundles small and support code-splitting of your routes, we've introduced a new `lazy()` route property. This is an async function that resolves the non-route-matching portions of your route definition (`loader`, `action`, `element`/`Component`, `errorElement`/`ErrorBoundary`, `shouldRevalidate`, `handle`).
48
+
49
+ Lazy routes are resolved on initial load and during the `loading` or `submitting` phase of a navigation or fetcher call. You cannot lazily define route-matching properties (`path`, `index`, `children`) since we only execute your lazy route functions after we've matched known routes.
50
+
51
+ Your `lazy` functions will typically return the result of a dynamic import.
52
+
53
+ ```jsx
54
+ // In this example, we assume most folks land on the homepage so we include that
55
+ // in our critical-path bundle, but then we lazily load modules for /a and /b so
56
+ // they don't load until the user navigates to those routes
57
+ let routes = createRoutesFromElements(
58
+ <Route path="/" element={<Layout />}>
59
+ <Route index element={<Home />} />
60
+ <Route path="a" lazy={() => import("./a")} />
61
+ <Route path="b" lazy={() => import("./b")} />
62
+ </Route>
63
+ );
64
+ ```
65
+
66
+ Then in your lazy route modules, export the properties you want defined for the route:
67
+
68
+ ```jsx
69
+ export async function loader({ request }) {
70
+ let data = await fetchData(request);
71
+ return json(data);
72
+ }
73
+
74
+ // Export a `Component` directly instead of needing to create a React Element from it
75
+ export function Component() {
76
+ let data = useLoaderData();
77
+
78
+ return (
79
+ <>
80
+ <h1>You made it!</h1>
81
+ <p>{data}</p>
82
+ </>
83
+ );
84
+ }
85
+
86
+ // Export an `ErrorBoundary` directly instead of needing to create a React Element from it
87
+ export function ErrorBoundary() {
88
+ let error = useRouteError();
89
+ return isRouteErrorResponse(error) ? (
90
+ <h1>
91
+ {error.status} {error.statusText}
92
+ </h1>
93
+ ) : (
94
+ <h1>{error.message || error}</h1>
95
+ );
96
+ }
97
+ ```
98
+
99
+ An example of this in action can be found in the [`examples/lazy-loading-router-provider`](https://github.com/remix-run/react-router/tree/main/examples/lazy-loading-router-provider) directory of the repository.
100
+
101
+ 🙌 Huge thanks to @rossipedia for the [Initial Proposal](https://github.com/remix-run/react-router/discussions/9826) and [POC Implementation](https://github.com/remix-run/react-router/pull/9830).
102
+
103
+ - Updated dependencies:
104
+ - `@remix-run/router@1.4.0`
105
+
106
+ ### Patch Changes
107
+
108
+ - Fix `generatePath` incorrectly applying parameters in some cases ([`bc6fefa1`](https://github.com/remix-run/react-router/commit/bc6fefa19019ce9f5250c8b5af9b8c5d3390e9d1))
109
+ - Improve memoization for context providers to avoid unnecessary re-renders ([`bc6fefa1`](https://github.com/remix-run/react-router/commit/bc6fefa19019ce9f5250c8b5af9b8c5d3390e9d1))
110
+
3
111
  ## 6.8.2
4
112
 
5
113
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type { ActionFunction, ActionFunctionArgs, Blocker, BlockerFunction, Fetcher, HydrationState, JsonFunction, LoaderFunction, LoaderFunctionArgs, Location, Navigation, Params, ParamParseKey, Path, PathMatch, PathPattern, RedirectFunction, Router as RemixRouter, ShouldRevalidateFunction, To, InitialEntry } from "@remix-run/router";
1
+ import type { ActionFunction, ActionFunctionArgs, Blocker, BlockerFunction, Fetcher, HydrationState, JsonFunction, LoaderFunction, LoaderFunctionArgs, Location, Navigation, Params, ParamParseKey, Path, PathMatch, PathPattern, RedirectFunction, Router as RemixRouter, ShouldRevalidateFunction, To, InitialEntry, LazyRouteFunction } 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
3
  import type { AwaitProps, MemoryRouterProps, NavigateProps, OutletProps, RouteProps, PathRouteProps, LayoutRouteProps, IndexRouteProps, RouterProps, RoutesProps, RouterProviderProps } from "./lib/components";
4
- import { enhanceManualRouteObjects, createRoutesFromChildren, renderMatches, Await, MemoryRouter, Navigate, Outlet, Route, Router, RouterProvider, Routes } from "./lib/components";
4
+ import { createRoutesFromChildren, renderMatches, Await, MemoryRouter, Navigate, Outlet, Route, Router, RouterProvider, Routes } from "./lib/components";
5
5
  import type { DataRouteMatch, DataRouteObject, IndexRouteObject, Navigator, NavigateOptions, NonIndexRouteObject, RouteMatch, RouteObject, RelativeRoutingType } from "./lib/context";
6
6
  import { DataRouterContext, DataRouterStateContext, LocationContext, NavigationContext, RouteContext } from "./lib/context";
7
7
  import type { NavigateFunction } from "./lib/hooks";
@@ -9,8 +9,9 @@ import { useBlocker, useHref, useInRouterContext, useLocation, useMatch, useNavi
9
9
  declare type Hash = string;
10
10
  declare type Pathname = string;
11
11
  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, 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, };
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
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, };
14
+ declare function detectErrorBoundary(route: RouteObject): boolean;
14
15
  export declare function createMemoryRouter(routes: RouteObject[], opts?: {
15
16
  basename?: string;
16
17
  hydrationData?: HydrationState;
@@ -18,4 +19,4 @@ export declare function createMemoryRouter(routes: RouteObject[], opts?: {
18
19
  initialIndex?: number;
19
20
  }): RemixRouter;
20
21
  /** @internal */
21
- export { NavigationContext as UNSAFE_NavigationContext, LocationContext as UNSAFE_LocationContext, RouteContext as UNSAFE_RouteContext, DataRouterContext as UNSAFE_DataRouterContext, DataRouterStateContext as UNSAFE_DataRouterStateContext, enhanceManualRouteObjects as UNSAFE_enhanceManualRouteObjects, };
22
+ export { NavigationContext as UNSAFE_NavigationContext, LocationContext as UNSAFE_LocationContext, RouteContext as UNSAFE_RouteContext, DataRouterContext as UNSAFE_DataRouterContext, DataRouterStateContext as UNSAFE_DataRouterStateContext, detectErrorBoundary as UNSAFE_detectErrorBoundary, };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * React Router v6.8.2
2
+ * React Router v6.9.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -8,27 +8,10 @@
8
8
  *
9
9
  * @license MIT
10
10
  */
11
- import { UNSAFE_invariant, joinPaths, matchPath, UNSAFE_getPathContributingMatches, warning, resolveTo, parsePath, matchRoutes, Action, isRouteErrorResponse, createMemoryHistory, stripBasename, AbortedDeferredError, createRouter } from '@remix-run/router';
11
+ import { UNSAFE_invariant, joinPaths, matchPath, UNSAFE_getPathContributingMatches, UNSAFE_warning, resolveTo, parsePath, matchRoutes, Action, isRouteErrorResponse, createMemoryHistory, stripBasename, AbortedDeferredError, createRouter } from '@remix-run/router';
12
12
  export { AbortedDeferredError, Action as NavigationType, createPath, defer, generatePath, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, resolvePath } from '@remix-run/router';
13
13
  import * as React from 'react';
14
14
 
15
- function _extends() {
16
- _extends = Object.assign ? Object.assign.bind() : function (target) {
17
- for (var i = 1; i < arguments.length; i++) {
18
- var source = arguments[i];
19
-
20
- for (var key in source) {
21
- if (Object.prototype.hasOwnProperty.call(source, key)) {
22
- target[key] = source[key];
23
- }
24
- }
25
- }
26
-
27
- return target;
28
- };
29
- return _extends.apply(this, arguments);
30
- }
31
-
32
15
  /**
33
16
  * Copyright (c) Facebook, Inc. and its affiliates.
34
17
  *
@@ -252,6 +235,23 @@ if (process.env.NODE_ENV !== "production") {
252
235
  RouteErrorContext.displayName = "RouteError";
253
236
  }
254
237
 
238
+ function _extends() {
239
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
240
+ for (var i = 1; i < arguments.length; i++) {
241
+ var source = arguments[i];
242
+
243
+ for (var key in source) {
244
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
245
+ target[key] = source[key];
246
+ }
247
+ }
248
+ }
249
+
250
+ return target;
251
+ };
252
+ return _extends.apply(this, arguments);
253
+ }
254
+
255
255
  /**
256
256
  * Returns the full href for the given "to" value. This is useful for building
257
257
  * custom links that are also accessible and preserve right-click behavior.
@@ -379,7 +379,7 @@ function useNavigate() {
379
379
  options = {};
380
380
  }
381
381
 
382
- process.env.NODE_ENV !== "production" ? warning(activeRef.current, "You should call navigate() in a React.useEffect(), not when " + "your component is first rendered.") : void 0;
382
+ process.env.NODE_ENV !== "production" ? UNSAFE_warning(activeRef.current, "You should call navigate() in a React.useEffect(), not when " + "your component is first rendered.") : void 0;
383
383
  if (!activeRef.current) return;
384
384
 
385
385
  if (typeof to === "number") {
@@ -532,8 +532,8 @@ function useRoutes(routes, locationArg) {
532
532
  });
533
533
 
534
534
  if (process.env.NODE_ENV !== "production") {
535
- process.env.NODE_ENV !== "production" ? warning(parentRoute || matches != null, "No routes matched location \"" + location.pathname + location.search + location.hash + "\" ") : void 0;
536
- process.env.NODE_ENV !== "production" ? warning(matches == null || matches[matches.length - 1].route.element !== undefined, "Matched leaf route at location \"" + location.pathname + location.search + location.hash + "\" does not have an element. " + "This means it will render an <Outlet /> with a null value by default resulting in an \"empty\" page.") : void 0;
535
+ process.env.NODE_ENV !== "production" ? UNSAFE_warning(parentRoute || matches != null, "No routes matched location \"" + location.pathname + location.search + location.hash + "\" ") : void 0;
536
+ process.env.NODE_ENV !== "production" ? UNSAFE_warning(matches == null || matches[matches.length - 1].route.element !== undefined || matches[matches.length - 1].route.Component !== undefined, "Matched leaf route at location \"" + location.pathname + location.search + location.hash + "\" " + "does not have an element or Component. This means it will render an <Outlet /> with a " + "null value by default resulting in an \"empty\" page.") : void 0;
537
537
  }
538
538
 
539
539
  let renderedMatches = _renderMatches(matches && matches.map(match => Object.assign({}, match, {
@@ -565,7 +565,7 @@ function useRoutes(routes, locationArg) {
565
565
  return renderedMatches;
566
566
  }
567
567
 
568
- function DefaultErrorElement() {
568
+ function DefaultErrorComponent() {
569
569
  let error = useRouteError();
570
570
  let message = isRouteErrorResponse(error) ? error.status + " " + error.statusText : error instanceof Error ? error.message : JSON.stringify(error);
571
571
  let stack = error instanceof Error ? error.stack : null;
@@ -583,7 +583,7 @@ function DefaultErrorElement() {
583
583
  if (process.env.NODE_ENV !== "production") {
584
584
  devInfo = /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("p", null, "\uD83D\uDCBF Hey developer \uD83D\uDC4B"), /*#__PURE__*/React.createElement("p", null, "You can provide a way better UX than this when your app throws errors by providing your own\xA0", /*#__PURE__*/React.createElement("code", {
585
585
  style: codeStyles
586
- }, "errorElement"), " props on\xA0", /*#__PURE__*/React.createElement("code", {
586
+ }, "ErrorBoundary"), " prop on\xA0", /*#__PURE__*/React.createElement("code", {
587
587
  style: codeStyles
588
588
  }, "<Route>")));
589
589
  }
@@ -662,7 +662,7 @@ function RenderedRoute(_ref) {
662
662
  let dataRouterContext = React.useContext(DataRouterContext); // Track how deep we got in our render pass to emulate SSR componentDidCatch
663
663
  // in a DataStaticRouter
664
664
 
665
- if (dataRouterContext && dataRouterContext.static && dataRouterContext.staticContext && match.route.errorElement) {
665
+ if (dataRouterContext && dataRouterContext.static && dataRouterContext.staticContext && (match.route.errorElement || match.route.ErrorBoundary)) {
666
666
  dataRouterContext.staticContext._deepestRenderedBoundaryId = match.route.id;
667
667
  }
668
668
 
@@ -699,21 +699,45 @@ function _renderMatches(matches, parentMatches, dataRouterState) {
699
699
  return renderedMatches.reduceRight((outlet, match, index) => {
700
700
  let error = match.route.id ? errors == null ? void 0 : errors[match.route.id] : null; // Only data routers handle errors
701
701
 
702
- let errorElement = dataRouterState ? match.route.errorElement || /*#__PURE__*/React.createElement(DefaultErrorElement, null) : null;
702
+ let errorElement = null;
703
+
704
+ if (dataRouterState) {
705
+ if (match.route.ErrorBoundary) {
706
+ errorElement = /*#__PURE__*/React.createElement(match.route.ErrorBoundary, null);
707
+ } else if (match.route.errorElement) {
708
+ errorElement = match.route.errorElement;
709
+ } else {
710
+ errorElement = /*#__PURE__*/React.createElement(DefaultErrorComponent, null);
711
+ }
712
+ }
713
+
703
714
  let matches = parentMatches.concat(renderedMatches.slice(0, index + 1));
704
715
 
705
- let getChildren = () => /*#__PURE__*/React.createElement(RenderedRoute, {
706
- match: match,
707
- routeContext: {
708
- outlet,
709
- matches
716
+ let getChildren = () => {
717
+ let children = outlet;
718
+
719
+ if (error) {
720
+ children = errorElement;
721
+ } else if (match.route.Component) {
722
+ children = /*#__PURE__*/React.createElement(match.route.Component, null);
723
+ } else if (match.route.element) {
724
+ children = match.route.element;
710
725
  }
711
- }, error ? errorElement : match.route.element !== undefined ? match.route.element : outlet); // Only wrap in an error boundary within data router usages when we have an
712
- // errorElement on this route. Otherwise let it bubble up to an ancestor
713
- // errorElement
726
+
727
+ return /*#__PURE__*/React.createElement(RenderedRoute, {
728
+ match: match,
729
+ routeContext: {
730
+ outlet,
731
+ matches
732
+ },
733
+ children: children
734
+ });
735
+ }; // Only wrap in an error boundary within data router usages when we have an
736
+ // ErrorBoundary/errorElement on this route. Otherwise let it bubble up to
737
+ // an ancestor ErrorBoundary/errorElement
714
738
 
715
739
 
716
- return dataRouterState && (match.route.errorElement || index === 0) ? /*#__PURE__*/React.createElement(RenderErrorBoundary, {
740
+ return dataRouterState && (match.route.ErrorBoundary || match.route.errorElement || index === 0) ? /*#__PURE__*/React.createElement(RenderErrorBoundary, {
717
741
  location: dataRouterState.location,
718
742
  component: errorElement,
719
743
  error: error,
@@ -735,6 +759,7 @@ var DataRouterHook;
735
759
  var DataRouterStateHook;
736
760
 
737
761
  (function (DataRouterStateHook) {
762
+ DataRouterStateHook["UseBlocker"] = "useBlocker";
738
763
  DataRouterStateHook["UseLoaderData"] = "useLoaderData";
739
764
  DataRouterStateHook["UseActionData"] = "useActionData";
740
765
  DataRouterStateHook["UseRouteError"] = "useRouteError";
@@ -858,7 +883,7 @@ function useActionData() {
858
883
  /**
859
884
  * Returns the nearest ancestor Route error, which could be a loader/action
860
885
  * error or a render error. This is intended to be called from your
861
- * errorElement to display a proper error message.
886
+ * ErrorBoundary/errorElement to display a proper error message.
862
887
  */
863
888
 
864
889
  function useRouteError() {
@@ -904,21 +929,24 @@ function useBlocker(shouldBlock) {
904
929
  let {
905
930
  router
906
931
  } = useDataRouterContext(DataRouterHook.UseBlocker);
932
+ let state = useDataRouterState(DataRouterStateHook.UseBlocker);
907
933
  let [blockerKey] = React.useState(() => String(++blockerId));
908
934
  let blockerFunction = React.useCallback(args => {
909
935
  return typeof shouldBlock === "function" ? !!shouldBlock(args) : !!shouldBlock;
910
936
  }, [shouldBlock]);
911
937
  let blocker = router.getBlocker(blockerKey, blockerFunction); // Cleanup on unmount
912
938
 
913
- React.useEffect(() => () => router.deleteBlocker(blockerKey), [router, blockerKey]);
914
- return blocker;
939
+ React.useEffect(() => () => router.deleteBlocker(blockerKey), [router, blockerKey]); // Prefer the blocker from state since DataRouterContext is memoized so this
940
+ // ensures we update on blocker state updates
941
+
942
+ return state.blockers.get(blockerKey) || blocker;
915
943
  }
916
944
  const alreadyWarned = {};
917
945
 
918
946
  function warningOnce(key, cond, message) {
919
947
  if (!cond && !alreadyWarned[key]) {
920
948
  alreadyWarned[key] = true;
921
- process.env.NODE_ENV !== "production" ? warning(false, message) : void 0;
949
+ process.env.NODE_ENV !== "production" ? UNSAFE_warning(false, message) : void 0;
922
950
  }
923
951
  }
924
952
 
@@ -930,11 +958,12 @@ function RouterProvider(_ref) {
930
958
  fallbackElement,
931
959
  router
932
960
  } = _ref;
933
- // Sync router state to our component state to force re-renders
934
- let state = useSyncExternalStore(router.subscribe, () => router.state, // We have to provide this so React@18 doesn't complain during hydration,
961
+ let getState = React.useCallback(() => router.state, [router]); // Sync router state to our component state to force re-renders
962
+
963
+ let state = useSyncExternalStore(router.subscribe, getState, // We have to provide this so React@18 doesn't complain during hydration,
935
964
  // but we pass our serialized hydration data into the router so state here
936
965
  // is already synced with what the server saw
937
- () => router.state);
966
+ getState);
938
967
  let navigator = React.useMemo(() => {
939
968
  return {
940
969
  createHref: router.createHref,
@@ -951,7 +980,13 @@ function RouterProvider(_ref) {
951
980
  })
952
981
  };
953
982
  }, [router]);
954
- let basename = router.basename || "/"; // The fragment and {null} here are important! We need them to keep React 18's
983
+ let basename = router.basename || "/";
984
+ let dataRouterContext = React.useMemo(() => ({
985
+ router,
986
+ navigator,
987
+ static: false,
988
+ basename
989
+ }), [router, navigator, basename]); // The fragment and {null} here are important! We need them to keep React 18's
955
990
  // useId happy when we are server-rendering since we may have a <script> here
956
991
  // containing the hydrated server-side staticContext (from StaticRouterProvider).
957
992
  // useId relies on the component tree structure to generate deterministic id's
@@ -959,13 +994,7 @@ function RouterProvider(_ref) {
959
994
  // we don't need the <script> tag
960
995
 
961
996
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DataRouterContext.Provider, {
962
- value: {
963
- router,
964
- navigator,
965
- static: false,
966
- // Do we need this?
967
- basename
968
- }
997
+ value: dataRouterContext
969
998
  }, /*#__PURE__*/React.createElement(DataRouterStateContext.Provider, {
970
999
  value: state
971
1000
  }, /*#__PURE__*/React.createElement(Router, {
@@ -1032,7 +1061,7 @@ function Navigate(_ref3) {
1032
1061
  !useInRouterContext() ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, // TODO: This error is probably because they somehow have 2 versions of
1033
1062
  // the router loaded. We can help them understand how to avoid that.
1034
1063
  "<Navigate> may be used only in the context of a <Router> component.") : UNSAFE_invariant(false) : void 0;
1035
- process.env.NODE_ENV !== "production" ? warning(!React.useContext(NavigationContext).static, "<Navigate> must not be used on the initial render in a <StaticRouter>. " + "This is a no-op, but you should modify your code so the <Navigate> is " + "only ever rendered in response to some user interaction or state change.") : void 0;
1064
+ process.env.NODE_ENV !== "production" ? UNSAFE_warning(!React.useContext(NavigationContext).static, "<Navigate> must not be used on the initial render in a <StaticRouter>. " + "This is a no-op, but you should modify your code so the <Navigate> is " + "only ever rendered in response to some user interaction or state change.") : void 0;
1036
1065
  let dataRouterState = React.useContext(DataRouterStateContext);
1037
1066
  let navigate = useNavigate();
1038
1067
  React.useEffect(() => {
@@ -1109,7 +1138,7 @@ function Router(_ref4) {
1109
1138
  state = null,
1110
1139
  key = "default"
1111
1140
  } = locationProp;
1112
- let location = React.useMemo(() => {
1141
+ let locationContext = React.useMemo(() => {
1113
1142
  let trailingPathname = stripBasename(pathname, basename);
1114
1143
 
1115
1144
  if (trailingPathname == null) {
@@ -1117,16 +1146,19 @@ function Router(_ref4) {
1117
1146
  }
1118
1147
 
1119
1148
  return {
1120
- pathname: trailingPathname,
1121
- search,
1122
- hash,
1123
- state,
1124
- key
1149
+ location: {
1150
+ pathname: trailingPathname,
1151
+ search,
1152
+ hash,
1153
+ state,
1154
+ key
1155
+ },
1156
+ navigationType
1125
1157
  };
1126
- }, [basename, pathname, search, hash, state, key]);
1127
- process.env.NODE_ENV !== "production" ? warning(location != null, "<Router basename=\"" + basename + "\"> is not able to match the URL " + ("\"" + pathname + search + hash + "\" because it does not start with the ") + "basename, so the <Router> won't render anything.") : void 0;
1158
+ }, [basename, pathname, search, hash, state, key, navigationType]);
1159
+ process.env.NODE_ENV !== "production" ? UNSAFE_warning(locationContext != null, "<Router basename=\"" + basename + "\"> is not able to match the URL " + ("\"" + pathname + search + hash + "\" because it does not start with the ") + "basename, so the <Router> won't render anything.") : void 0;
1128
1160
 
1129
- if (location == null) {
1161
+ if (locationContext == null) {
1130
1162
  return null;
1131
1163
  }
1132
1164
 
@@ -1134,10 +1166,7 @@ function Router(_ref4) {
1134
1166
  value: navigationContext
1135
1167
  }, /*#__PURE__*/React.createElement(LocationContext.Provider, {
1136
1168
  children: children,
1137
- value: {
1138
- location,
1139
- navigationType
1140
- }
1169
+ value: locationContext
1141
1170
  }));
1142
1171
  }
1143
1172
 
@@ -1334,14 +1363,17 @@ function createRoutesFromChildren(children, parentPath) {
1334
1363
  id: element.props.id || treePath.join("-"),
1335
1364
  caseSensitive: element.props.caseSensitive,
1336
1365
  element: element.props.element,
1366
+ Component: element.props.Component,
1337
1367
  index: element.props.index,
1338
1368
  path: element.props.path,
1339
1369
  loader: element.props.loader,
1340
1370
  action: element.props.action,
1341
1371
  errorElement: element.props.errorElement,
1342
- hasErrorBoundary: element.props.errorElement != null,
1372
+ ErrorBoundary: element.props.ErrorBoundary,
1373
+ hasErrorBoundary: element.props.ErrorBoundary != null || element.props.errorElement != null,
1343
1374
  shouldRevalidate: element.props.shouldRevalidate,
1344
- handle: element.props.handle
1375
+ handle: element.props.handle,
1376
+ lazy: element.props.lazy
1345
1377
  };
1346
1378
 
1347
1379
  if (element.props.children) {
@@ -1359,26 +1391,21 @@ function createRoutesFromChildren(children, parentPath) {
1359
1391
  function renderMatches(matches) {
1360
1392
  return _renderMatches(matches);
1361
1393
  }
1362
- /**
1363
- * @private
1364
- * Walk the route tree and add hasErrorBoundary if it's not provided, so that
1365
- * users providing manual route arrays can just specify errorElement
1366
- */
1367
-
1368
- function enhanceManualRouteObjects(routes) {
1369
- return routes.map(route => {
1370
- let routeClone = _extends({}, route);
1371
1394
 
1372
- if (routeClone.hasErrorBoundary == null) {
1373
- routeClone.hasErrorBoundary = routeClone.errorElement != null;
1395
+ function detectErrorBoundary(route) {
1396
+ if (process.env.NODE_ENV !== "production") {
1397
+ if (route.Component && route.element) {
1398
+ process.env.NODE_ENV !== "production" ? UNSAFE_warning(false, "You should not include both `Component` and `element` on your route - " + "`element` will be ignored.") : void 0;
1374
1399
  }
1375
1400
 
1376
- if (routeClone.children) {
1377
- routeClone.children = enhanceManualRouteObjects(routeClone.children);
1401
+ if (route.ErrorBoundary && route.errorElement) {
1402
+ process.env.NODE_ENV !== "production" ? UNSAFE_warning(false, "You should not include both `ErrorBoundary` and `errorElement` on your route - " + "`errorElement` will be ignored.") : void 0;
1378
1403
  }
1404
+ } // Note: this check also occurs in createRoutesFromChildren so update
1405
+ // there if you change this
1379
1406
 
1380
- return routeClone;
1381
- });
1407
+
1408
+ return Boolean(route.ErrorBoundary) || Boolean(route.errorElement);
1382
1409
  }
1383
1410
 
1384
1411
  function createMemoryRouter(routes, opts) {
@@ -1389,9 +1416,10 @@ function createMemoryRouter(routes, opts) {
1389
1416
  initialIndex: opts == null ? void 0 : opts.initialIndex
1390
1417
  }),
1391
1418
  hydrationData: opts == null ? void 0 : opts.hydrationData,
1392
- routes: enhanceManualRouteObjects(routes)
1419
+ routes,
1420
+ detectErrorBoundary
1393
1421
  }).initialize();
1394
1422
  } ///////////////////////////////////////////////////////////////////////////////
1395
1423
 
1396
- 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, enhanceManualRouteObjects as UNSAFE_enhanceManualRouteObjects, 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 };
1424
+ 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, detectErrorBoundary as UNSAFE_detectErrorBoundary, 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 };
1397
1425
  //# sourceMappingURL=index.js.map