Pass the priority level along to children
Sebastian Markbage committed
Jun 14, 2016 at 13:40 UTC
e53f0dc4b44f08b354f24acb2e22ce1349dfc76f
5 files changed
+34
-24
src/renderers/shared/fiber/ReactChildFiber.js
+16
-15
@@ -14,6 +14,7 @@
14
15
import type { ReactCoroutine, ReactYield } from 'ReactCoroutine';
16
import type { Fiber } from 'ReactFiber';
17
+import type { PriorityLevel } from 'ReactPriorityLevel';
18
19
import type { ReactNodeList } from 'ReactTypes';
20
@@ -28,7 +29,7 @@ var {
29
var ReactFiber = require('ReactFiber');
30
var ReactReifiedYield = require('ReactReifiedYield');
31
31
-function createSubsequentChild(parent : Fiber, existingChild : ?Fiber, previousSibling : Fiber, newChildren) : Fiber {
32
+function createSubsequentChild(parent : Fiber, existingChild : ?Fiber, previousSibling : Fiber, newChildren, priority : PriorityLevel) : Fiber {
33
if (typeof newChildren !== 'object' || newChildren === null) {
34
return previousSibling;
35
}
@@ -41,14 +42,14 @@ function createSubsequentChild(parent : Fiber, existingChild : ?Fiber, previousS
42
element.key === existingChild.key) {
43
// TODO: This is not sufficient since previous siblings could be new.
44
// Will fix reconciliation properly later.
44
- const clone = ReactFiber.cloneFiber(existingChild);
45
+ const clone = ReactFiber.cloneFiber(existingChild, priority);
46
clone.pendingProps = element.props;
47
clone.child = existingChild.child;
48
clone.sibling = null;
49
previousSibling.sibling = clone;
50
return clone;
51
}
51
- const child = ReactFiber.createFiberFromElement(element);
52
+ const child = ReactFiber.createFiberFromElement(element, priority);
53
previousSibling.sibling = child;
54
child.parent = parent;
55
return child;
@@ -56,7 +57,7 @@ function createSubsequentChild(parent : Fiber, existingChild : ?Fiber, previousS
57
58
case REACT_COROUTINE_TYPE: {
59
const coroutine = (newChildren : ReactCoroutine);
59
- const child = ReactFiber.createFiberFromCoroutine(coroutine);
60
+ const child = ReactFiber.createFiberFromCoroutine(coroutine, priority);
61
previousSibling.sibling = child;
62
child.parent = parent;
63
return child;
@@ -65,7 +66,7 @@ function createSubsequentChild(parent : Fiber, existingChild : ?Fiber, previousS
66
case REACT_YIELD_TYPE: {
67
const yieldNode = (newChildren : ReactYield);
68
const reifiedYield = ReactReifiedYield.createReifiedYield(yieldNode);
68
- const child = ReactFiber.createFiberFromYield(yieldNode);
69
+ const child = ReactFiber.createFiberFromYield(yieldNode, priority);
70
child.output = reifiedYield;
71
previousSibling.sibling = child;
72
child.parent = parent;
@@ -77,7 +78,7 @@ function createSubsequentChild(parent : Fiber, existingChild : ?Fiber, previousS
78
let prev : Fiber = previousSibling;
79
let existing : ?Fiber = existingChild;
80
for (var i = 0; i < newChildren.length; i++) {
80
- prev = createSubsequentChild(parent, existing, prev, newChildren[i]);
81
+ prev = createSubsequentChild(parent, existing, prev, newChildren[i], priority);
82
if (prev && existing) {
83
// TODO: This is not correct because there could've been more
84
// than one sibling consumed but I don't want to return a tuple.
@@ -91,7 +92,7 @@ function createSubsequentChild(parent : Fiber, existingChild : ?Fiber, previousS
92
}
93
}
94
94
-function createFirstChild(parent, existingChild, newChildren) {
95
+function createFirstChild(parent, existingChild, newChildren, priority) {
96
if (typeof newChildren !== 'object' || newChildren === null) {
97
return null;
98
}
@@ -103,20 +104,20 @@ function createFirstChild(parent, existingChild, newChildren) {
104
element.type === existingChild.type &&
105
element.key === existingChild.key) {
106
// Get the clone of the existing fiber.
106
- const clone = ReactFiber.cloneFiber(existingChild);
107
+ const clone = ReactFiber.cloneFiber(existingChild, priority);
108
clone.pendingProps = element.props;
109
clone.child = existingChild.child;
110
clone.sibling = null;
111
return clone;
112
}
112
- const child = ReactFiber.createFiberFromElement(element);
113
+ const child = ReactFiber.createFiberFromElement(element, priority);
114
child.parent = parent;
115
return child;
116
}
117
118
case REACT_COROUTINE_TYPE: {
119
const coroutine = (newChildren : ReactCoroutine);
119
- const child = ReactFiber.createFiberFromCoroutine(coroutine);
120
+ const child = ReactFiber.createFiberFromCoroutine(coroutine, priority);
121
child.parent = parent;
122
return child;
123
}
@@ -127,7 +128,7 @@ function createFirstChild(parent, existingChild, newChildren) {
128
// the fragment.
129
const yieldNode = (newChildren : ReactYield);
130
const reifiedYield = ReactReifiedYield.createReifiedYield(yieldNode);
130
- const child = ReactFiber.createFiberFromYield(yieldNode);
131
+ const child = ReactFiber.createFiberFromYield(yieldNode, priority);
132
child.output = reifiedYield;
133
child.parent = parent;
134
return child;
@@ -140,10 +141,10 @@ function createFirstChild(parent, existingChild, newChildren) {
141
var existing : ?Fiber = existingChild;
142
for (var i = 0; i < newChildren.length; i++) {
143
if (prev == null) {
143
- prev = createFirstChild(parent, existing, newChildren[i]);
144
+ prev = createFirstChild(parent, existing, newChildren[i], priority);
145
first = prev;
146
} else {
146
- prev = createSubsequentChild(parent, existing, prev, newChildren[i]);
147
+ prev = createSubsequentChild(parent, existing, prev, newChildren[i], priority);
148
}
149
if (prev && existing) {
150
// TODO: This is not correct because there could've been more
@@ -160,6 +161,6 @@ function createFirstChild(parent, existingChild, newChildren) {
161
162
// TODO: This API won't work because we'll need to transfer the side-effects of
163
// unmounting children to the parent.
163
-exports.reconcileChildFibers = function(parent : Fiber, currentFirstChild : ?Fiber, newChildren : ReactNodeList) : ?Fiber {
164
- return createFirstChild(parent, currentFirstChild, newChildren);
164
+exports.reconcileChildFibers = function(parent : Fiber, currentFirstChild : ?Fiber, newChildren : ReactNodeList, priority : PriorityLevel) : ?Fiber {
165
+ return createFirstChild(parent, currentFirstChild, newChildren, priority);
166
};
src/renderers/shared/fiber/ReactFiber.js
+10
-5
@@ -122,13 +122,14 @@ function shouldConstruct(Component) {
122
}
123
124
// This is used to create an alternate fiber to do work on.
125
-exports.cloneFiber = function(fiber : Fiber) : Fiber {
125
+exports.cloneFiber = function(fiber : Fiber, priorityLevel : PriorityLevel) : Fiber {
126
// We use a double buffering pooling technique because we know that we'll only
127
// ever need at most two versions of a tree. We pool the "other" unused node
128
// that we're free to reuse. This is lazily created to avoid allocating extra
129
// objects for things that are never updated. It also allow us to reclaim the
130
// extra memory if needed.
131
if (fiber.alternate) {
132
+ fiber.alternate.pendingWorkPriority = priorityLevel;
133
return fiber.alternate;
134
}
135
// This should not have an alternate already
@@ -144,19 +145,22 @@ exports.cloneFiber = function(fiber : Fiber) : Fiber {
145
alt.type = fiber.type;
146
alt.stateNode = fiber.stateNode;
147
alt.alternate = fiber;
148
+ alt.pendingWorkPriority = priorityLevel;
149
fiber.alternate = alt;
150
return alt;
151
};
152
151
-exports.createHostContainerFiber = function(containerInfo : ?Object) {
153
+exports.createHostContainerFiber = function(containerInfo : ?Object, priorityLevel : PriorityLevel) {
154
const fiber = createFiber(HostContainer, null);
155
fiber.stateNode = containerInfo;
156
+ fiber.pendingWorkPriority = priorityLevel;
157
return fiber;
158
};
159
157
-exports.createFiberFromElement = function(element : ReactElement) {
160
+exports.createFiberFromElement = function(element : ReactElement, priorityLevel : PriorityLevel) {
161
const fiber = exports.createFiberFromElementType(element.type, element.key);
162
fiber.pendingProps = element.props;
163
+ fiber.pendingWorkPriority = priorityLevel;
164
return fiber;
165
};
166
@@ -179,14 +183,15 @@ exports.createFiberFromElementType = function(type : mixed, key : null | string)
183
return fiber;
184
};
185
182
-exports.createFiberFromCoroutine = function(coroutine : ReactCoroutine) {
186
+exports.createFiberFromCoroutine = function(coroutine : ReactCoroutine, priorityLevel : PriorityLevel) {
187
const fiber = createFiber(CoroutineComponent, coroutine.key);
188
fiber.type = coroutine.handler;
189
fiber.pendingProps = coroutine;
190
+ fiber.pendingWorkPriority = priorityLevel;
191
return fiber;
192
};
193
189
-exports.createFiberFromYield = function(yieldNode : ReactYield) {
194
+exports.createFiberFromYield = function(yieldNode : ReactYield, priorityLevel : PriorityLevel) {
195
const fiber = createFiber(YieldComponent, yieldNode.key);
196
return fiber;
197
};
src/renderers/shared/fiber/ReactFiberBeginWork.js
+3
-1
@@ -29,10 +29,12 @@ var {
29
} = ReactTypeOfWork;
30
31
function reconcileChildren(current, workInProgress, nextChildren) {
32
+ const priority = workInProgress.pendingWorkPriority;
33
workInProgress.child = ReactChildFiber.reconcileChildFibers(
34
workInProgress,
35
current ? current.child : null,
35
- nextChildren
36
+ nextChildren,
37
+ priority
38
);
39
}
40
src/renderers/shared/fiber/ReactFiberCompleteWork.js
+4
-1
@@ -83,10 +83,13 @@ function moveCoroutineToHandlerPhase(current : ?Fiber, workInProgress : Fiber) {
83
var nextChildren = fn(props, yields);
84
85
var currentFirstChild = current ? current.stateNode : null;
86
+ // Inherit the priority of the parent.
87
+ const priority = workInProgress.pendingWorkPriority;
88
workInProgress.stateNode = ReactChildFiber.reconcileChildFibers(
89
workInProgress,
90
currentFirstChild,
89
- nextChildren
91
+ nextChildren,
92
+ priority
93
);
94
return workInProgress.stateNode;
95
}
src/renderers/shared/fiber/ReactFiberReconciler.js
+1
-2
@@ -219,10 +219,9 @@ module.exports = function<T, P, I>(config : HostConfig<T, P, I>) : Reconciler {
219
return {
220
221
mountContainer(element : ReactElement<any>, containerInfo : ?Object) : OpaqueNode {
222
- const container = ReactFiber.createHostContainerFiber(containerInfo);
222
+ const container = ReactFiber.createHostContainerFiber(containerInfo, LowPriority);
223
container.alternate = container;
224
container.pendingProps = element;
225
- container.pendingWorkPriority = LowPriority;
225
226
scheduleLowPriWork(container);
227