Skip to content

Use deep equal in mutableValue #380

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

intersrc
Copy link

Sometimes, val & old are objects, like { label, value }, val !== old is true, but they have same label & value, this may cause a dead loop.
It's better to use a deep equal here.

@sagalbot
Copy link
Owner

sagalbot commented Dec 6, 2017

@intersrc thanks! Could you add a test to cover that case?

@intersrc
Copy link
Author

intersrc commented Dec 7, 2017

The test added. Now use val !== old will make tests die.
There is a small problem: if that happened, we can't locate which test is broken because of the dead loop.

@intersrc
Copy link
Author

intersrc commented Dec 7, 2017

Solved.

@@ -594,7 +594,7 @@
if (this.multiple) {
this.onChange ? this.onChange(val) : null
} else {
this.onChange && val !== old ? this.onChange(val) : null
this.onChange && JSON.stringify(val) !== JSON.stringify(old) ? this.onChange(val) : null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a good comparison because order of properties can be different but values can be equal, so as a result comparison will fail.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified.

@skjnldsv
Copy link

This is really an issue that needs to be fixed :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants