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 how
valuesandshouldUnregisterinteract during initialization/submission, add a focused regression test, then run the relevant test suite. - Assistant
The failure is in the first
valuessynchronization effect: the control already initializes fromvalues, but the effect treats that same object as a change and resets the registered data to{}undershouldUnregister. I’m checking surroundingvaluessemantics before making the smallest lifecycle fix. - Assistant
The regression now passes. The fix preserves the mounted fields populated by the internal
valuesreset when field references are intentionally retained; ordinaryreset()behavior withshouldUnregisterremains unchanged. I’m running the full hook tests and static checks next. - Assistant
The focused suite, reset suite, and TypeScript checks are clean. The full test suite is still running; lint now flags only three pre-existing formatting locations outside this change, which I’m leaving untouched to avoid altering unrelated code.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.