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

Change of dirtyFields logic after 6.14.0 #3873

Closed
OlehRb opened this issue Jan 11, 2021 · 3 comments
Closed

Change of dirtyFields logic after 6.14.0 #3873

OlehRb opened this issue Jan 11, 2021 · 3 comments
Labels
question Further information is requested

Comments

@OlehRb
Copy link

OlehRb commented Jan 11, 2021

Hi @bluebill1049 , first of all, thanks for this amazing library, it's been a real pleasure working with it so far.
However recently, we've faced with a minor issue, which affects logic of our apps

Description
As of version 6.14.0 the logic behind dirtyFields and isDirty from useForm / useFormContext seems to be changed quite drastically.

Before 6.14.0 it worked in a following way:

Screen.Recording.2021-01-11.at.18.20.51.mov

But, from 6.14.0 it started working in a completely different way:

Screen.Recording.2021-01-11.at.18.22.38.mov

So, previously we relayed on this behaviour in order to define if user changed anything in the form in order to prevent accidental redirects

Was it an intentional change of behaviour?

To Reproduce
Steps to reproduce the behaviour:

  1. Go to
  2. Make sure you are using version 6.14.0 or 6.14.1 (the most recent once, at the time of bug report)
  3. Enter any value in one of the fields
  4. Check that output for "DirtyField" shows true for the altered field
  5. Clean the touched field
  6. Check that output for "DirtyField" still shows previous state

Expected behaviour
On step 6 "DirtyField" the altered field should be removed from the list of dirtyField

Desktop (please complete the following information):

  • OS: MacOS Big Sur 11.1
  • Browser: Chrome
  • Version: 87

If you need any additional info about the reported issue, please, let me know

@bluebill1049 bluebill1049 added status: under investigation aware of this issue and pending for investigation question Further information is requested and removed status: under investigation aware of this issue and pending for investigation labels Jan 11, 2021
@bluebill1049
Copy link
Member

bluebill1049 commented Jan 11, 2021

you will need to supply defaultValues to make it work correctly with dirty fields. This was fixed by quite a few bugs which is a result of us predicting the default value to be an empty string.

one of the bug below:
🐞 fix #3261 dirtyField with object or array value compare (#3262) merged around Oct 2020

so for isDirty and dirtyFields should always supply a defaultValue for us to do the comparison to avoid issues.

looks like the doc only mentions the need for isDirty, I will include that info in the dirtyFields as well. I know this is not convenient, but as the lib grows we need to seek a more stable and safe approach.

@OlehRb
Copy link
Author

OlehRb commented Jan 12, 2021

@bluebill1049 , thanks for a super fast response
Yep, it looks like, providing of defaultValues makes isDirty and dirtyFields work as expected

I am gonna close this issue

@OlehRb OlehRb closed this as completed Jan 12, 2021
@bluebill1049
Copy link
Member

No worries, buddy.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants