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

Unhandled rejection (HttpError) on Edit, optimistic rendering - undoable true #5685

Closed
sspread opened this issue Dec 18, 2020 · 3 comments · Fixed by #5781
Closed

Unhandled rejection (HttpError) on Edit, optimistic rendering - undoable true #5685

sspread opened this issue Dec 18, 2020 · 3 comments · Fixed by #5781
Assignees
Labels

Comments

@sspread
Copy link

sspread commented Dec 18, 2020

What you were expecting:
Optimistically return to index page, show error notification 'not found' once server responds with 404

What happened instead:
Optimistically returns to index page with 'undo' option as expected. But once server responds with 404, I get unhandled rejection.

Other information:
If I use undoable: false on my Edit component, the index view is not optimistically rendered and react admin correctly handles the HttpError with a 'not found' notification.

I'm using fetchUtils.fetchJson and returning a promise from update method on dataProvider. Per docs, I'm under the impression that react admin should handle http errors, and the fact that it does when undoable: false is evidence that I have it set up correctly.

Is the unhandled rejection that I'm seeing with the optimistic rendering the expected behavior for react admin?

Environment

  • React-admin version: 3.11.0
  • React version: 17.0.1
  • Browser: chrome (latest)
@fzaninotto
Copy link
Member

I don't understand your test case. Can you please provide a CodeSandbox reproducing the error, and add a step-by-step way to reproduce the error?

@sspread
Copy link
Author

sspread commented Jan 8, 2021

The test case is simply that using the out-of-the-box edit action (with undoable: true) will throw an uncaught http error after it optimistically redirects back to list view when server responds to the put/patch with an error. I can do a sandbox at some point.

@fzaninotto
Copy link
Member

Right, it can be triggered in the simple example sandbox by editing a post, setting 'f00bar' as the title, saving, and waiting until the notification disappears.

It seems to be caused by the following line:

It was introduced in #4291, where I used the same code for optimistic and non-optimistic calls. If it make sense to re-throw the error in non-optimistic mode (so that the dataProvider promise rejects), it doesn't make sense in optimistic mode, as the dataProvider promise already resolved. So the error musn't be rethrown in optimistic mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants