Skip to content

Commit 28f7d72

Browse files
committed
Always use the second result
1 parent 96d2a7b commit 28f7d72

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

packages/react-reconciler/src/ReactFiberClassComponent.new.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,21 +169,21 @@ function applyDerivedStateFromProps(
169169
nextProps: any,
170170
) {
171171
const prevState = workInProgress.memoizedState;
172-
const partialState = getDerivedStateFromProps(nextProps, prevState);
172+
let partialState = getDerivedStateFromProps(nextProps, prevState);
173173
if (__DEV__) {
174-
warnOnUndefinedDerivedState(ctor, partialState);
175174
if (
176175
debugRenderPhaseSideEffectsForStrictMode &&
177176
workInProgress.mode & StrictLegacyMode
178177
) {
179178
disableLogs();
180179
try {
181180
// Invoke the function an extra time to help detect side-effects.
182-
getDerivedStateFromProps(nextProps, prevState);
181+
partialState = getDerivedStateFromProps(nextProps, prevState);
183182
} finally {
184183
reenableLogs();
185184
}
186185
}
186+
warnOnUndefinedDerivedState(ctor, partialState);
187187
}
188188
// Merge the partial state and the previous state.
189189
const memoizedState =
@@ -318,7 +318,7 @@ function checkShouldComponentUpdate(
318318
) {
319319
const instance = workInProgress.stateNode;
320320
if (typeof instance.shouldComponentUpdate === 'function') {
321-
const shouldUpdate = instance.shouldComponentUpdate(
321+
let shouldUpdate = instance.shouldComponentUpdate(
322322
newProps,
323323
newState,
324324
nextContext,
@@ -338,7 +338,11 @@ function checkShouldComponentUpdate(
338338
disableLogs();
339339
try {
340340
// Invoke the function an extra time to help detect side-effects.
341-
instance.shouldComponentUpdate(newProps, newState, nextContext);
341+
shouldUpdate = instance.shouldComponentUpdate(
342+
newProps,
343+
newState,
344+
nextContext,
345+
);
342346
} finally {
343347
reenableLogs();
344348
}
@@ -651,7 +655,7 @@ function constructClassInstance(
651655
: emptyContextObject;
652656
}
653657

654-
const instance = new ctor(props, context);
658+
let instance = new ctor(props, context);
655659
// Instantiate twice to help detect side-effects.
656660
if (__DEV__) {
657661
if (
@@ -660,7 +664,7 @@ function constructClassInstance(
660664
) {
661665
disableLogs();
662666
try {
663-
new ctor(props, context); // eslint-disable-line no-new
667+
instance = new ctor(props, context); // eslint-disable-line no-new
664668
} finally {
665669
reenableLogs();
666670
}

packages/react-reconciler/src/ReactFiberClassComponent.old.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,21 +169,21 @@ function applyDerivedStateFromProps(
169169
nextProps: any,
170170
) {
171171
const prevState = workInProgress.memoizedState;
172-
const partialState = getDerivedStateFromProps(nextProps, prevState);
172+
let partialState = getDerivedStateFromProps(nextProps, prevState);
173173
if (__DEV__) {
174-
warnOnUndefinedDerivedState(ctor, partialState);
175174
if (
176175
debugRenderPhaseSideEffectsForStrictMode &&
177176
workInProgress.mode & StrictLegacyMode
178177
) {
179178
disableLogs();
180179
try {
181180
// Invoke the function an extra time to help detect side-effects.
182-
getDerivedStateFromProps(nextProps, prevState);
181+
partialState = getDerivedStateFromProps(nextProps, prevState);
183182
} finally {
184183
reenableLogs();
185184
}
186185
}
186+
warnOnUndefinedDerivedState(ctor, partialState);
187187
}
188188
// Merge the partial state and the previous state.
189189
const memoizedState =
@@ -318,7 +318,7 @@ function checkShouldComponentUpdate(
318318
) {
319319
const instance = workInProgress.stateNode;
320320
if (typeof instance.shouldComponentUpdate === 'function') {
321-
const shouldUpdate = instance.shouldComponentUpdate(
321+
let shouldUpdate = instance.shouldComponentUpdate(
322322
newProps,
323323
newState,
324324
nextContext,
@@ -338,7 +338,11 @@ function checkShouldComponentUpdate(
338338
disableLogs();
339339
try {
340340
// Invoke the function an extra time to help detect side-effects.
341-
instance.shouldComponentUpdate(newProps, newState, nextContext);
341+
shouldUpdate = instance.shouldComponentUpdate(
342+
newProps,
343+
newState,
344+
nextContext,
345+
);
342346
} finally {
343347
reenableLogs();
344348
}
@@ -651,7 +655,7 @@ function constructClassInstance(
651655
: emptyContextObject;
652656
}
653657

654-
const instance = new ctor(props, context);
658+
let instance = new ctor(props, context);
655659
// Instantiate twice to help detect side-effects.
656660
if (__DEV__) {
657661
if (
@@ -660,7 +664,7 @@ function constructClassInstance(
660664
) {
661665
disableLogs();
662666
try {
663-
new ctor(props, context); // eslint-disable-line no-new
667+
instance = new ctor(props, context); // eslint-disable-line no-new
664668
} finally {
665669
reenableLogs();
666670
}

0 commit comments

Comments
 (0)