Skip to content

Conversation

@AkprasadoP
Copy link

Summary

Fixes a critical bug where useModalForm modal fails to show when switching from "edit" to "create" action.

Root Cause

The handleShow callback in useModalForm had incomplete dependencies in its useCallback, causing stale closure issues when the action prop changed.

Solution

  • Added missing dependencies (action, setId, show) to the useCallback
  • Added comprehensive test case reproducing the exact bug scenario

Changes

  • packages/react-hook-form/src/useModalForm/index.ts: Fixed useCallback dependencies
  • packages/react-hook-form/src/useModalForm/index.spec.ts: Added test for action switching

Testing

Added test case that reproduces the bug:

  1. Open create modal ✅
  2. Close modal ✅
  3. Switch to edit action and open modal ✅
  4. Close modal ✅
  5. Switch back to create action and open modal ✅ (was failing before fix)

Closes #7095

@AkprasadoP AkprasadoP requested a review from a team as a code owner November 3, 2025 10:13
@changeset-bot
Copy link

changeset-bot bot commented Nov 3, 2025

🦋 Changeset detected

Latest commit: 9e12005

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@refinedev/react-hook-form Patch

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

@netlify
Copy link

netlify bot commented Nov 3, 2025

Deploy Preview for refine-doc-live-previews ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 9e12005
🔍 Latest deploy log https://app.netlify.com/projects/refine-doc-live-previews/deploys/6908a174c5a09800089e9bff
😎 Deploy Preview https://deploy-preview-7100--refine-doc-live-previews.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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
Copy link
Member

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 🙌

Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] useModalForm doesn't show after switching action from edit to create

2 participants