Move isHostComponent branches out of bailout
Since we only call bailout from within the host component branch now, we can just move this to the branch where we already know that this is a host component. As part of this I noticed that we don't always push the host context so I moved that to the beginning of the branch.
Sebastian Markbage committed
Dec 21, 2016 at 00:05 UTC
9a210114e464d717e0ba9f2d3e5d936adfbad1db
1 file changed
+31
-39
src/renderers/shared/fiber/ReactFiberBeginWork.js
+31
-39
@@ -290,6 +290,8 @@ module.exports = function<T, P, I, TI, C, CX>(
290
}
291
292
function updateHostComponent(current, workInProgress) {
293
+ pushHostContext(workInProgress);
294
+
295
let nextProps = workInProgress.pendingProps;
296
const prevProps = current ? current.memoizedProps : null;
297
const memoizedProps = workInProgress.memoizedProps;
@@ -303,6 +305,24 @@ module.exports = function<T, P, I, TI, C, CX>(
305
}
306
}
307
} else if (nextProps === null || memoizedProps === nextProps) {
308
+ if (memoizedProps.hidden &&
309
+ workInProgress.pendingWorkPriority !== OffscreenPriority) {
310
+ // This subtree still has work, but it should be deprioritized so we need
311
+ // to bail out and not do any work yet.
312
+ // TODO: It would be better if this tree got its correct priority set
313
+ // during scheduleUpdate instead because otherwise we'll start a higher
314
+ // priority reconciliation first before we can get down here. However,
315
+ // that is a bit tricky since workInProgress and current can have
316
+ // different "hidden" settings.
317
+ let child = workInProgress.progressedChild;
318
+ while (child) {
319
+ // To ensure that this subtree gets its priority reset, the children
320
+ // need to be reset.
321
+ child.pendingWorkPriority = OffscreenPriority;
322
+ child = child.sibling;
323
+ }
324
+ return null;
325
+ }
326
return bailoutOnAlreadyFinishedWork(current, workInProgress);
327
}
328
@@ -359,7 +379,6 @@ module.exports = function<T, P, I, TI, C, CX>(
379
// Abort and don't process children yet.
380
return null;
381
} else {
362
- pushHostContext(workInProgress);
382
reconcileChildren(current, workInProgress, nextChildren);
383
return workInProgress.child;
384
}
@@ -474,28 +493,6 @@ module.exports = function<T, P, I, TI, C, CX>(
493
494
function bailoutOnAlreadyFinishedWork(current, workInProgress : Fiber) : ?Fiber {
495
const priorityLevel = workInProgress.pendingWorkPriority;
477
- const isHostComponent = workInProgress.tag === HostComponent;
478
-
479
- if (isHostComponent &&
480
- workInProgress.memoizedProps.hidden &&
481
- workInProgress.pendingWorkPriority !== OffscreenPriority) {
482
- // This subtree still has work, but it should be deprioritized so we need
483
- // to bail out and not do any work yet.
484
- // TODO: It would be better if this tree got its correct priority set
485
- // during scheduleUpdate instead because otherwise we'll start a higher
486
- // priority reconciliation first before we can get down here. However,
487
- // that is a bit tricky since workInProgress and current can have
488
- // different "hidden" settings.
489
- let child = workInProgress.progressedChild;
490
- while (child) {
491
- // To ensure that this subtree gets its priority reset, the children
492
- // need to be reset.
493
- child.pendingWorkPriority = OffscreenPriority;
494
- child = child.sibling;
495
- }
496
- return null;
497
- }
498
-
496
// TODO: We should ideally be able to bail out early if the children have no
497
// more work to do. However, since we don't have a separation of this
498
// Fiber's priority and its children yet - we don't know without doing lots
@@ -519,23 +516,18 @@ module.exports = function<T, P, I, TI, C, CX>(
516
cloneChildFibers(current, workInProgress);
517
markChildAsProgressed(current, workInProgress, priorityLevel);
518
522
- // Put context on the stack because we will work on children
523
- if (isHostComponent) {
524
- pushHostContext(workInProgress);
525
- } else {
526
- // TODO: Unify this switch with the other branches above.
527
- switch (workInProgress.tag) {
528
- case ClassComponent:
529
- if (isContextProvider(workInProgress)) {
530
- pushContextProvider(workInProgress, false);
531
- }
532
- break;
533
- case HostRoot:
534
- case HostPortal:
535
- pushHostContainer(workInProgress.stateNode.containerInfo);
536
- break;
537
- }
519
+ switch (workInProgress.tag) {
520
+ case ClassComponent:
521
+ if (isContextProvider(workInProgress)) {
522
+ pushContextProvider(workInProgress, false);
523
+ }
524
+ break;
525
+ case HostRoot:
526
+ case HostPortal:
527
+ pushHostContainer(workInProgress.stateNode.containerInfo);
528
+ break;
529
}
530
+
531
// TODO: this is annoyingly duplicating non-jump codepaths.
532
533
return workInProgress.child;