react-router-dom-v5-compat 0.0.0-experimental-c9f8a7b2 → 0.0.0-experimental-e960cf1a

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,171 +1,5 @@
1
1
  # `react-router-dom-v5-compat`
2
2
 
3
- ## 6.21.3
4
-
5
- ### Patch Changes
6
-
7
- - Remove leftover `unstable_` prefix from `Blocker`/`BlockerFunction` types ([#11187](https://github.com/remix-run/react-router/pull/11187))
8
- - Updated dependencies:
9
- - `react-router-dom@6.21.3`
10
- - `react-router@6.21.3`
11
-
12
- ## 6.21.2
13
-
14
- ### Patch Changes
15
-
16
- - Updated dependencies:
17
- - `react-router-dom@6.21.2`
18
- - `react-router@6.21.2`
19
-
20
- ## 6.21.1
21
-
22
- ### Patch Changes
23
-
24
- - Updated dependencies:
25
- - `react-router@6.21.1`
26
- - `react-router-dom@6.21.1`
27
-
28
- ## 6.21.0
29
-
30
- ### Minor Changes
31
-
32
- - 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))
33
-
34
- 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))
35
-
36
- **The Bug**
37
- 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.
38
-
39
- **The Background**
40
- 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:
41
-
42
- ```jsx
43
- <BrowserRouter>
44
- <Routes>
45
- <Route path="/" element={<Home />} />
46
- <Route path="dashboard/*" element={<Dashboard />} />
47
- </Routes>
48
- </BrowserRouter>
49
- ```
50
-
51
- Any paths like `/dashboard`, `/dashboard/team`, `/dashboard/projects` will match the `Dashboard` route. The dashboard component itself can then render nested `<Routes>`:
52
-
53
- ```jsx
54
- function Dashboard() {
55
- return (
56
- <div>
57
- <h2>Dashboard</h2>
58
- <nav>
59
- <Link to="/">Dashboard Home</Link>
60
- <Link to="team">Team</Link>
61
- <Link to="projects">Projects</Link>
62
- </nav>
63
-
64
- <Routes>
65
- <Route path="/" element={<DashboardHome />} />
66
- <Route path="team" element={<DashboardTeam />} />
67
- <Route path="projects" element={<DashboardProjects />} />
68
- </Routes>
69
- </div>
70
- );
71
- }
72
- ```
73
-
74
- 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.
75
-
76
- **The Problem**
77
-
78
- 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 `"."`:
79
-
80
- ```jsx
81
- // If we are on URL /dashboard/team, and we want to link to /dashboard/team:
82
- function DashboardTeam() {
83
- // ❌ This is broken and results in <a href="/dashboard">
84
- return <Link to=".">A broken link to the Current URL</Link>;
85
-
86
- // ✅ This is fixed but super unintuitive since we're already at /dashboard/team!
87
- return <Link to="./team">A broken link to the Current URL</Link>;
88
- }
89
- ```
90
-
91
- 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.
92
-
93
- Even worse, consider a nested splat route configuration:
94
-
95
- ```jsx
96
- <BrowserRouter>
97
- <Routes>
98
- <Route path="dashboard">
99
- <Route path="*" element={<Dashboard />} />
100
- </Route>
101
- </Routes>
102
- </BrowserRouter>
103
- ```
104
-
105
- Now, a `<Link to=".">` and a `<Link to="..">` inside the `Dashboard` component go to the same place! That is definitely not correct!
106
-
107
- 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:
108
-
109
- ```jsx
110
- let router = createBrowserRouter({
111
- path: "/dashboard",
112
- children: [
113
- {
114
- path: "*",
115
- action: dashboardAction,
116
- Component() {
117
- // ❌ This form is broken! It throws a 405 error when it submits because
118
- // it tries to submit to /dashboard (without the splat value) and the parent
119
- // `/dashboard` route doesn't have an action
120
- return <Form method="post">...</Form>;
121
- },
122
- },
123
- ],
124
- });
125
- ```
126
-
127
- 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.
128
-
129
- **The Solution**
130
- 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:
131
-
132
- ```jsx
133
- <BrowserRouter>
134
- <Routes>
135
- <Route path="dashboard">
136
- <Route index path="*" element={<Dashboard />} />
137
- </Route>
138
- </Routes>
139
- </BrowserRouter>
140
-
141
- function Dashboard() {
142
- return (
143
- <div>
144
- <h2>Dashboard</h2>
145
- <nav>
146
- <Link to="..">Dashboard Home</Link>
147
- <Link to="../team">Team</Link>
148
- <Link to="../projects">Projects</Link>
149
- </nav>
150
-
151
- <Routes>
152
- <Route path="/" element={<DashboardHome />} />
153
- <Route path="team" element={<DashboardTeam />} />
154
- <Route path="projects" element={<DashboardProjects />} />
155
- </Router>
156
- </div>
157
- );
158
- }
159
- ```
160
-
161
- 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".
162
-
163
- ### Patch Changes
164
-
165
- - Updated dependencies:
166
- - `react-router-dom@6.21.0`
167
- - `react-router@6.21.0`
168
-
169
3
  ## 6.20.1
170
4
 
171
5
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -46,7 +46,7 @@
46
46
  * would break. We could stop doing two bundles in v6 "react-router-dom" and
47
47
  * deprecate the deep require if we wanted to avoid the duplication here.
48
48
  */
49
- export type { ActionFunction, ActionFunctionArgs, AwaitProps, BrowserRouterProps, DataRouteMatch, DataRouteObject, ErrorResponse, Fetcher, FetcherWithComponents, FormEncType, FormMethod, FormProps, FutureConfig, GetScrollRestorationKeyFunction, Hash, HashRouterProps, HistoryRouterProps, IndexRouteObject, IndexRouteProps, JsonFunction, LayoutRouteProps, LinkProps, LoaderFunction, LoaderFunctionArgs, Location, MemoryRouterProps, NavLinkProps, NavigateFunction, NavigateOptions, NavigateProps, Navigation, Navigator, NonIndexRouteObject, OutletProps, ParamKeyValuePair, ParamParseKey, Params, Path, PathMatch, PathParam, PathPattern, PathRouteProps, Pathname, RedirectFunction, RelativeRoutingType, RouteMatch, RouteObject, RouteProps, RouterProps, RouterProviderProps, RoutesProps, ScrollRestorationProps, Search, ShouldRevalidateFunction, ShouldRevalidateFunctionArgs, SubmitFunction, SubmitOptions, To, URLSearchParamsInit, UIMatch, Blocker, BlockerFunction, } from "./react-router-dom";
49
+ export type { ActionFunction, ActionFunctionArgs, AwaitProps, BrowserRouterProps, DataRouteMatch, DataRouteObject, ErrorResponse, Fetcher, FetcherWithComponents, FormEncType, FormMethod, FormProps, FutureConfig, GetScrollRestorationKeyFunction, Hash, HashRouterProps, HistoryRouterProps, IndexRouteObject, IndexRouteProps, JsonFunction, LayoutRouteProps, LinkProps, LoaderFunction, LoaderFunctionArgs, Location, MemoryRouterProps, NavLinkProps, NavigateFunction, NavigateOptions, NavigateProps, Navigation, Navigator, NonIndexRouteObject, OutletProps, ParamKeyValuePair, ParamParseKey, Params, Path, PathMatch, PathParam, PathPattern, PathRouteProps, Pathname, RedirectFunction, RelativeRoutingType, RouteMatch, RouteObject, RouteProps, RouterProps, RouterProviderProps, RoutesProps, ScrollRestorationProps, Search, ShouldRevalidateFunction, ShouldRevalidateFunctionArgs, SubmitFunction, SubmitOptions, To, URLSearchParamsInit, UIMatch, unstable_Blocker, unstable_BlockerFunction, } from "./react-router-dom";
50
50
  export { AbortedDeferredError, Await, BrowserRouter, Form, HashRouter, Link, MemoryRouter, NavLink, Navigate, NavigationType, Outlet, Route, Router, RouterProvider, Routes, ScrollRestoration, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_LocationContext, UNSAFE_NavigationContext, UNSAFE_RouteContext, UNSAFE_useRouteId, UNSAFE_useScrollRestoration, createBrowserRouter, createHashRouter, createMemoryRouter, createPath, createRoutesFromChildren, createRoutesFromElements, createSearchParams, defer, generatePath, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, redirectDocument, renderMatches, resolvePath, unstable_HistoryRouter, useBlocker, unstable_usePrompt, useActionData, useAsyncError, useAsyncValue, useBeforeUnload, useFetcher, useFetchers, useFormAction, useHref, useInRouterContext, useLinkClickHandler, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes, useSearchParams, useSubmit, } from "./react-router-dom";
51
51
  export type { StaticRouterProps } from "./lib/components";
52
52
  export { CompatRoute, CompatRouter, StaticRouter } from "./lib/components";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * React Router DOM v5 Compat v0.0.0-experimental-c9f8a7b2
2
+ * React Router DOM v5 Compat v0.0.0-experimental-e960cf1a
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -224,7 +224,8 @@ function createBrowserRouter(routes, opts) {
224
224
  hydrationData: (opts == null ? void 0 : opts.hydrationData) || parseHydrationData(),
225
225
  routes,
226
226
  mapRouteProperties: UNSAFE_mapRouteProperties,
227
- window: opts == null ? void 0 : opts.window
227
+ window: opts == null ? void 0 : opts.window,
228
+ unstable_dataStrategy: opts == null ? void 0 : opts.unstable_dataStrategy
228
229
  }).initialize();
229
230
  }
230
231
  function createHashRouter(routes, opts) {
@@ -330,8 +331,6 @@ const START_TRANSITION = "startTransition";
330
331
  const startTransitionImpl = React[START_TRANSITION];
331
332
  const FLUSH_SYNC = "flushSync";
332
333
  const flushSyncImpl = ReactDOM[FLUSH_SYNC];
333
- const USE_ID = "useId";
334
- const useIdImpl = React[USE_ID];
335
334
  function startTransitionSafe(cb) {
336
335
  if (startTransitionImpl) {
337
336
  startTransitionImpl(cb);
@@ -526,7 +525,7 @@ function RouterProvider(_ref) {
526
525
  }
527
526
  }, [vtContext.isTransitioning, interruption]);
528
527
  React.useEffect(() => {
529
- 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;
528
+ process.env.NODE_ENV !== "production" ? UNSAFE_warning(fallbackElement == null || !router.future.v7_partialHydration, "`<RouterProvider fallbackElement>` is deprecated when using `v7_partialHydration`") : void 0;
530
529
  // Only log this once on initial mount
531
530
  // eslint-disable-next-line react-hooks/exhaustive-deps
532
531
  }, []);
@@ -551,7 +550,10 @@ function RouterProvider(_ref) {
551
550
  router,
552
551
  navigator,
553
552
  static: false,
554
- basename
553
+ basename,
554
+ future: {
555
+ v7_relativeSplatPath: router.future.v7_relativeSplatPath
556
+ }
555
557
  }), [router, navigator, basename]);
556
558
  // The fragment and {null} here are important! We need them to keep React 18's
557
559
  // useId happy when we are server-rendering since we may have a <script> here
@@ -571,11 +573,8 @@ function RouterProvider(_ref) {
571
573
  basename: basename,
572
574
  location: state.location,
573
575
  navigationType: state.historyAction,
574
- navigator: navigator,
575
- future: {
576
- v7_relativeSplatPath: router.future.v7_relativeSplatPath
577
- }
578
- }, state.initialized || router.future.v7_partialHydration ? /*#__PURE__*/React.createElement(DataRoutes, {
576
+ navigator: navigator
577
+ }, state.initialized ? /*#__PURE__*/React.createElement(DataRoutes, {
579
578
  routes: router.routes,
580
579
  future: router.future,
581
580
  state: state
@@ -800,8 +799,7 @@ const NavLink = /*#__PURE__*/React.forwardRef(function NavLinkWithRef(_ref8, ref
800
799
  let location = useLocation();
801
800
  let routerState = React.useContext(UNSAFE_DataRouterStateContext);
802
801
  let {
803
- navigator,
804
- basename
802
+ navigator
805
803
  } = React.useContext(UNSAFE_NavigationContext);
806
804
  let isTransitioning = routerState != null &&
807
805
  // Conditional usage is OK here because the usage of a data router is static
@@ -815,9 +813,6 @@ const NavLink = /*#__PURE__*/React.forwardRef(function NavLinkWithRef(_ref8, ref
815
813
  nextLocationPathname = nextLocationPathname ? nextLocationPathname.toLowerCase() : null;
816
814
  toPathname = toPathname.toLowerCase();
817
815
  }
818
- if (nextLocationPathname && basename) {
819
- nextLocationPathname = stripBasename(nextLocationPathname, basename) || nextLocationPathname;
820
- }
821
816
  // If the `to` has a trailing slash, look at that exact spot. Otherwise,
822
817
  // we're looking for a slash _after_ what's in `to`. For example:
823
818
  //
@@ -1141,14 +1136,10 @@ function useFetcher(_temp3) {
1141
1136
  !route ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "useFetcher must be used inside a RouteContext") : UNSAFE_invariant(false) : void 0;
1142
1137
  !(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;
1143
1138
  // Fetcher key handling
1144
- // OK to call conditionally to feature detect `useId`
1145
- // eslint-disable-next-line react-hooks/rules-of-hooks
1146
- let defaultKey = useIdImpl ? useIdImpl() : "";
1147
- let [fetcherKey, setFetcherKey] = React.useState(key || defaultKey);
1139
+ let [fetcherKey, setFetcherKey] = React.useState(key || "");
1148
1140
  if (key && key !== fetcherKey) {
1149
1141
  setFetcherKey(key);
1150
1142
  } else if (!fetcherKey) {
1151
- // We will only fall through here when `useId` is not available
1152
1143
  setFetcherKey(getUniqueFetcherId());
1153
1144
  }
1154
1145
  // Registration/cleanup