Automatically downgrade an update to a hidden node
This automatically downgrades the priority of a hidden node. Its children won't be reconciled until they come around the next time.
Sebastian Markbage committed
Jun 14, 2016 at 13:54 UTC
8ad8bd193986e9bd0942f6c8c6ed816a3c58e520
1 file changed
+26
-3
src/renderers/shared/fiber/ReactFiberBeginWork.js
+26
-3
@@ -27,6 +27,9 @@ var {
27
CoroutineHandlerPhase,
28
YieldComponent,
29
} = ReactTypeOfWork;
30
+var {
31
+ OffscreenPriority,
32
+} = require('ReactPriorityLevel');
33
34
function reconcileChildren(current, workInProgress, nextChildren) {
35
const priority = workInProgress.pendingWorkPriority;
@@ -50,7 +53,28 @@ function updateHostComponent(current, workInProgress) {
53
console.log('host component', workInProgress.type, typeof workInProgress.pendingProps.children === 'string' ? workInProgress.pendingProps.children : '');
54
55
var nextChildren = workInProgress.pendingProps.children;
53
- reconcileChildren(current, workInProgress, nextChildren);
56
+
57
+ let priority = workInProgress.pendingWorkPriority;
58
+ if (workInProgress.pendingProps.hidden && priority !== OffscreenPriority) {
59
+ // If this host component is hidden, we can reconcile its children at
60
+ // the lowest priority and bail out from this particular pass. Unless, we're
61
+ // currently reconciling the lowest priority.
62
+ workInProgress.child = ReactChildFiber.reconcileChildFibers(
63
+ workInProgress,
64
+ current ? current.child : null,
65
+ nextChildren,
66
+ OffscreenPriority
67
+ );
68
+ return null;
69
+ } else {
70
+ workInProgress.child = ReactChildFiber.reconcileChildFibers(
71
+ workInProgress,
72
+ current ? current.child : null,
73
+ nextChildren,
74
+ priority
75
+ );
76
+ return workInProgress.child;
77
+ }
78
}
79
80
function mountIndeterminateComponent(current, workInProgress) {
@@ -119,8 +143,7 @@ function beginWork(current : ?Fiber, workInProgress : Fiber) : ?Fiber {
143
}
144
return null;
145
case HostComponent:
122
- updateHostComponent(current, workInProgress);
123
- return workInProgress.child;
146
+ return updateHostComponent(current, workInProgress);
147
case CoroutineHandlerPhase:
148
// This is a restart. Reset the tag to the initial phase.
149
workInProgress.tag = CoroutineComponent;