Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize useNavigate/useSubmit/fetcher.submit for data routers #10336

Merged
merged 22 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .changeset/fetcher-basename.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,19 @@
},
"filesize": {
"packages/router/dist/router.umd.min.js": {
"none": "44.1 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
Original file line number Diff line number Diff line change
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
Loading