Skip to content

Fix TabbedForm and TabbedShowLayout with react-router v7#10469

Merged
djhi merged 4 commits intomasterfrom
fix-tabs-react-router-v7
Jan 24, 2025
Merged

Fix TabbedForm and TabbedShowLayout with react-router v7#10469
djhi merged 4 commits intomasterfrom
fix-tabs-react-router-v7

Conversation

@slax57
Copy link
Contributor

@slax57 slax57 commented Jan 24, 2025

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 to false to disable the feature.

Then, use PostEdit and PostShow to confirm the tabs are working OK.

Additional Checks

  • The PR targets master for a bugfix, or next for a feature
  • The PR includes unit tests (if not possible, describe why) -> can't unit test in v7
  • The PR includes one or several stories (if not possible, describe why) -> no need for more stories
  • The documentation is up to date

Also, please make sure to read the contributing guidelines.

@slax57 slax57 added the WIP Work In Progress label Jan 24, 2025
...rest
} = props;
const location = useLocation();
const resolvedPath = useResolvedPath('');
Copy link
Contributor Author

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

@slax57
Copy link
Contributor Author

slax57 commented Jan 24, 2025

There seems to be a bug with encoded paths... Investigating

@slax57
Copy link
Contributor Author

slax57 commented Jan 24, 2025

All issues fixed, back to RFR

@slax57 slax57 added RFR Ready For Review and removed WIP Work In Progress labels Jan 24, 2025
Comment on lines +49 to +50
const titleInput = await screen.findByLabelText('Title');
expect(titleInput).toBeVisible();
Copy link
Contributor Author

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 😬

);

export const Basic = () => (
<Wrapper>
Copy link
Contributor Author

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.

@djhi djhi merged commit 527f8b0 into master Jan 24, 2025
16 checks passed
@djhi djhi deleted the fix-tabs-react-router-v7 branch January 24, 2025 13:45
@djhi djhi added this to the 5.5.1 milestone Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RFR Ready For Review

Development

Successfully merging this pull request may close these issues.

TabbedForm does not work

2 participants