mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
StrictMode should call sCU twice in DEV (#17942)
This commit is contained in:
@@ -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([
|
||||
|
||||
Reference in New Issue
Block a user