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

Use SameValue instead of === to check for dispatchAction equivalence #14752

Merged

Conversation

Jessidhia
Copy link
Contributor

@Jessidhia Jessidhia commented Feb 4, 2019

This allows a Reducer/State that happens to hold a -0 or NaN to not bail out of the bail outs / incorrectly bail out. It's the same algorithm that is used to check the deps array in Effect/Memo/etc.

I'm not sure if this is sufficient test coverage, but it does what I expected (and, more importantly, fails if I undo the changes).

@acdlite
Copy link
Collaborator

acdlite commented Feb 4, 2019

This makes sense to me, since we also use Object.is semantics for PureComponent, memo, context providers, deps, and so on. Thanks for the PR!

@acdlite acdlite merged commit e602b52 into facebook:master Feb 4, 2019
@Jessidhia Jessidhia deleted the use-samevalue-for-dispatchAction branch February 5, 2019 01:07
@thomschke
Copy link

Immutable data structure libraries have their own equality check (like immutable-js).

see -> #14569 (comment)

@sudhirj
Copy link

sudhirj commented Feb 7, 2019

@acdlite @Jessidhia This really needs a giant warning saying "DO NOT USE ARRAYS AS STATE!!!". This completely breaks them:

const [list, setList] = useState([])
setList((l) => {
  l.push(1)
  return l
}

is a complete fail, because Object.is sees the same array returned, absolutely nothing happens.

This was referenced Sep 20, 2019
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.

5 participants