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, add a focused regression test, then patch and run the relevant test suite. - Assistant
The failure is in the controlled
valuesreset path: it writes incoming values into mounted fields, thenshouldUnregisterreplaces the entire form-value store with{}. I’m checking reset semantics so the fix preserves only registered fields without changing normal unregister behavior. - Assistant
The regression now passes: mounted fields retain their incoming controlled value, while unmounted fields remain excluded. I’m running the broader reset tests and static checks because this change touches shared reset logic.
- Assistant
TypeScript and both targeted suites pass. The implementation file has three pre-existing Prettier violations outside this change, so I’m leaving those unrelated lines untouched; the new regression test itself passes lint. I’m doing one final broader
useFormtest run.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.