Skip to content

fix(react-hook-form): replace custom layout effect sync with native reset#7479

Open
hiteshchoudhary738-alt wants to merge 2 commits into
refinedev:mainfrom
hiteshchoudhary738-alt:fix/useFieldArray-empty-revisit
Open

fix(react-hook-form): replace custom layout effect sync with native reset#7479
hiteshchoudhary738-alt wants to merge 2 commits into
refinedev:mainfrom
hiteshchoudhary738-alt:fix/useFieldArray-empty-revisit

Conversation

@hiteshchoudhary738-alt

@hiteshchoudhary738-alt hiteshchoudhary738-alt commented Jul 12, 2026

Copy link
Copy Markdown

PR Checklist

Please check if your PR fulfills the following requirements:

Bugs / Features

What is the current behavior?

During SPA navigation, useFieldArray instances wrapped within components conditional on formLoading fail to retain values upon form remounting. This occurs because the internal microtask-deferred applyValuesToFields executes and checks getRegisteredFields() before the dynamically rendering inputs finish their mount-level registration lifecycle with React Hook Form.

What is the new behavior?

Replaced the custom microtask applyValuesToFields framework on initial data load with React Hook Form's native reset(data, { keepDirtyValues: true }). This natively handles delayed field hydration irrespective of active DOM input registration states, ensuring complete value restoration when revisiting the edit view.

fixes #7401

Notes for reviewers

The existing downstream render-driven loop for late-registered inputs (useEffect checking getMountedFields()) remains intact to preserve structural sync for components like unmounted UI controllers without regressing state on dirty fields.

@changeset-bot

changeset-bot Bot commented Jul 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: baa54bd

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

This PR includes changesets to release 6 packages
Name Type
@refinedev/react-hook-form Major
@refinedev/chakra-ui Patch
@refinedev/inferencer Major
@refinedev/live-previews Patch
@refinedev/mui Major
@refinedev/refine-ui 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

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] useFieldArray fields empty on second visit when using useForm

1 participant