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
Let me write a quick repro test to confirm the bug:
- Assistant
The fix works. Now let me add the test to the proper suite and run the full regression tests:
- Assistant
Fixed. Summary of the issue and resolution:
Root cause
With
shouldUnregister: true,_formValuesstarts empty and is populated only when fields register. When thevaluesprop is used,useFormcallscontrol._reset(props.values, { keepFieldsRef: true, ... })after the first render (src/useForm.ts:155).Inside
_reset, thekeepFieldsRefpath syncs each mounted field's value viasetValue— but then the very next statement wiped_formValuesto{}whenshouldUnregisteris set (src/logic/createFormControl.ts:1677). That wipe was designed for a normal , where forces every field to re-register and repopulate . With the fields are preserved ( stays ), so nothing ever re-registers and the form permanently loses its values — submitting then fails validation with empty data. This regressed in 802b0472 (#12923), which reinstated the wipe while adding .
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.