react-router-dom 0.0.0-experimental-9463fb5e → 0.0.0-experimental-d90c8fb3

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,10 +1,168 @@
1
1
  # `react-router-dom`
2
2
 
3
+ ## 6.21.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Leverage `useId` for internal fetcher keys when available ([#11166](https://github.com/remix-run/react-router/pull/11166))
8
+ - Updated dependencies:
9
+ - `@remix-run/router@1.14.2`
10
+ - `react-router@6.21.2`
11
+
12
+ ## 6.21.1
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies:
17
+ - `react-router@6.21.1`
18
+ - `@remix-run/router@1.14.1`
19
+
20
+ ## 6.21.0
21
+
22
+ ### Minor Changes
23
+
24
+ - Add a new `future.v7_relativeSplatPath` flag to implement a breaking bug fix to relative routing when inside a splat route. ([#11087](https://github.com/remix-run/react-router/pull/11087))
25
+
26
+ This fix was originally added in [#10983](https://github.com/remix-run/react-router/issues/10983) and was later reverted in [#11078](https://github.com/remix-run/react-router/pull/11078) because it was determined that a large number of existing applications were relying on the buggy behavior (see [#11052](https://github.com/remix-run/react-router/issues/11052))
27
+
28
+ **The Bug**
29
+ The buggy behavior is that without this flag, the default behavior when resolving relative paths is to _ignore_ any splat (`*`) portion of the current route path.
30
+
31
+ **The Background**
32
+ This decision was originally made thinking that it would make the concept of nested different sections of your apps in `<Routes>` easier if relative routing would _replace_ the current splat:
33
+
34
+ ```jsx
35
+ <BrowserRouter>
36
+ <Routes>
37
+ <Route path="/" element={<Home />} />
38
+ <Route path="dashboard/*" element={<Dashboard />} />
39
+ </Routes>
40
+ </BrowserRouter>
41
+ ```
42
+
43
+ Any paths like `/dashboard`, `/dashboard/team`, `/dashboard/projects` will match the `Dashboard` route. The dashboard component itself can then render nested `<Routes>`:
44
+
45
+ ```jsx
46
+ function Dashboard() {
47
+ return (
48
+ <div>
49
+ <h2>Dashboard</h2>
50
+ <nav>
51
+ <Link to="/">Dashboard Home</Link>
52
+ <Link to="team">Team</Link>
53
+ <Link to="projects">Projects</Link>
54
+ </nav>
55
+
56
+ <Routes>
57
+ <Route path="/" element={<DashboardHome />} />
58
+ <Route path="team" element={<DashboardTeam />} />
59
+ <Route path="projects" element={<DashboardProjects />} />
60
+ </Routes>
61
+ </div>
62
+ );
63
+ }
64
+ ```
65
+
66
+ Now, all links and route paths are relative to the router above them. This makes code splitting and compartmentalizing your app really easy. You could render the `Dashboard` as its own independent app, or embed it into your large app without making any changes to it.
67
+
68
+ **The Problem**
69
+
70
+ The problem is that this concept of ignoring part of a path breaks a lot of other assumptions in React Router - namely that `"."` always means the current location pathname for that route. When we ignore the splat portion, we start getting invalid paths when using `"."`:
71
+
72
+ ```jsx
73
+ // If we are on URL /dashboard/team, and we want to link to /dashboard/team:
74
+ function DashboardTeam() {
75
+ // ❌ This is broken and results in <a href="/dashboard">
76
+ return <Link to=".">A broken link to the Current URL</Link>;
77
+
78
+ // ✅ This is fixed but super unintuitive since we're already at /dashboard/team!
79
+ return <Link to="./team">A broken link to the Current URL</Link>;
80
+ }
81
+ ```
82
+
83
+ We've also introduced an issue that we can no longer move our `DashboardTeam` component around our route hierarchy easily - since it behaves differently if we're underneath a non-splat route, such as `/dashboard/:widget`. Now, our `"."` links will, properly point to ourself _inclusive of the dynamic param value_ so behavior will break from it's corresponding usage in a `/dashboard/*` route.
84
+
85
+ Even worse, consider a nested splat route configuration:
86
+
87
+ ```jsx
88
+ <BrowserRouter>
89
+ <Routes>
90
+ <Route path="dashboard">
91
+ <Route path="*" element={<Dashboard />} />
92
+ </Route>
93
+ </Routes>
94
+ </BrowserRouter>
95
+ ```
96
+
97
+ Now, a `<Link to=".">` and a `<Link to="..">` inside the `Dashboard` component go to the same place! That is definitely not correct!
98
+
99
+ Another common issue arose in Data Routers (and Remix) where any `<Form>` should post to it's own route `action` if you the user doesn't specify a form action:
100
+
101
+ ```jsx
102
+ let router = createBrowserRouter({
103
+ path: "/dashboard",
104
+ children: [
105
+ {
106
+ path: "*",
107
+ action: dashboardAction,
108
+ Component() {
109
+ // ❌ This form is broken! It throws a 405 error when it submits because
110
+ // it tries to submit to /dashboard (without the splat value) and the parent
111
+ // `/dashboard` route doesn't have an action
112
+ return <Form method="post">...</Form>;
113
+ },
114
+ },
115
+ ],
116
+ });
117
+ ```
118
+
119
+ This is just a compounded issue from the above because the default location for a `Form` to submit to is itself (`"."`) - and if we ignore the splat portion, that now resolves to the parent route.
120
+
121
+ **The Solution**
122
+ If you are leveraging this behavior, it's recommended to enable the future flag, move your splat to it's own route, and leverage `../` for any links to "sibling" pages:
123
+
124
+ ```jsx
125
+ <BrowserRouter>
126
+ <Routes>
127
+ <Route path="dashboard">
128
+ <Route index path="*" element={<Dashboard />} />
129
+ </Route>
130
+ </Routes>
131
+ </BrowserRouter>
132
+
133
+ function Dashboard() {
134
+ return (
135
+ <div>
136
+ <h2>Dashboard</h2>
137
+ <nav>
138
+ <Link to="..">Dashboard Home</Link>
139
+ <Link to="../team">Team</Link>
140
+ <Link to="../projects">Projects</Link>
141
+ </nav>
142
+
143
+ <Routes>
144
+ <Route path="/" element={<DashboardHome />} />
145
+ <Route path="team" element={<DashboardTeam />} />
146
+ <Route path="projects" element={<DashboardProjects />} />
147
+ </Router>
148
+ </div>
149
+ );
150
+ }
151
+ ```
152
+
153
+ This way, `.` means "the full current pathname for my route" in all cases (including static, dynamic, and splat routes) and `..` always means "my parents pathname".
154
+
155
+ ### Patch Changes
156
+
157
+ - Updated dependencies:
158
+ - `@remix-run/router@1.14.0`
159
+ - `react-router@6.21.0`
160
+
3
161
  ## 6.20.1
4
162
 
5
163
  ### Patch Changes
6
164
 
7
- - Revert the `useResolvedPath` fix for splat routes due to a large number of applications that were relying on the buggy behavior (see https://github.com/remix-run/react-router/issues/11052#issuecomment-1836589329). We plan to re-introduce this fix behind a future flag in the next minor version. ([#11078](https://github.com/remix-run/react-router/pull/11078))
165
+ - Revert the `useResolvedPath` fix for splat routes due to a large number of applications that were relying on the buggy behavior (see <https://github.com/remix-run/react-router/issues/11052#issuecomment-1836589329>). We plan to re-introduce this fix behind a future flag in the next minor version. ([#11078](https://github.com/remix-run/react-router/pull/11078))
8
166
  - Updated dependencies:
9
167
  - `react-router@6.20.1`
10
168
  - `@remix-run/router@1.13.1`
@@ -259,7 +417,7 @@
259
417
 
260
418
  ## 6.12.1
261
419
 
262
- > [!WARNING]
420
+ > \[!WARNING]
263
421
  > 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.
264
422
 
265
423
  ### Patch Changes
@@ -594,7 +752,7 @@
594
752
 
595
753
  ## 6.4.0
596
754
 
597
- Whoa this is a big one! `6.4.0` brings all the data loading and mutation APIs over from Remix. Here's a quick high level overview, but it's recommended you go check out the [docs][rr-docs], especially the [feature overview][rr-feature-overview] and the [tutorial][rr-tutorial].
755
+ Whoa this is a big one! `6.4.0` brings all the data loading and mutation APIs over from Remix. Here's a quick high level overview, but it's recommended you go check out the [docs](https://reactrouter.com), especially the [feature overview](https://reactrouter.com/start/overview) and the [tutorial](https://reactrouter.com/start/tutorial).
598
756
 
599
757
  **New APIs**
600
758
 
@@ -620,7 +778,3 @@ Whoa this is a big one! `6.4.0` brings all the data loading and mutation APIs ov
620
778
  **Updated Dependencies**
621
779
 
622
780
  - `react-router@6.4.0`
623
-
624
- [rr-docs]: https://reactrouter.com
625
- [rr-feature-overview]: https://reactrouter.com/start/overview
626
- [rr-tutorial]: https://reactrouter.com/start/tutorial
package/dist/index.d.ts CHANGED
@@ -9,7 +9,7 @@ import type { SubmitOptions, ParamKeyValuePair, URLSearchParamsInit, SubmitTarge
9
9
  import { createSearchParams } from "./dom";
10
10
  export type { FormEncType, FormMethod, GetScrollRestorationKeyFunction, ParamKeyValuePair, SubmitOptions, URLSearchParamsInit, V7_FormMethod, };
11
11
  export { createSearchParams };
12
- export type { ActionFunction, ActionFunctionArgs, AwaitProps, unstable_Blocker, unstable_BlockerFunction, DataRouteMatch, DataRouteObject, ErrorResponse, Fetcher, FutureConfig, Hash, IndexRouteObject, IndexRouteProps, JsonFunction, LazyRouteFunction, LayoutRouteProps, LoaderFunction, LoaderFunctionArgs, Location, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, Navigation, Navigator, NonIndexRouteObject, OutletProps, Params, ParamParseKey, Path, PathMatch, Pathname, PathParam, PathPattern, PathRouteProps, RedirectFunction, RelativeRoutingType, RouteMatch, RouteObject, RouteProps, RouterProps, RouterProviderProps, RoutesProps, Search, ShouldRevalidateFunction, ShouldRevalidateFunctionArgs, To, UIMatch, } from "react-router";
12
+ export type { ActionFunction, ActionFunctionArgs, AwaitProps, Blocker, BlockerFunction, DataRouteMatch, DataRouteObject, ErrorResponse, Fetcher, FutureConfig, Hash, IndexRouteObject, IndexRouteProps, JsonFunction, LazyRouteFunction, LayoutRouteProps, LoaderFunction, LoaderFunctionArgs, Location, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, Navigation, Navigator, NonIndexRouteObject, OutletProps, Params, ParamParseKey, Path, PathMatch, Pathname, PathParam, PathPattern, PathRouteProps, RedirectFunction, RelativeRoutingType, RouteMatch, RouteObject, RouteProps, RouterProps, RouterProviderProps, RoutesProps, Search, ShouldRevalidateFunction, ShouldRevalidateFunctionArgs, To, UIMatch, } from "react-router";
13
13
  export { AbortedDeferredError, Await, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, Routes, createMemoryRouter, createPath, createRoutesFromChildren, createRoutesFromElements, defer, isRouteErrorResponse, generatePath, json, matchPath, matchRoutes, parsePath, redirect, redirectDocument, renderMatches, resolvePath, useActionData, useAsyncError, useAsyncValue, useBlocker, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes, } from "react-router";
14
14
  /** @internal */
15
15
  export { UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_NavigationContext, UNSAFE_LocationContext, UNSAFE_RouteContext, UNSAFE_useRouteId, } from "react-router";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * React Router DOM v0.0.0-experimental-9463fb5e
2
+ * React Router DOM v0.0.0-experimental-d90c8fb3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -328,6 +328,8 @@ const START_TRANSITION = "startTransition";
328
328
  const startTransitionImpl = React[START_TRANSITION];
329
329
  const FLUSH_SYNC = "flushSync";
330
330
  const flushSyncImpl = ReactDOM[FLUSH_SYNC];
331
+ const USE_ID = "useId";
332
+ const useIdImpl = React[USE_ID];
331
333
  function startTransitionSafe(cb) {
332
334
  if (startTransitionImpl) {
333
335
  startTransitionImpl(cb);
@@ -522,7 +524,7 @@ function RouterProvider(_ref) {
522
524
  }
523
525
  }, [vtContext.isTransitioning, interruption]);
524
526
  React.useEffect(() => {
525
- process.env.NODE_ENV !== "production" ? UNSAFE_warning(fallbackElement == null || !router.future.v7_partialHydration, "`<RouterProvider fallbackElement>` is deprecated when using `v7_partialHydration`") : void 0;
527
+ process.env.NODE_ENV !== "production" ? UNSAFE_warning(fallbackElement == null || !router.future.v7_partialHydration, "`<RouterProvider fallbackElement>` is deprecated when using " + "`v7_partialHydration`, use a `HydrateFallback` component instead") : void 0;
526
528
  // Only log this once on initial mount
527
529
  // eslint-disable-next-line react-hooks/exhaustive-deps
528
530
  }, []);
@@ -547,10 +549,7 @@ function RouterProvider(_ref) {
547
549
  router,
548
550
  navigator,
549
551
  static: false,
550
- basename,
551
- future: {
552
- v7_relativeSplatPath: router.future.v7_relativeSplatPath
553
- }
552
+ basename
554
553
  }), [router, navigator, basename]);
555
554
  // The fragment and {null} here are important! We need them to keep React 18's
556
555
  // useId happy when we are server-rendering since we may have a <script> here
@@ -570,8 +569,11 @@ function RouterProvider(_ref) {
570
569
  basename: basename,
571
570
  location: state.location,
572
571
  navigationType: state.historyAction,
573
- navigator: navigator
574
- }, state.initialized ? /*#__PURE__*/React.createElement(DataRoutes, {
572
+ navigator: navigator,
573
+ future: {
574
+ v7_relativeSplatPath: router.future.v7_relativeSplatPath
575
+ }
576
+ }, state.initialized || router.future.v7_partialHydration ? /*#__PURE__*/React.createElement(DataRoutes, {
575
577
  routes: router.routes,
576
578
  future: router.future,
577
579
  state: state
@@ -796,7 +798,8 @@ const NavLink = /*#__PURE__*/React.forwardRef(function NavLinkWithRef(_ref8, ref
796
798
  let location = useLocation();
797
799
  let routerState = React.useContext(UNSAFE_DataRouterStateContext);
798
800
  let {
799
- navigator
801
+ navigator,
802
+ basename
800
803
  } = React.useContext(UNSAFE_NavigationContext);
801
804
  let isTransitioning = routerState != null &&
802
805
  // Conditional usage is OK here because the usage of a data router is static
@@ -810,6 +813,9 @@ const NavLink = /*#__PURE__*/React.forwardRef(function NavLinkWithRef(_ref8, ref
810
813
  nextLocationPathname = nextLocationPathname ? nextLocationPathname.toLowerCase() : null;
811
814
  toPathname = toPathname.toLowerCase();
812
815
  }
816
+ if (nextLocationPathname && basename) {
817
+ nextLocationPathname = stripBasename(nextLocationPathname, basename) || nextLocationPathname;
818
+ }
813
819
  // If the `to` has a trailing slash, look at that exact spot. Otherwise,
814
820
  // we're looking for a slash _after_ what's in `to`. For example:
815
821
  //
@@ -1133,10 +1139,14 @@ function useFetcher(_temp3) {
1133
1139
  !route ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "useFetcher must be used inside a RouteContext") : UNSAFE_invariant(false) : void 0;
1134
1140
  !(routeId != null) ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "useFetcher can only be used on routes that contain a unique \"id\"") : UNSAFE_invariant(false) : void 0;
1135
1141
  // Fetcher key handling
1136
- let [fetcherKey, setFetcherKey] = React.useState(key || "");
1142
+ // OK to call conditionally to feature detect `useId`
1143
+ // eslint-disable-next-line react-hooks/rules-of-hooks
1144
+ let defaultKey = useIdImpl ? useIdImpl() : "";
1145
+ let [fetcherKey, setFetcherKey] = React.useState(key || defaultKey);
1137
1146
  if (key && key !== fetcherKey) {
1138
1147
  setFetcherKey(key);
1139
1148
  } else if (!fetcherKey) {
1149
+ // We will only fall through here when `useId` is not available
1140
1150
  setFetcherKey(getUniqueFetcherId());
1141
1151
  }
1142
1152
  // Registration/cleanup