issue: values data is reset after first render, when shouldUnregister is provided…
- User
issue:
valuesdata is reset after first render, whenshouldUnregisteris providedVersion Number
7.71.2
Codesandbox/Expo snack
https://codesandbox.io/p/sandbox/blazing-dust-3225h9?file=%2Fsrc%2FApp.js
Steps to reproduce
- Simply submit a form
- See error
Expected behaviour
It is possible to successfully submit a form, when data is provided via
values, andshouldUnregister: trueoption is setWhat browsers are you seeing the problem on?
Chrome
Code of Conduct
- I agree to follow this project's Code of Conduct
Interface
No new interfaces are introduced.
- Assistant
I’ll trace the
valuessynchronization and unregister lifecycle, add a focused regression test, then run the relevant test suite. - Assistant
The worktree already has an unrelated
package.jsonchange; I’ll leave it untouched.rgisn’t installed here, so I’m switching to targetedgrep/file inspection. - Assistant
The failure is localized: the initial
valueseffect calls the reset path even though the control was already initialized from those same values. WithshouldUnregister, that reset deliberately clears the internal value store after updating mounted inputs, so submission receives an empty object. I’m adding a test that exercises the public submit path before changing initialization. - Assistant
The first test attempt was intercepted by Corepack’s package-manager consistency check before Jest ran; it did not execute the test. Dependencies are now present locally, so I’ll invoke the local Jest binary directly and avoid any further package resolution.
- Assistant
The regression test confirms the empty submission. A broader review found that skipping the first reset would break the established case where both
defaultValuesandvaluesare supplied. I’m keeping that synchronization intact and correcting the reset ordering instead: clear the unregistering store before repopulating mounted field refs, then preserve those repopulated values. - Assistant
The full
useFormsuite now passes (71/71), including the new submission regression and existingvalues/defaultValuesprecedence tests. I’m cleaning only the package-manager artifacts created by the intercepted test command, then I’ll run reset-focused tests and static checks. - Assistant
Formatting, lint, TypeScript, the full
useFormsuite, and the reset suite are clean. The final diff is limited to the reset ordering plus one regression test; the pre-existingpackage.jsonedit remains untouched. I’m running the complete Jest suite as the final verification because the changed reset path is shared infrastructure.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.