Don't call componentDidUpdate() in shallow renderer (#10372)
* Don't call componentDidUpdate() in shallow renderer * Lint Sent from my iPhone haha * Consistent comments
Dan Abramov committed
Aug 3, 2017 at 22:49 UTC
80577eb64928c59faf04f4d51593300a2e24e89c
2 files changed
+6
-22
src/renderers/testing/ReactShallowRendererEntry.js
+4
-15
@@ -136,17 +136,12 @@ class ReactShallowRenderer {
136
}
137
138
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.
141
}
142
143
_updateClassComponent(props, context) {
144
const oldProps = this._instance.props;
149
- const oldState = this._instance.state;
145
146
if (
147
oldProps !== props &&
@@ -180,14 +175,8 @@ class ReactShallowRenderer {
175
this._instance.state = state;
176
177
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.
180
}
181
}
182
src/renderers/testing/__tests__/ReactShallowRenderer-test.js
+2
-7
@@ -51,12 +51,7 @@ describe('ReactShallowRenderer', () => {
51
const instance = shallowRenderer.getMountedInstance();
52
instance.setState({});
53
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']);
55
56
logs.splice(0);
57
@@ -407,7 +402,7 @@ describe('ReactShallowRenderer', () => {
402
updatedState,
403
updatedContext,
404
]);
410
- expect(componentDidUpdateParams).toEqual([initialProp, initialState]);
405
+ expect(componentDidUpdateParams).toEqual([]);
406
});
407
408
it('can shallowly render components with ref as function', () => {