-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Add a confirmation modal when the user tries to navigate away with unsaved changes #35625
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
Conversation
Test Results SummaryCommit SHA: a83ba72
To view the full API test report, click here. To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
a0120aa to
fc86cf0
Compare
fc86cf0 to
cca422c
Compare
louwie17
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test well as is, although I did leave one question, but the original issue seems to imply exactly that window, so all good on my end.
I did notice though, that this only works when a user refreshes the page or navigates to another page that isn't a React page.
If I navigate to a React page, let's say from Products > Add New (MVP) to WooCommerce > Home with changes, I don't see a warning any my changes are lost.
Could we have a separate PR to address this @mdperez86 ?
| const { isDirty, isValidForm, values, resetForm } = | ||
| useFormContext< Product >(); | ||
|
|
||
| usePreventLeavingPage( isDirty ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes you made may not be saved. is this the default text that shows up in the popup? I was confused where this was coming from.
Also I assume Changes you made may not be saved. will be supported by different languages, as the browser will take care of that? Otherwise I did say we should pass ours in manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately changing this message is not fully supported by all browsers you can check here. So the message is managed by the browser in those cases.
louwie17
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the React router support as well, this tested very well, nice work @mdperez86 💯
louwie17
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing the tests.
All Submissions:
Changes proposed in this Pull Request:
Closes #35194
How to test the changes in this Pull Request:
Products -> Add New (MVP)Other information:
pnpm --filter=<project> changelog add?FOR PR REVIEWER ONLY: