react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

Back button does not function properly with warnWhenUnsavedChanges

Open ostertag opened this issue 2 years ago • 3 comments

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:

  1. Open the list of posts.
  2. Click on any post to edit it and make changes, like its title.
  3. Click the back button (or pressing Alt + Left arrow).
  4. A dialog will appear saying: 'Some of your changes weren't saved. Are you sure you want to ignore them?'.
  5. Click OK button to ignore changes.
  6. 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

ostertag avatar Nov 06 '23 12:11 ostertag

Reproduced, thanks!

slax57 avatar Nov 06 '23 15:11 slax57

@ostertag @slax57 we would like to pick this up

gitstart avatar Nov 28 '23 14:11 gitstart

@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.

slax57 avatar Nov 28 '23 14:11 slax57