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

issue: dirtyFields is incorrect when reset() with keepDefaultValues and keepDirtyValues #11386

Closed
1 task done
IanVS opened this issue Jan 11, 2024 · 5 comments · Fixed by #11401
Closed
1 task done
Labels
status: under investigation aware of this issue and pending for investigation

Comments

@IanVS
Copy link
Contributor

IanVS commented Jan 11, 2024

Version Number

7.49.3

Codesandbox/Expo snack

https://codesandbox.io/p/github/IanVS/reproduction-keep-dirty-and-default/main

Steps to reproduce

  1. Go to https://codesandbox.io/p/github/IanVS/reproduction-keep-dirty-and-default/main
  2. Click on the first button ('Reset with keepDirtyValues')
  3. Notice that the first field was updated, but is not considered dirty, even though it does not match the defaultValue
  4. Click on the first button ('Reset')
  5. This works correctly, the field is updated again, and now it is considered to be dirty

Expected behaviour

Sorry, I've got another sneaky potential keepDefaultValues bug.

I think I should be able to update the value of non-dirty fields in the form without changing the defaultValue, and dirty tracking should continue to work correctly.

I did notice that controlled form elements work correctly as I expect, but not uncontrolled as shown in the reproduction.

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
@IanVS
Copy link
Contributor Author

IanVS commented Jan 12, 2024

I updated the reproduction to the vite-based one. It might be a good idea to update the link in the issue template if possible. The existing one links to a CSB with a pretty old version of react-hook-form, using an old create-react-app.

@IanVS
Copy link
Contributor Author

IanVS commented Jan 12, 2024

I think I have a fix for this, I'll be submitting a PR shortly. Never mind, it doesn't actually work. But I'll keep trying.

@bluebill1049 bluebill1049 added the status: under investigation aware of this issue and pending for investigation label Jan 13, 2024
@bluebill1049
Copy link
Member

Thanks for trying to fix with a PR @IanVS 🙏 I will take a look at it today.

@bluebill1049
Copy link
Member

bluebill1049 commented Jan 13, 2024

Did you change your CSB?

Screenshot 2024-01-14 at 9 41 39 am

@IanVS
Copy link
Contributor Author

IanVS commented Jan 16, 2024

Strange, I guess CSB doesn't automatically update if you sync with a repo? Sorry about that. I can't figure out how CSB is working, so here's the link to my repository instead: https://github.com/IanVS/reproduction-keep-dirty-and-default

I think I can make a PR after all, though I'm not sure if it's the right approach. I'll do that now.

bluebill1049 pushed a commit that referenced this issue Jan 16, 2024
…rty values (#11401)

* Add test

* Get newly-dirty fields when keeping defaults and dirty values
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 2024
rafaelcalhau pushed a commit to rafaelcalhau/react-hook-form that referenced this issue May 5, 2024
…defaults and dirty values (react-hook-form#11401)

* Add test

* Get newly-dirty fields when keeping defaults and dirty values
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: under investigation aware of this issue and pending for investigation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants