Back button does not function properly with warnWhenUnsavedChanges
What you were expecting:
After clicking the back button on dirty edit page of a resource with warnWhenUnsavedChanges and clicking OK to ignore changes, you should go back to previous page.
What happened instead:
After clicking the back button on dirty edit page of a resource with warnWhenUnsavedChanges and clicking OK to ignore changes, you stay on the same page.
Steps to reproduce:
- Open the list of posts.
- Click on any post to edit it and make changes, like its title.
- Click the back button (or pressing Alt + Left arrow).
- A dialog will appear saying: 'Some of your changes weren't saved. Are you sure you want to ignore them?'.
- Click
OKbutton to ignore changes. - You should be returned to the list of posts, but instead you find yourself still on the same page, continuing to edit the selected post.
Related code: Standard sample application on stackblitz.com is enough to reproduce the bug:
https://stackblitz.com/github/marmelab/react-admin/tree/master/examples/simple
You get the same behavior from cloning react-admin and running simple example locally.
Other information:
In Firefox, after you go back once, you immediately encounter another 'unsaved changes' dialog. After clicking OK a second time, you return to the list of posts.
In Edge and Chrome, when you go back the first time, you remain on the same edit page. Going back a second time takes you back to the posts list, even if you've made additional changes to the edit page at that point.
If you click on Posts instead of using the back button, and then ignore the 'unsaved changes' dialog, you'll be taken directly to the list of posts, which is the expected behavior
Environment
- React-admin version: ^4.15.3
- React version: ^17.0.0
- Browser: Chrome, Edge, Firefox
Reproduced, thanks!
@ostertag @slax57 we would like to pick this up
@gitstart feel free to give it a try :slightly_smiling_face:
However, you should know that we are planning to bump to the latest version of react-router with the upcoming react-admin v5 release, which will probably require rewriting the logic behind the warnWhenUnsavedChanges feature in any case.