@samitouri / QOS-React-2 / commits / 6ae2c33a75

StrictMode should call sCU twice in DEV (#17942)

Brian Vaughn committed Jan 30, 2020 at 13:03 UTC 6ae2c33a759e8f44622795603c84da9a2ebddf43
2 files changed +13
packages/react-reconciler/src/ReactFiberClassComponent.js
+9
@@ -262,6 +262,15 @@ function checkShouldComponentUpdate(
262 ) {
263 const instance = workInProgress.stateNode;
264 if (typeof instance.shouldComponentUpdate === 'function') {
265 + if (__DEV__) {
266 + if (
267 + debugRenderPhaseSideEffectsForStrictMode &&
268 + workInProgress.mode & StrictMode
269 + ) {
270 + // Invoke the function an extra time to help detect side-effects.
271 + instance.shouldComponentUpdate(newProps, newState, nextContext);
272 + }
273 + }
274 startPhaseTimer(workInProgress, 'shouldComponentUpdate');
275 const shouldUpdate = instance.shouldComponentUpdate(
276 newProps,
packages/react/src/__tests__/ReactStrictMode-test.js
+4
@@ -138,6 +138,7 @@ describe('ReactStrictMode', () => {
138 'getDerivedStateFromProps',
139 'getDerivedStateFromProps',
140 'shouldComponentUpdate',
141 + 'shouldComponentUpdate',
142 'render',
143 'render',
144 'componentDidUpdate',
@@ -166,6 +167,7 @@ describe('ReactStrictMode', () => {
167 'getDerivedStateFromProps',
168 'getDerivedStateFromProps',
169 'shouldComponentUpdate',
170 + 'shouldComponentUpdate',
171 ]);
172 } else {
173 expect(log).toEqual([
@@ -283,6 +285,7 @@ describe('ReactStrictMode', () => {
285 'getDerivedStateFromProps',
286 'getDerivedStateFromProps',
287 'shouldComponentUpdate',
288 + 'shouldComponentUpdate',
289 'render',
290 'render',
291 'componentDidUpdate',
@@ -305,6 +308,7 @@ describe('ReactStrictMode', () => {
308 'getDerivedStateFromProps',
309 'getDerivedStateFromProps',
310 'shouldComponentUpdate',
311 + 'shouldComponentUpdate',
312 ]);
313 } else {
314 expect(log).toEqual([