mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Don't call componentDidUpdate() in shallow renderer (#10372)
* Don't call componentDidUpdate() in shallow renderer * Lint Sent from my iPhone haha * Consistent comments
This commit is contained in:
@@ -136,17 +136,12 @@ class ReactShallowRenderer {
|
||||
}
|
||||
|
||||
this._rendered = this._instance.render();
|
||||
|
||||
// Calling cDU might lead to problems with host component references.
|
||||
// Since our components aren't really mounted, refs won't be available.
|
||||
// if (typeof this._instance.componentDidMount === 'function') {
|
||||
// this._instance.componentDidMount();
|
||||
// }
|
||||
// Intentionally do not call componentDidMount()
|
||||
// because DOM refs are not available.
|
||||
}
|
||||
|
||||
_updateClassComponent(props, context) {
|
||||
const oldProps = this._instance.props;
|
||||
const oldState = this._instance.state;
|
||||
|
||||
if (
|
||||
oldProps !== props &&
|
||||
@@ -180,14 +175,8 @@ class ReactShallowRenderer {
|
||||
this._instance.state = state;
|
||||
|
||||
this._rendered = this._instance.render();
|
||||
|
||||
// The 15.x shallow renderer triggered cDU for setState() calls only.
|
||||
if (
|
||||
oldState !== state &&
|
||||
typeof this._instance.componentDidUpdate === 'function'
|
||||
) {
|
||||
this._instance.componentDidUpdate(oldProps, oldState);
|
||||
}
|
||||
// Intentionally do not call componentDidUpdate()
|
||||
// because DOM refs are not available.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,12 +51,7 @@ describe('ReactShallowRenderer', () => {
|
||||
const instance = shallowRenderer.getMountedInstance();
|
||||
instance.setState({});
|
||||
|
||||
// The previous shallow renderer triggered cDU for setState() calls.
|
||||
expect(logs).toEqual([
|
||||
'shouldComponentUpdate',
|
||||
'componentWillUpdate',
|
||||
'componentDidUpdate',
|
||||
]);
|
||||
expect(logs).toEqual(['shouldComponentUpdate', 'componentWillUpdate']);
|
||||
|
||||
logs.splice(0);
|
||||
|
||||
@@ -407,7 +402,7 @@ describe('ReactShallowRenderer', () => {
|
||||
updatedState,
|
||||
updatedContext,
|
||||
]);
|
||||
expect(componentDidUpdateParams).toEqual([initialProp, initialState]);
|
||||
expect(componentDidUpdateParams).toEqual([]);
|
||||
});
|
||||
|
||||
it('can shallowly render components with ref as function', () => {
|
||||
|
||||
Reference in New Issue
Block a user