Skip to content

Commit

Permalink
StrictMode should call sCU twice in DEV
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Jan 30, 2020
1 parent 9dbe1c5 commit 9682e5b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/react-reconciler/src/ReactFiberClassComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions packages/react/src/__tests__/ReactStrictMode-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ describe('ReactStrictMode', () => {
'getDerivedStateFromProps',
'getDerivedStateFromProps',
'shouldComponentUpdate',
'shouldComponentUpdate',
'render',
'render',
'componentDidUpdate',
Expand Down Expand Up @@ -166,6 +167,7 @@ describe('ReactStrictMode', () => {
'getDerivedStateFromProps',
'getDerivedStateFromProps',
'shouldComponentUpdate',
'shouldComponentUpdate',
]);
} else {
expect(log).toEqual([
Expand Down Expand Up @@ -283,6 +285,7 @@ describe('ReactStrictMode', () => {
'getDerivedStateFromProps',
'getDerivedStateFromProps',
'shouldComponentUpdate',
'shouldComponentUpdate',
'render',
'render',
'componentDidUpdate',
Expand All @@ -305,6 +308,7 @@ describe('ReactStrictMode', () => {
'getDerivedStateFromProps',
'getDerivedStateFromProps',
'shouldComponentUpdate',
'shouldComponentUpdate',
]);
} else {
expect(log).toEqual([
Expand Down

0 comments on commit 9682e5b

Please sign in to comment.