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

dirty-state comparison is to strict with initial values #4341

Closed
5 tasks done
sebastian-ludwig opened this issue Jun 29, 2023 · 2 comments
Closed
5 tasks done

dirty-state comparison is to strict with initial values #4341

sebastian-ludwig opened this issue Jun 29, 2023 · 2 comments
Labels
✨ enhancement a "nice to have" feature

Comments

@sebastian-ludwig
Copy link

sebastian-ludwig commented Jun 29, 2023

What happened?

I wanted to create a new User with Firstname, Lastname and Category in a Form.
The category is initially already set (in real life, the values object is much more complex)

const initialValues = {category: 'student'} ;
const currentValues = {category: 'student', firstname: undefined, lastname: undefined}

The Problem ist, that isEqual is answering now with false (and therefore dirty is to true), but actually is isn't dirty because there have not been made any changes.

The reason is the check of the keys, that varies when comparing initialValues to currentValues

keys = Object.keys(a);
length = keys.length;
if (length !== Object.keys(b).length) return false

This might be related to this issue: #4320

Version

Vue.js 3.x and vee-validate 4.x

What browsers are you seeing the problem on?

  • Firefox
  • Chrome
  • Safari
  • Microsoft Edge

Relevant log output

No response

Demo link

https://stackblitz.com/edit/u8xuns?file=src%2FApp.vue

Code of Conduct

@logaretm logaretm added the ✨ enhancement a "nice to have" feature label Jun 29, 2023
@logaretm
Copy link
Owner

Fixing this might incur a performance hit since that check skips key by key checks. But I think that is acceptable, maybe the check could be modified a little with length checking for non-undefined keys.

I will see what I can do.

logaretm added a commit that referenced this issue Jun 29, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@logaretm
Copy link
Owner

Don't think it has that much performance hit if we remove the key existence check and hasOwnProperty. Thanks for reporting this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement a "nice to have" feature
Projects
None yet
Development

No branches or pull requests

2 participants