react-router-dom 0.0.0-experimental-35fa15e5 → 0.0.0-experimental-8bb3ffdf

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,167 @@
1
1
  # `react-router-dom`
2
2
 
3
+ ## 6.21.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 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))
8
+
9
+ 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))
10
+
11
+ **The Bug**
12
+ 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.
13
+
14
+ **The Background**
15
+ 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:
16
+
17
+ ```jsx
18
+ <BrowserRouter>
19
+ <Routes>
20
+ <Route path="/" element={<Home />} />
21
+ <Route path="dashboard/*" element={<Dashboard />} />
22
+ </Routes>
23
+ </BrowserRouter>
24
+ ```
25
+
26
+ Any paths like `/dashboard`, `/dashboard/team`, `/dashboard/projects` will match the `Dashboard` route. The dashboard component itself can then render nested `<Routes>`:
27
+
28
+ ```jsx
29
+ function Dashboard() {
30
+ return (
31
+ <div>
32
+ <h2>Dashboard</h2>
33
+ <nav>
34
+ <Link to="/">Dashboard Home</Link>
35
+ <Link to="team">Team</Link>
36
+ <Link to="projects">Projects</Link>
37
+ </nav>
38
+
39
+ <Routes>
40
+ <Route path="/" element={<DashboardHome />} />
41
+ <Route path="team" element={<DashboardTeam />} />
42
+ <Route path="projects" element={<DashboardProjects />} />
43
+ </Routes>
44
+ </div>
45
+ );
46
+ }
47
+ ```
48
+
49
+ 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.
50
+
51
+ **The Problem**
52
+
53
+ 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 `"."`:
54
+
55
+ ```jsx
56
+ // If we are on URL /dashboard/team, and we want to link to /dashboard/team:
57
+ function DashboardTeam() {
58
+ // ❌ This is broken and results in <a href="/dashboard">
59
+ return <Link to=".">A broken link to the Current URL</Link>;
60
+
61
+ // ✅ This is fixed but super unintuitive since we're already at /dashboard/team!
62
+ return <Link to="./team">A broken link to the Current URL</Link>;
63
+ }
64
+ ```
65
+
66
+ 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.
67
+
68
+ Even worse, consider a nested splat route configuration:
69
+
70
+ ```jsx
71
+ <BrowserRouter>
72
+ <Routes>
73
+ <Route path="dashboard">
74
+ <Route path="*" element={<Dashboard />} />
75
+ </Route>
76
+ </Routes>
77
+ </BrowserRouter>
78
+ ```
79
+
80
+ Now, a `<Link to=".">` and a `<Link to="..">` inside the `Dashboard` component go to the same place! That is definitely not correct!
81
+
82
+ 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:
83
+
84
+ ```jsx
85
+ let router = createBrowserRouter({
86
+ path: "/dashboard",
87
+ children: [
88
+ {
89
+ path: "*",
90
+ action: dashboardAction,
91
+ Component() {
92
+ // ❌ This form is broken! It throws a 405 error when it submits because
93
+ // it tries to submit to /dashboard (without the splat value) and the parent
94
+ // `/dashboard` route doesn't have an action
95
+ return <Form method="post">...</Form>;
96
+ },
97
+ },
98
+ ],
99
+ });
100
+ ```
101
+
102
+ 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.
103
+
104
+ **The Solution**
105
+ 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:
106
+
107
+ ```jsx
108
+ <BrowserRouter>
109
+ <Routes>
110
+ <Route path="dashboard">
111
+ <Route path="*" element={<Dashboard />} />
112
+ </Route>
113
+ </Routes>
114
+ </BrowserRouter>
115
+
116
+ function Dashboard() {
117
+ return (
118
+ <div>
119
+ <h2>Dashboard</h2>
120
+ <nav>
121
+ <Link to="..">Dashboard Home</Link>
122
+ <Link to="../team">Team</Link>
123
+ <Link to="../projects">Projects</Link>
124
+ </nav>
125
+
126
+ <Routes>
127
+ <Route path="/" element={<DashboardHome />} />
128
+ <Route path="team" element={<DashboardTeam />} />
129
+ <Route path="projects" element={<DashboardProjects />} />
130
+ </Router>
131
+ </div>
132
+ );
133
+ }
134
+ ```
135
+
136
+ 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".
137
+
138
+ ### Patch Changes
139
+
140
+ - Updated dependencies:
141
+ - `@remix-run/router@1.14.0`
142
+ - `react-router@6.21.0`
143
+
144
+ ## 6.20.1
145
+
146
+ ### Patch Changes
147
+
148
+ - 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))
149
+ - Updated dependencies:
150
+ - `react-router@6.20.1`
151
+ - `@remix-run/router@1.13.1`
152
+
153
+ ## 6.20.0
154
+
155
+ ### Minor Changes
156
+
157
+ - Export the `PathParam` type from the public API ([#10719](https://github.com/remix-run/react-router/pull/10719))
158
+
159
+ ### Patch Changes
160
+
161
+ - Updated dependencies:
162
+ - `react-router@6.20.0`
163
+ - `@remix-run/router@1.13.0`
164
+
3
165
  ## 6.19.0
4
166
 
5
167
  ### Minor Changes
@@ -238,7 +400,7 @@
238
400
 
239
401
  ## 6.12.1
240
402
 
241
- > **Warning**
403
+ > [!WARNING]
242
404
  > 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.
243
405
 
244
406
  ### Patch Changes
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, 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, 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";
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-35fa15e5
2
+ * React Router DOM v0.0.0-experimental-8bb3ffdf
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -522,7 +522,7 @@ function RouterProvider(_ref) {
522
522
  }
523
523
  }, [vtContext.isTransitioning, interruption]);
524
524
  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;
525
+ 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
526
  // Only log this once on initial mount
527
527
  // eslint-disable-next-line react-hooks/exhaustive-deps
528
528
  }, []);
@@ -567,8 +567,11 @@ function RouterProvider(_ref) {
567
567
  basename: basename,
568
568
  location: state.location,
569
569
  navigationType: state.historyAction,
570
- navigator: navigator
571
- }, state.initialized ? /*#__PURE__*/React.createElement(DataRoutes, {
570
+ navigator: navigator,
571
+ future: {
572
+ v7_relativeSplatPath: router.future.v7_relativeSplatPath
573
+ }
574
+ }, state.initialized || router.future.v7_partialHydration ? /*#__PURE__*/React.createElement(DataRoutes, {
572
575
  routes: router.routes,
573
576
  future: router.future,
574
577
  state: state
@@ -616,7 +619,8 @@ function BrowserRouter(_ref4) {
616
619
  children: children,
617
620
  location: state.location,
618
621
  navigationType: state.action,
619
- navigator: history
622
+ navigator: history,
623
+ future: future
620
624
  });
621
625
  }
622
626
  /**
@@ -654,7 +658,8 @@ function HashRouter(_ref5) {
654
658
  children: children,
655
659
  location: state.location,
656
660
  navigationType: state.action,
657
- navigator: history
661
+ navigator: history,
662
+ future: future
658
663
  });
659
664
  }
660
665
  /**
@@ -686,7 +691,8 @@ function HistoryRouter(_ref6) {
686
691
  children: children,
687
692
  location: state.location,
688
693
  navigationType: state.action,
689
- navigator: history
694
+ navigator: history,
695
+ future: future
690
696
  });
691
697
  }
692
698
  if (process.env.NODE_ENV !== "production") {