Skip to content

Commit

Permalink
Move bailouts to as early as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
acdlite committed Mar 12, 2018
1 parent 1b3cacd commit 7aa8d48
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,15 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
const newProps = workInProgress.pendingProps;
const oldProps = workInProgress.memoizedProps;

if (hasLegacyContextChanged()) {
// Normally we can bail out on props equality but if context has changed
// we don't do the bailout and we have to reuse existing props instead.
} else if (oldProps === newProps) {
workInProgress.stateNode = 0;
pushProvider(workInProgress);
return bailoutOnAlreadyFinishedWork(current, workInProgress);
}

const newValue = newProps.value;

let changedBits: number;
Expand Down Expand Up @@ -896,13 +905,6 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
workInProgress.stateNode = changedBits;
pushProvider(workInProgress);

if (hasLegacyContextChanged()) {
// Normally we can bail out on props equality but if context has changed
// we don't do the bailout and we have to reuse existing props instead.
} else if (oldProps === newProps) {
return bailoutOnAlreadyFinishedWork(current, workInProgress);
}

workInProgress.memoizedProps = newProps;
const newChildren = newProps.children;
reconcileChildren(current, workInProgress, newChildren);
Expand All @@ -921,7 +923,14 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
const newValue = context.currentValue;
const changedBits = context.changedBits;

if (changedBits !== 0) {
if (changedBits === 0) {
if (hasLegacyContextChanged()) {
// Normally we can bail out on props equality but if context has changed
// we don't do the bailout and we have to reuse existing props instead.
} else if (oldProps === newProps) {
return bailoutOnAlreadyFinishedWork(current, workInProgress);
}
} else if (changedBits !== 0) {
// Context change propagation stops at matching consumers, for time-
// slicing. Continue the propagation here.
propagateContextChange(
Expand All @@ -940,13 +949,6 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
}
workInProgress.stateNode = observedBits;

if (hasLegacyContextChanged()) {
// Normally we can bail out on props equality but if context has changed
// we don't do the bailout and we have to reuse existing props instead.
} else if (changedBits === 0 && oldProps === newProps) {
return bailoutOnAlreadyFinishedWork(current, workInProgress);
}

workInProgress.memoizedProps = newProps;
const render = newProps.children;

Expand Down

0 comments on commit 7aa8d48

Please # to comment.