Add support for React router v8#11289
Conversation
|
Thanks for your PR, but U'm not fan of the extra compatibility layer & the partial reimplementation. I'd prefer if you created an entirely new adapter for react-router v8 (in a new package). We'd probably need to move the current routing adapter to a package, too. |
React Router v8 merged react-router-dom into react-router and requires React 19. Rather than adding a compatibility layer and partial reimplementation inside ra-core (per review feedback on marmelab#11289), v8 support ships as a standalone, opt-in adapter package mirroring ra-router-tanstack. The adapter is a thin pass-through over react-router v8's native API: the obsolete v6/v7 `future` flags are dropped (now defaults in v8) and imports come from `react-router` instead of `react-router-dom`. ra-core keeps its built-in react-router v6/v7 adapter as the default, so existing apps are unaffected. The package is ESM-only because react-router v8 is ESM-only. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
After merging the ra-router-react-router-v8 package, the in-core react-router adapter no longer needs the compatibility shims: - reactRouterProvider imports everything from `react-router`, with only `Link` and `createHashRouter` from `react-router-dom` - Form.stories uses `HashRouter` from `react-router-dom` directly - Remove CompatHashRouter, CompatLink and their tests - Restore `react-router-dom` to the dependencies of ra-core, ra-ui-materialui and react-admin, and narrow the react-router range back to ^6.28.1 || ^7.1.1 (v8 is supported via the separate package) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
No code in ra-ui-materialui imports react-router-dom; all routing imports come from react-router. ra-core declares its own react-router-dom peer for its router adapter. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Individual zshy builds had rewritten the exports field to the flat pre-normalization form. Restore the nested import/require form that update-package-exports produces and that matches upstream. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…-exports update-package-exports forces dual import/require exports on every package; the ESM-only v8 adapter must keep its ESM-only exports (it has no .cjs build). Also keep minor README/story/doc wording. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
zshy's ESM build pass already uses Bundler resolution and cjs is disabled, so these compilerOptions are not needed for the build. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Hi @fzaninotto The ra-router-react-router-v8 is pulled out to a separate package |
fzaninotto
left a comment
There was a problem hiding this comment.
Thanks. Several remarks:
- This is a new feature, so it must be PRed against
nextand notmaster - As RR v7 is still loaded by default by ra-core, users of RRv8 will end up with 2 versions of RR, leading to probable context conflicts. You also need to extract the default RRv7 adapter to a package in the monorepo
- The new RRv8 adapter needs unit tests in addition to user stories
- you also need to test the basename feature (check the tests of the tanstack router adapter)
| </li> | ||
| ))} | ||
| </ul> | ||
| <button onClick={() => navigate('/posts/create')}> |
There was a problem hiding this comment.
why not use test-ui's CreateButton?
| const { id } = useParams<{ id: string }>(); | ||
| return ( | ||
| <ShowBase resource="posts" id={id}> | ||
| <PostShowView onEdit={() => navigate(`/posts/${id}`)} /> |
There was a problem hiding this comment.
Why do you need a specific onEdit? It should work without it.
| ); | ||
| }; | ||
|
|
||
| const PostShowView = ({ onEdit }: { onEdit: () => void }) => { |
There was a problem hiding this comment.
Use test-ui's SimpleShowLayout
| }; | ||
|
|
||
| const PostEdit = () => { | ||
| const { id } = useParams<{ id: string }>(); |
There was a problem hiding this comment.
This should not be nevessary, EditBase already reads the route params
| <ListBase | ||
| resource="comments" | ||
| render={({ data }) => ( | ||
| <ul> |
| * BasicStandalone: react-admin runs on its own hash router created by the | ||
| * react-router v8 provider (no surrounding router). | ||
| */ | ||
| export const BasicStandalone = () => ( |
There was a problem hiding this comment.
by convention, the most basic story is called Basic in ra
| dataProvider={dataProvider} | ||
| layout={Layout} | ||
| > | ||
| <Resource name="posts" list={PostList} show={PostShow} /> |
There was a problem hiding this comment.
to test the Link component, I suggest you use custom routes and no resource
| layout={Layout} | ||
| > | ||
| <CustomRoutes> | ||
| <Route path="/" element={<RedirectToPosts />} /> |
There was a problem hiding this comment.
This is already the default behavior of react-admin (redirecting to the first resourc elist if no dashboard when accessing /)
| dataProvider={dataProvider} | ||
| layout={Layout} | ||
| > | ||
| <Resource name="posts" list={PostList} show={PostShow} /> |
There was a problem hiding this comment.
same: use a customRoute to test this hook
| * UseBlockerTest: blocks navigation while a form is dirty. | ||
| */ | ||
| const BlockerForm = () => { | ||
| const [dirty, setDirty] = React.useState(false); |
There was a problem hiding this comment.
I suggest you use useWarnWhenUnsavedChanges instead of reimplementing it.
|
Hi @fzaninotto Can you restore the I have already noted this in the additional checks. |
|
Sure, the |
Problem
react-router v8 is out
Solution
Follow #10440
Add support for React router v8
Find a way to avoid dependency resolution issue after dropping
react-router-domHow To Test
Build RA packages locally, then link with apps in /examples folder
Additional Checks
masterfor a bugfix or a documentation fix, ornextfor a featurenextbranch seems is disappeared, I assumemasterbranch can be used for new features.Needs to be end-2-end tested with /examples folder.
Stories using the routers are updated.
Also, please make sure to read the contributing guidelines.