Skip to content

Commit 7bd4fa5

Browse files
committed
Always use the second result
1 parent 96d2a7b commit 7bd4fa5

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ 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__) {
174174
warnOnUndefinedDerivedState(ctor, partialState);
175175
if (
@@ -179,7 +179,7 @@ function applyDerivedStateFromProps(
179179
disableLogs();
180180
try {
181181
// Invoke the function an extra time to help detect side-effects.
182-
getDerivedStateFromProps(nextProps, prevState);
182+
partialState = getDerivedStateFromProps(nextProps, prevState);
183183
} finally {
184184
reenableLogs();
185185
}
@@ -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: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ 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__) {
174174
warnOnUndefinedDerivedState(ctor, partialState);
175175
if (
@@ -179,7 +179,7 @@ function applyDerivedStateFromProps(
179179
disableLogs();
180180
try {
181181
// Invoke the function an extra time to help detect side-effects.
182-
getDerivedStateFromProps(nextProps, prevState);
182+
partialState = getDerivedStateFromProps(nextProps, prevState);
183183
} finally {
184184
reenableLogs();
185185
}
@@ -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)