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



Copy link

@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).

Copy link

@acdlite acdlite commented Feb 4, 2019

This makes sense to me, since we also use 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
1 check passed
1 check passed
ci/circleci Your tests passed on CircleCI!
@Jessidhia Jessidhia deleted the Jessidhia:use-samevalue-for-dispatchAction branch Feb 5, 2019
Copy link

@thomschke thomschke commented Feb 6, 2019

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

see -> #14569 (comment)

Copy link

@sudhirj 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) => {
  return l

is a complete fail, because 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
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants