-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Fix TabbedForm and TabbedShowLayout with react-router v7 #10469
Conversation
@@ -35,9 +29,9 @@ export const TabbedFormView = (props: TabbedFormViewProps): ReactElement => { | |||
...rest | |||
} = props; | |||
const location = useLocation(); | |||
const resolvedPath = useResolvedPath(''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useResolvedPath
can no longer be used with both v6 and v7. See https://reactrouter.com/en/6.28.2/hooks/use-resolved-path
There seems to be a bug with encoded paths... Investigating |
All issues fixed, back to RFR |
const titleInput = await screen.findByLabelText('Title'); | ||
expect(titleInput).toBeVisible(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to add this extra check because the current test did not detect the regression 😬
</TestMemoryRouter> | ||
); | ||
|
||
export const Basic = () => ( | ||
<Wrapper> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to add a Wrapper to all stories to render the tabs in a nested route, otherwise the new implementation does not work.
Problem
Fix #10458
React-router v7 reintroduced the change they introduced in 6.19.0, which was reverted in 6.20.1 due to it causing issues in many apps, including react-admin.
Solution
Introduce
useSplatPathBase
hook, which allows to compute the splat route's base path, allowing react-admin to create absolute paths for tabs (as opposed to relative paths previously), which will work both with react-router v6 and v7.How To Test
Wrap the
<Admin>
in the simple example with a<HashRouter>
.Then, you can set
<HashRouter future={{ v7_relativeSplatPath: true }}>
to test with the feature enabled (which is the default in v7), or set it tofalse
to disable the feature.Then, use
PostEdit
andPostShow
to confirm the tabs are working OK.Additional Checks
master
for a bugfix, ornext
for a featureAlso, please make sure to read the contributing guidelines.