-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Fix to prevent updates with PureComponent #1786
Conversation
@@ -5066,6 +5066,40 @@ describeWithDOM('mount', () => { | |||
}); | |||
}); | |||
|
|||
describeIf(is('>= 15.3'), 'PureComponent', () => { | |||
it('should not update when state and props did not change', () => { | |||
class Foo extends React.PureComponent { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's add PureComponent to the react-compat
file, and bring it in from there.
@@ -5066,6 +5066,40 @@ describeWithDOM('mount', () => { | |||
}); | |||
}); | |||
|
|||
describeIf(is('>= 15.3'), 'PureComponent', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also add corresponding tests for non-pure components that implement their own shouldComponentUpdate
(or flesh out the existing one)
@@ -339,6 +339,9 @@ class ShallowWrapper { | |||
&& typeof instance.shouldComponentUpdate === 'function' | |||
) { | |||
spy = spyMethod(instance, 'shouldComponentUpdate'); | |||
// PureComponent | |||
} else if (instance.isPureReactComponent) { | |||
shouldRender = !isEqual(prevProps, props) || !isEqual(state, instance.state); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's put this in some sort of pureComponentShouldComponentUpdate
function, so here and line 471 can share the implementation.
a70fb05
to
633f5a0
Compare
955a794
to
8ad1015
Compare
4aa56fa
to
ec51957
Compare
- [New] Add forwardRef support (#1592, @jquense) - [New] Add Portal support (#1760, #1761, #1772, #1774, @jgzuke) - [New] Add pointer events support (#1753, @ljharb) - [Fix] preemptively fix compat with React v16.4.3 (#1790, #1778, @gaearon, @aweary) - [Fix] `shallow`: prevent rerenders with PureComponents (#1786, @koba04) - [Fix] `shallow`: skip updates when nextState is `null` or `undefined` (#1785, @koba04) - [Fix] `shallow`: `setState` after `setProps` calls `componentWillReceiveProps` (#1779, @peanutenthusiast) - [Fix] `mount`/`shallow`: be stricter on the wrapper’s setState/setProps callback - [Fix] `shallow`/`mount`: improve error message when wrapping invalid elements (#1759, @jgzuke) - update deps - [Refactor] remove most uses of lodash - [meta] ensure a license and readme is present in all packages when published
Fix #1784 (comment)