react-hook-form / react-hook-form

📋 React Hooks for form state management and validation (Web + React Native)
https://react-hook-form.com
MIT License
41.5k stars 2.08k forks source link

issue: Controller render `field.value` becomes unsynchronized after remounting #12341

Open lutzseverino opened 2 weeks ago

lutzseverino commented 2 weeks ago

Version Number

7.53.0

Codesandbox/Expo snack

https://codesandbox.io/p/sandbox/nqxrwd

Steps to reproduce

  1. Open dialog, input new value, test "Reset" and "Set to Hello World". All works as intended.
  2. Close dialog, open back up again. Test "Reset", only control._formValues.dialogField resets, control._fields.dialogField?._f.value does NOT reset and shows old value and field.value provided by the render prop also displays an old value.
  3. Click "Set to Hello World", see both _formValues and _fields update accordingly.
  4. Click "Reset" once again and see how _fields somehow remembers the value set on the previous dialog close and _formValues update correctly.

Video showcase: https://github.com/user-attachments/assets/9a5de662-a328-41c2-8b79-6d72486336d3

Expected behaviour

The value from the last dialog closure should not be remembered, resetValue should... reset the value regardless the situation.

What browsers are you seeing the problem on?

Firefox, Chrome, Safari, Edge

Relevant log output

No response

Code of Conduct

lutzseverino commented 2 weeks ago

Found this related discussion from July of 2023.