GeezerVison is showing github.com — StrictMode should call sCU twice in DEV (#17942) · react/react@6ae2c33
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberClassComponent.js +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -262,6 +262,15 @@ function checkShouldComponentUpdate( | 262 | 262 | ) { | 263 | 263 | const instance = workInProgress.stateNode; | 264 | 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 | + } | 265 | 274 | startPhaseTimer(workInProgress, 'shouldComponentUpdate'); | 266 | 275 | const shouldUpdate = instance.shouldComponentUpdate( | 267 | 276 | newProps, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react/src/__tests__/ReactStrictMode-test.js +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -138,6 +138,7 @@ describe('ReactStrictMode', () => { | 138 | 138 | 'getDerivedStateFromProps', | 139 | 139 | 'getDerivedStateFromProps', | 140 | 140 | 'shouldComponentUpdate', | | 141 | + 'shouldComponentUpdate', | 141 | 142 | 'render', | 142 | 143 | 'render', | 143 | 144 | 'componentDidUpdate', | @@ -166,6 +167,7 @@ describe('ReactStrictMode', () => { | 166 | 167 | 'getDerivedStateFromProps', | 167 | 168 | 'getDerivedStateFromProps', | 168 | 169 | 'shouldComponentUpdate', | | 170 | + 'shouldComponentUpdate', | 169 | 171 | ]); | 170 | 172 | } else { | 171 | 173 | expect(log).toEqual([ | @@ -283,6 +285,7 @@ describe('ReactStrictMode', () => { | 283 | 285 | 'getDerivedStateFromProps', | 284 | 286 | 'getDerivedStateFromProps', | 285 | 287 | 'shouldComponentUpdate', | | 288 | + 'shouldComponentUpdate', | 286 | 289 | 'render', | 287 | 290 | 'render', | 288 | 291 | 'componentDidUpdate', | @@ -305,6 +308,7 @@ describe('ReactStrictMode', () => { | 305 | 308 | 'getDerivedStateFromProps', | 306 | 309 | 'getDerivedStateFromProps', | 307 | 310 | 'shouldComponentUpdate', | | 311 | + 'shouldComponentUpdate', | 308 | 312 | ]); | 309 | 313 | } else { | 310 | 314 | expect(log).toEqual([ | |
|