Skip to content

Fix Show and Edit controllers can trigger a redirect loop with react-router v7 if getOne rejects#10850

Merged
djhi merged 1 commit intomasterfrom
fix-getOne-loop-on-error
Jul 22, 2025
Merged

Fix Show and Edit controllers can trigger a redirect loop with react-router v7 if getOne rejects#10850
djhi merged 1 commit intomasterfrom
fix-getOne-loop-on-error

Conversation

@slax57
Copy link
Copy Markdown
Contributor

@slax57 slax57 commented Jul 22, 2025

Problem

Fix #10842

If getOne rejects, Show and Edit controllers will trigger a redirect to the list view, and also force refreshing the react-query cache with useRefresh().
This can lead to creating a redirect loop because refresh will trigger a getOne call again, which will fail again and trigger this side-effect again, etc.

This issue only seems to appear when using react-router v7.

#10776 already attempted to fix this issue, but according to my tests it doesn't work (and actually seems to have no effect) so I reverted the changes it brought.

Solution

Simply remove calling refresh() from the side-effects, as redirecting to the list view will refresh the data anyway thanks to react-query.

How To Test

We need a demo with RR v7 to test this fix, so I recommend to use the e-commerce demo (make run-demo).

You can for instance replace the examples/demo/src/dataProvider/rest.ts file with the following:

import simpleRestProvider from 'ra-data-simple-rest';
import { HttpError } from 'react-admin';

export default {
    ...simpleRestProvider('http://localhost:4000'),
    getOne: () => Promise.reject(new HttpError('TEST ERROR', 500)),
};

And then try to access the OrderEdit view.

With the fix, the error notification is only showed once, and there is no redirection loop.

Additional Checks

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

Also, please make sure to read the contributing guidelines.

@slax57 slax57 added the RFR Ready For Review label Jul 22, 2025
@djhi djhi merged commit c6b1fcd into master Jul 22, 2025
15 checks passed
@djhi djhi deleted the fix-getOne-loop-on-error branch July 22, 2025 15:54
@slax57 slax57 added this to the 5.10.1 milestone Jul 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RFR Ready For Review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Data provider getOne loop on error

2 participants