Skip to content

Commit dbc9ba3

Browse files
authored
Stabilize useNavigate/useSubmit/fetcher.submit for data routers (#10336)
1 parent 0685cd9 commit dbc9ba3

File tree

19 files changed

+2572
-146
lines changed

19 files changed

+2572
-146
lines changed

.changeset/fetcher-basename.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"react-router-dom": minor
3+
"@remix-run/router": minor
4+
---
5+
6+
- Enable relative routing in the `@remix-run/router` when providing a source route ID from which the path is relative to:
7+
8+
- Example: `router.navigate("../path", { fromRouteId: "some-route" })`.
9+
- This also applies to `router.fetch` which already receives a source route ID
10+
11+
- Introduce a new `@remix-run/router` `future.v7_prependBasename` flag to enable `basename` prefixing to all paths coming into `router.navigate` and `router.fetch`.
12+
- Previously the `basename` was prepended in the React Router layer, but now that relative routing is being handled by the router we need prepend the `basename` _after_ resolving any relative paths
13+
- This also enables `basename` support in `useFetcher` as well

.changeset/stable-navigate-submit.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"react-router": patch
3+
"react-router-dom": patch
4+
---
5+
6+
When using a `RouterProvider`, `useNavigate`/`useSubmit`/`fetcher.submit` are now stable across location changes, since we can handle relative routing via the `@remix-run/router` instance and get rid of our dependence on `useLocation()`. When using `BrowserRouter`, these hooks remain unstable across location changes because they still rely on `useLocation()`.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,19 @@
105105
},
106106
"filesize": {
107107
"packages/router/dist/router.umd.min.js": {
108-
"none": "44.2 kB"
108+
"none": "45 kB"
109109
},
110110
"packages/react-router/dist/react-router.production.min.js": {
111-
"none": "13.1 kB"
111+
"none": "13.3 kB"
112112
},
113113
"packages/react-router/dist/umd/react-router.production.min.js": {
114-
"none": "15.3 kB"
114+
"none": "15.6 kB"
115115
},
116116
"packages/react-router-dom/dist/react-router-dom.production.min.js": {
117-
"none": "11.6 kB"
117+
"none": "11.8 kB"
118118
},
119119
"packages/react-router-dom/dist/umd/react-router-dom.production.min.js": {
120-
"none": "17.5 kB"
120+
"none": "17.7 kB"
121121
}
122122
}
123123
}

packages/react-router-dom-v5-compat/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ export {
177177
UNSAFE_DataRouterContext,
178178
UNSAFE_DataRouterStateContext,
179179
UNSAFE_useScrollRestoration,
180+
UNSAFE_useRouteId,
180181
} from "./react-router-dom";
181182

182183
export type { StaticRouterProps } from "./lib/components";

0 commit comments

Comments
 (0)