StrictMode should call sCU twice in DEV (#17942)

This commit is contained in:
Brian Vaughn
2020-01-30 13:03:44 -08:00
committed by GitHub
parent 9dbe1c54df
commit 6ae2c33a75
2 changed files with 13 additions and 0 deletions
@@ -262,6 +262,15 @@ function checkShouldComponentUpdate(
) {
const instance = workInProgress.stateNode;
if (typeof instance.shouldComponentUpdate === 'function') {
if (__DEV__) {
if (
debugRenderPhaseSideEffectsForStrictMode &&
workInProgress.mode & StrictMode
) {
// Invoke the function an extra time to help detect side-effects.
instance.shouldComponentUpdate(newProps, newState, nextContext);
}
}
startPhaseTimer(workInProgress, 'shouldComponentUpdate');
const shouldUpdate = instance.shouldComponentUpdate(
newProps,
@@ -138,6 +138,7 @@ describe('ReactStrictMode', () => {
'getDerivedStateFromProps',
'getDerivedStateFromProps',
'shouldComponentUpdate',
'shouldComponentUpdate',
'render',
'render',
'componentDidUpdate',
@@ -166,6 +167,7 @@ describe('ReactStrictMode', () => {
'getDerivedStateFromProps',
'getDerivedStateFromProps',
'shouldComponentUpdate',
'shouldComponentUpdate',
]);
} else {
expect(log).toEqual([
@@ -283,6 +285,7 @@ describe('ReactStrictMode', () => {
'getDerivedStateFromProps',
'getDerivedStateFromProps',
'shouldComponentUpdate',
'shouldComponentUpdate',
'render',
'render',
'componentDidUpdate',
@@ -305,6 +308,7 @@ describe('ReactStrictMode', () => {
'getDerivedStateFromProps',
'getDerivedStateFromProps',
'shouldComponentUpdate',
'shouldComponentUpdate',
]);
} else {
expect(log).toEqual([