Skip to content

fix(react-hook-form): useFieldArray fields empty on second visit - #7417

Closed
zons-zhaozhy wants to merge 1 commit into
refinedev:mainfrom
zons-zhaozhy:fix/useFieldArray-fields-second-visit
Closed

zons-zhaozhy wants to merge 1 commit into
refinedev:mainfrom
zons-zhaozhy:fix/useFieldArray-fields-second-visit

Conversation

@zons-zhaozhy

Copy link
Copy Markdown

Hey! Saw #7401 and figured I'd take a look.

The issue is that applyValuesToFields(getRegisteredFields(), data, false) misses useFieldArray fields when navigating back to the edit form. The problem: on the second visit, fieldArray fields register after the queueMicrotask callback runs, so getRegisteredFields() doesn't include them.

The fix replaces the manual setValue loop with RHF's reset(data, { keepDirtyValues: true }). reset handles field arrays natively and doesn't depend on field registration timing.

Changes:

  • Added reset to the destructuring from useHookFormResult
  • Replaced applyValuesToFields(getRegisteredFields(), data, false) with reset(data, { keepDirtyValues: true })

This matches the fix suggested in the issue. Let me know if anything needs tweaking.

@changeset-bot

changeset-bot Bot commented May 11, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 1064508

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

@BatuhanW

Copy link
Copy Markdown
Member

Hello @zons-zhaozhy please see if any additional tests are needed. Also you need to create changeset for us to release the fix.

Please see details here: https://refine.dev/core/docs/guides-concepts/contributing/

@Woutuuur

Copy link
Copy Markdown

Hi, there's already a PR open for this issue: #7402. Do you see any problems with its implementation? If so, let's discuss there instead of creating additional PRs!

@zons-zhaozhy

Copy link
Copy Markdown
Author

Ah, I missed #7402 — that's a more complete fix with tests and changesets. Closing in favor of that one. Thanks @Woutuuur for pointing it out!

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.

4 participants