New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Unmount of non-primitive field immediately after reset causes error #5492
Comments
Thank you for the quick resolution! I appreciate the great work you've done on this library and the good support you provide! |
Welcome @rosemariesadler 🙉 |
@bluebill1049 I'm getting the same bug again in the new version 7.30.0 , I saw few lines around that useEffect has changed c41511f ?? |
In the Commit c41511f we can see there is a check on field._f but in the latest version we don't have that check. |
I have a different bug with a similar error message. It seems to be happening on a component which is being unmounted after the form submits. I tried versions 7.29.0, 7.30.0, and 7.31.2 and have the same result on all 3.
|
I had a wrapper component which was passed the for some reason, changing the object so that the |
Describe the bug
When the value of a field is not a primitive (i.e. we have some meta-data that we save into the form for a typeahead component), if the field is unmounted immediately after reset an error occurs:
cannot set property 'mount' of undefined
.registerAbsentFields
treats the object like each layer is its own key, causing_f
to be undefined onget(fieldsRef.current, name)
during the cleanup function ofuseController
'suseEffect
.To Reproduce
Steps to reproduce the behavior:
Codesandbox link (Required)
https://codesandbox.io/s/restless-tree-j60ws
Expected behavior
No error should occur when the field is unmounted immediately after reset.
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context
I'm happy to put out a PR to fix the issue, but I'm not certain of the preferred approach. The most obvious fast fix I see is adding the check for
_f
existence in the cleanup function, but I'm wondering if more support should be added for non-primitive values? Maybe a ref that keeps track of the names of registered fields that we would then reference duringregisterAbsentFields
instead of just checking if the field is a primitive value?The text was updated successfully, but these errors were encountered: