@samitouri / QOS-React / commits / 1637b43e27

Changed the way we double-invoke cWM lifecycle hook (#11764)

* Changed the way we double-invoke cWM lifecycle hook * Explicitly pass props to super() in test

Brian Vaughn committed Dec 5, 2017 at 08:24 UTC 1637b43e27c40c73f9489603145f9bb1d0ece618
3 files changed +16 -5
packages/react-reconciler/src/ReactFiberBeginWork.js
+10
@@ -218,6 +218,16 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
218 // In the initial pass we might need to construct the instance.
219 constructClassInstance(workInProgress, workInProgress.pendingProps);
220 mountClassInstance(workInProgress, renderExpirationTime);
221 +
222 + // Simulate an async bailout/interruption by invoking lifecycle twice.
223 + // We do this here rather than inside of ReactFiberClassComponent,
224 + // To more realistically simulate the interruption behavior of async,
225 + // Which would never call componentWillMount() twice on the same instance.
226 + if (debugRenderPhaseSideEffects) {
227 + constructClassInstance(workInProgress, workInProgress.pendingProps);
228 + mountClassInstance(workInProgress, renderExpirationTime);
229 + }
230 +
231 shouldUpdate = true;
232 } else {
233 invariant(false, 'Resuming work not yet implemented.');
packages/react-reconciler/src/ReactFiberClassComponent.js
-5
@@ -387,11 +387,6 @@ export default function(
387 instance.componentWillMount();
388 stopPhaseTimer();
389
390 - // Simulate an async bailout/interruption by invoking lifecycle twice.
391 - if (debugRenderPhaseSideEffects) {
392 - instance.componentWillMount();
393 - }
394 -
390 if (oldState !== instance.state) {
391 if (__DEV__) {
392 warning(
packages/react/src/__tests__/ReactAsyncClassComponent-test.internal.js
+6
@@ -28,6 +28,10 @@ describe('ReactAsyncClassComponent', () => {
28 let shouldComponentUpdate = false;
29 class ClassComponent extends React.Component {
30 state = {};
31 + constructor(props) {
32 + super(props);
33 + log.push('constructor');
34 + }
35 componentDidMount() {
36 log.push('componentDidMount');
37 }
@@ -58,7 +62,9 @@ describe('ReactAsyncClassComponent', () => {
62
63 const component = ReactTestRenderer.create(<ClassComponent />);
64 expect(log).toEqual([
65 + 'constructor',
66 'componentWillMount',
67 + 'constructor',
68 'componentWillMount',
69 'render',
70 'render',