issue: cleanup process in useController
crashes when used with useFieldArray
in certain cases
#11937
Closed
1 task done
Version Number
7.51.5
Codesandbox/Expo snack
https://codesandbox.io/p/sandbox/react-hook-form-null-check-zqxx7v?file=%2Fsrc%2FApp.js
Steps to reproduce
Expected behaviour
The error should not occur.
The cause of the error is as follows:
{ arr: [{ k: 0 }, { k: 1 }] }
is rendered as follows:arr
field is rendered by the<Zeroth />
component where the"arr.0"
path is controlled byuseController
.arr
field is rendered by<First />
component where the"arr.1.k"
path is controlled byuseController
.control._fields
. Here, the resultingcontrol._fields
is{ arr: [{ k: { _f: ... }] }
becausearr.1.k
is controlled byuseController
.<Zeroth />
and<First />
components start to unmount.<Zeroth />
component, the cleanup process inuseController
for the"arr.0"
path is executed. Here, this cleanup expectscontrol._fields
to be{ arr: [{ k: ..., _f: ... }, ...] }
. However, as mentioned above, the_f
field does not exist.Although the current example is too trivial to use
useController
(just the return values ofuseFieldArray
are enough), in a complex form with heavily nested form values, usinguseController
withuseFieldArray
can sometimes be more convenient.What browsers are you seeing the problem on?
Chrome
Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: