Skip to content
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

Breaking change between 7.22.4 & 7.22.5 #9524

Closed
1 task done
o-alexandrov opened this issue Dec 5, 2022 · 10 comments
Closed
1 task done

Breaking change between 7.22.4 & 7.22.5 #9524

o-alexandrov opened this issue Dec 5, 2022 · 10 comments

Comments

@o-alexandrov
Copy link

Version Number

7.22.5

Codesandbox/Expo snack

https://codesandbox.io/s/sharp-margulis-wf7myr

Steps to reproduce

  1. Go to provided Codesandbox
  2. Use version 7.22.5
  3. Open console
  4. Click on Set name to undefined
  5. Observe the bug: FieldController doesn't get an value update (no console)

Go back to step 2, use version 7.22.4, repeat steps, and see that it correctly updates the value to undefined and triggers an update (console statement is invoked)

Expected behaviour

  • setValue to undefined triggers an update and does update the value to undefined (currently it doesn't)

What browsers are you seeing the problem on?

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@bluebill1049
Copy link
Member

Thanks for the issue report, however, please refer to the doc undefined value is not supported. The patch is most likely due to a bug fix, and you can consider using another type of default value instead.

@bluebill1049 bluebill1049 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 5, 2022
@o-alexandrov
Copy link
Author

@bluebill1049 how do you suggest to remove a value from form values?

@o-alexandrov
Copy link
Author

o-alexandrov commented Dec 5, 2022

Btw, the breaking change was introduced in this set of changes and in this file

@o-alexandrov
Copy link
Author

I hope you do reconsider, as suggesting users-developers to patch on their side for conversion (ex. undefined => null) is error-prone for users whereas it should be handled by the library.

@bluebill1049
Copy link
Member

If an input is removed or unmounted, then it should use unregister function.

@o-alexandrov
Copy link
Author

o-alexandrov commented Dec 5, 2022

The input exists, the value is removed from a form.
Based on your message and the logic behind removal of a feature to setValue(fieldName, undefined), I guess you believe a user-developer should:

  • unregister
  • and register again
context.unregister(name)
context.register(name)

Do you really think this is a good DX for a developer to remove a value from a form?

@o-alexandrov
Copy link
Author

The really bad part here is:

  • setValue doesn't complain in the provided code sandbox that undefined is not allowed

So many other devs would stumble on this error

@bluebill1049
Copy link
Member

setValue doesn't complain in the provided code sandbox that undefined is not allowed

It's a valid point above, I will tighten up the type. Everything else will stay the same.

@o-alexandrov
Copy link
Author

So there will be no way to remove a value.
No alternative to previous:
setValue(fieldName, undefined)

I hope you will reconsider, as many developers looking at this issue would probably lose trust in this library to be safe long-term, especially with breaking changes in patch versions.

@o-alexandrov
Copy link
Author

o-alexandrov commented Dec 5, 2022

setValue doesn't complain in the provided code sandbox that undefined is not allowed

It's a valid point above, I will tighten up the type. Everything else will stay the same.

Even if you change typings, it won’t help devs in all cases, as event’s target in inputs is typed in a way that it’s always truthy.

  • as well as it’s naive to think deeply nested fields using useFormContext would be all correctly typed on a possible undefined value

The only safe way to handle this is to actually handle undefined within the library, not to depend on a developer to know about this nuance.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants