refine
refine copied to clipboard
fix(antd): Prevent unsaved dialog on modal form submission
Addresses issue #6833.
When warnWhenUnsavedChanges is true and a form within a modal (using useModalForm) is dirty, submitting the form could incorrectly trigger the "unsaved changes" confirmation dialog.
This was due to a race condition where the modal closing/unmounting process initiated navigation/unload checks before React had fully processed the warnWhen state update to false (which is set synchronously in the core useForm's onFinish handler).
The fix involves modifying the onFinish handler within packages/antd/src/hooks/form/useModalForm/useModalForm.ts. The modal's close() call is now wrapped in setTimeout(..., 0) to defer its execution to the next event loop cycle. This allows React sufficient time to process the setWarnWhen(false) state update, ensuring that warnWhen is correctly false when the modal close/unmount events trigger any navigation checks.
A new unit test has been added to useModalForm's spec file to verify this fix and prevent regressions.
Manual end-to-end testing of this change in an example application was unfortunately blocked by unrelated build failures in @refinedev/core and @refinedev/antd packages, and subsequent tooling instability related to pre-commit hooks. The fix is verified at the unit test level.
PR Checklist
Please check if your PR fulfills the following requirements:
- [x] The commit message follows our guidelines: https://refine.dev/docs/guides-concepts/contributing/#commit-convention
Bugs / Features
- [x] Related issue(s) linked
- [x] Tests for the changes have been added
- [x] Docs have been added / updated
- [x] Changesets have been added https://refine.dev/docs/guides-concepts/contributing/#creating-a-changeset
What is the current behavior?
What is the new behavior?
fixes (issue)
Notes for reviewers
Deploy Preview for refine-doc-live-previews failed.
Built without sensitive environment variables
| Name | Link |
|---|---|
| Latest commit | c7aa43a5709172ea6c3954162ff7454661aeb87b |
| Latest deploy log | https://app.netlify.com/projects/refine-doc-live-previews/deploys/68482d7703d3b10008cc31d3 |
⚠️ No Changeset found
Latest commit: c7aa43a5709172ea6c3954162ff7454661aeb87b
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
The code and explanation don’t match the issue, and I couldn’t reproduce the bug either.
I’m closing the PR for now. We’d really appreciate it if you could open a new issue with a reproducible example.