Skip to content

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

Merged
acdlite merged 1 commit into
react:masterfrom
Jessidhia:use-samevalue-for-dispatchAction
Feb 4, 2019
Merged

Use SameValue instead of === to check for dispatchAction equivalence#14752
acdlite merged 1 commit into
react:masterfrom
Jessidhia:use-samevalue-for-dispatchAction

Conversation

@Jessidhia

@Jessidhia Jessidhia commented Feb 4, 2019

Copy link
Copy Markdown
Contributor

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

acdlite commented Feb 4, 2019

Copy link
Copy Markdown
Collaborator

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 react:master Feb 4, 2019
@Jessidhia Jessidhia deleted the use-samevalue-for-dispatchAction branch February 5, 2019 01:07
@thomschke

Copy link
Copy Markdown

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

see -> #14569 (comment)

@sudhirj

sudhirj commented Feb 7, 2019

Copy link
Copy Markdown

@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