Skip to content

Commit

Permalink
Stabilize useNavigate/useSubmit/fetcher.submit for data routers (#10336)
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Apr 14, 2023
1 parent 0685cd9 commit dbc9ba3
Show file tree
Hide file tree
Showing 19 changed files with 2,572 additions and 146 deletions.
13 changes: 13 additions & 0 deletions .changeset/fetcher-basename.md
@@ -0,0 +1,13 @@
---
"react-router-dom": minor
"@remix-run/router": minor
---

- Enable relative routing in the `@remix-run/router` when providing a source route ID from which the path is relative to:

- Example: `router.navigate("../path", { fromRouteId: "some-route" })`.
- This also applies to `router.fetch` which already receives a source route ID

- Introduce a new `@remix-run/router` `future.v7_prependBasename` flag to enable `basename` prefixing to all paths coming into `router.navigate` and `router.fetch`.
- 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
- This also enables `basename` support in `useFetcher` as well
6 changes: 6 additions & 0 deletions .changeset/stable-navigate-submit.md
@@ -0,0 +1,6 @@
---
"react-router": patch
"react-router-dom": patch
---

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()`.
10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -105,19 +105,19 @@
},
"filesize": {
"packages/router/dist/router.umd.min.js": {
"none": "44.2 kB"
"none": "45 kB"
},
"packages/react-router/dist/react-router.production.min.js": {
"none": "13.1 kB"
"none": "13.3 kB"
},
"packages/react-router/dist/umd/react-router.production.min.js": {
"none": "15.3 kB"
"none": "15.6 kB"
},
"packages/react-router-dom/dist/react-router-dom.production.min.js": {
"none": "11.6 kB"
"none": "11.8 kB"
},
"packages/react-router-dom/dist/umd/react-router-dom.production.min.js": {
"none": "17.5 kB"
"none": "17.7 kB"
}
}
}
1 change: 1 addition & 0 deletions packages/react-router-dom-v5-compat/index.ts
Expand Up @@ -177,6 +177,7 @@ export {
UNSAFE_DataRouterContext,
UNSAFE_DataRouterStateContext,
UNSAFE_useScrollRestoration,
UNSAFE_useRouteId,
} from "./react-router-dom";

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

0 comments on commit dbc9ba3

Please sign in to comment.