- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 2.8k
 
fix(react-hook-form): resolve modal visibility issue when switching between actions #7100
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
base: main
Are you sure you want to change the base?
fix(react-hook-form): resolve modal visibility issue when switching between actions #7100
Conversation
          🦋 Changeset detectedLatest commit: 9e12005 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
 Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR  | 
    
          ✅ Deploy Preview for refine-doc-live-previews ready!Built without sensitive environment variables 
 To edit notification comments on pull requests, go to your Netlify project configuration.  | 
    
| // Step 6: Switch back to create action | ||
| rerender({ action: "create" }); | ||
| 
               | 
          ||
| // Step 7: Try to open create modal again - THIS IS WHERE THE BUG OCCURS | 
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.
We shouldn’t add comments about issues to the codebase. It can be confusing. Beside that, everything is great! Thanks for improving Refine 🙌
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 the feedback! 🙏
You're absolutely right about keeping the codebase clean. I've removed the bug reference comment from the test case.
Really appreciate you taking the time to review this — and thanks for the kind words about improving Refine!
Summary
Fixes a critical bug where
useModalFormmodal fails to show when switching from "edit" to "create" action.Root Cause
The
handleShowcallback inuseModalFormhad incomplete dependencies in itsuseCallback, causing stale closure issues when theactionprop changed.Solution
action,setId,show) to theuseCallbackChanges
packages/react-hook-form/src/useModalForm/index.ts: Fixed useCallback dependenciespackages/react-hook-form/src/useModalForm/index.spec.ts: Added test for action switchingTesting
Added test case that reproduces the bug:
Closes #7095