question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: Unmount of non-primitive field immediately after reset causes error

See original GitHub issue

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 on get(fieldsRef.current, name) during the cleanup function of useController’s useEffect.

To Reproduce Steps to reproduce the behavior:

  1. Go to https://codesandbox.io/s/restless-tree-j60ws
  2. Click on “Toggle Metadata” so the field is showing
  3. Click on “Reset”, which resets the form and hides the field
  4. See error

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):

  • OS: macOS Catalina
  • Browser: Chrome
  • Version 91

Smartphone (please complete the following information):

  • Device: Pixel 3
  • OS: Android 11
  • Browser: Chrome
  • Version: 91

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 during registerAbsentFields instead of just checking if the field is a primitive value?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
rosemariesadlercommented, Jun 4, 2021

Thank you for the quick resolution! I appreciate the great work you’ve done on this library and the good support you provide!

0reactions
tetchelcommented, May 26, 2022

I had a wrapper component which was passed the name to provide to the controlled component.

for some reason, changing the object so that the name did not contain any periods (ie, the object was not nested) fixed this bug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SONAR complaining about Make the enclosing method "static ...
Correctly updating a static field from a non-static method is tricky to get right and could easily lead to bugs if there are...
Read more >
Troubleshooting in Athena - AWS Documentation
This error is caused by a parquet schema mismatch. A column that has a non-primitive type (for example, array ) has been declared...
Read more >
React re-renders guide: everything, all at once - Developer way
Comprehensive guide on React re-renders. The guide explains what are re-renders, what is necessary and unnecessary re-render, ...
Read more >
Code Issues - Embold Help Center
The buffer 'buffer' is not null-terminated after the call to strncpy(). This will cause bugs later in the code if the code assumes...
Read more >
UnboundID LDAP SDK for Java
This could cause problems for other LDAP SDK components that may rely on ... types and updated the LDAP SDK codebase to mark...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found