Skip to content

Commit 80577eb

Browse files
authored
Don't call componentDidUpdate() in shallow renderer (#10372)
* Don't call componentDidUpdate() in shallow renderer * Lint Sent from my iPhone haha * Consistent comments
1 parent a130757 commit 80577eb

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed

src/renderers/testing/ReactShallowRendererEntry.js

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,12 @@ class ReactShallowRenderer {
136136
}
137137

138138
this._rendered = this._instance.render();
139-
140-
// Calling cDU might lead to problems with host component references.
141-
// Since our components aren't really mounted, refs won't be available.
142-
// if (typeof this._instance.componentDidMount === 'function') {
143-
// this._instance.componentDidMount();
144-
// }
139+
// Intentionally do not call componentDidMount()
140+
// because DOM refs are not available.
145141
}
146142

147143
_updateClassComponent(props, context) {
148144
const oldProps = this._instance.props;
149-
const oldState = this._instance.state;
150145

151146
if (
152147
oldProps !== props &&
@@ -180,14 +175,8 @@ class ReactShallowRenderer {
180175
this._instance.state = state;
181176

182177
this._rendered = this._instance.render();
183-
184-
// The 15.x shallow renderer triggered cDU for setState() calls only.
185-
if (
186-
oldState !== state &&
187-
typeof this._instance.componentDidUpdate === 'function'
188-
) {
189-
this._instance.componentDidUpdate(oldProps, oldState);
190-
}
178+
// Intentionally do not call componentDidUpdate()
179+
// because DOM refs are not available.
191180
}
192181
}
193182

src/renderers/testing/__tests__/ReactShallowRenderer-test.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,7 @@ describe('ReactShallowRenderer', () => {
5151
const instance = shallowRenderer.getMountedInstance();
5252
instance.setState({});
5353

54-
// The previous shallow renderer triggered cDU for setState() calls.
55-
expect(logs).toEqual([
56-
'shouldComponentUpdate',
57-
'componentWillUpdate',
58-
'componentDidUpdate',
59-
]);
54+
expect(logs).toEqual(['shouldComponentUpdate', 'componentWillUpdate']);
6055

6156
logs.splice(0);
6257

@@ -407,7 +402,7 @@ describe('ReactShallowRenderer', () => {
407402
updatedState,
408403
updatedContext,
409404
]);
410-
expect(componentDidUpdateParams).toEqual([initialProp, initialState]);
405+
expect(componentDidUpdateParams).toEqual([]);
411406
});
412407

413408
it('can shallowly render components with ref as function', () => {

0 commit comments

Comments
 (0)