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

[core] fix(OverflowList): edge case in shouldComponentUpdate #5486

Merged
merged 5 commits into from
Aug 22, 2022

Conversation

braeden
Copy link
Contributor

@braeden braeden commented Aug 6, 2022

Checklist

  • Includes tests
  • Update documentation

Changes proposed in this pull request (update):

Context:

Through some testing, I've been able to repro the problematic condition: props change on the same tick as both state !== prevState AND shallowCompare(state, prevState) === true.

This means a re-render doesn't happen when it should. The original code was written to aggressively re-render (even in the case that the state doesn't change). But it failed to account for the case where: props change, state changes, but shallow compare is truthy (all in a single shouldComponentUpdate).


Here's a log demonstrating this happen:

 console.log("SCU called! [props, state, shallowCompare, return]", this.props === _nextProps, this.state === nextState, shallowCompareKeys(this.state, nextState), !(this.state !== nextState && shallowCompareKeys(this.state, nextState)));

image


Note: This component is reasonable suited returning to a PureComponent in the future, but that will be a breaking change.

Original expression: `!(this.state !== nextState && shallowCompareKeys(this.state, nextState))`
With DeMorgans laws can be written as `(this.state === nextState || !shallowCompareKeys(this.state, nextState))`

This is saying that the component SHOULD update iff: the states are equal by reference OR the keys are NOT shallow equal. 

I don't believe this was the intended logic, based on the above comments -- I imagine we don't actually want to re-render if they states have referential equality.
@palantirtech
Copy link
Member

Thanks for your interest in palantir/blueprint, @braeden! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request.

@braeden braeden marked this pull request as ready for review August 8, 2022 16:27
@adidahiya adidahiya changed the title Fix shouldComponentUpdate in OverflowList [core] fix(OverflowList): edge case in shouldComponentUpdate Aug 22, 2022
@adidahiya adidahiya merged commit 7dd6964 into palantir:develop Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants