@samitouri / QOS-React-2 / commits / 52011d58b0

Restructure clone child fiber a bit to make it clearer

Sebastian Markbage committed Sep 6, 2016 at 14:17 UTC 52011d58b0f631396973c2cd3a53be3fa5a6add3
1 file changed +23 -29
src/renderers/shared/fiber/ReactChildFiber.js
+23 -29
@@ -67,7 +67,6 @@ function ChildReconciler(shouldClone) {
67 clone.pendingWorkPriority = priority;
68 }
69 clone.pendingProps = element.props;
70 - // clone.child = existingChild.child;
70 clone.sibling = null;
71 clone.return = returnFiber;
72 previousSibling.sibling = clone;
@@ -139,7 +138,6 @@ function ChildReconciler(shouldClone) {
138 clone.pendingWorkPriority = priority;
139 }
140 clone.pendingProps = element.props;
142 - // clone.child = existingChild.child;
141 clone.sibling = null;
142 clone.return = returnFiber;
143 return clone;
@@ -240,34 +238,30 @@ exports.cloneChildFibers = function(current : ?Fiber, workInProgress : Fiber) {
238 if (!workInProgress.child) {
239 return;
240 }
243 - if (!current || workInProgress.child !== current.child) {
244 - // If there is no alternate, then we don't need to clone the children.
245 - // If the children of the alternate fiber is a different set, then we don't
246 - // need to clone. We need to reset the return fiber though since we'll
247 - // traverse down into them.
248 - let child = workInProgress.child;
249 - while (child) {
250 - child.return = workInProgress;
251 - child = child.sibling;
252 - }
253 - return;
241 + if (current && workInProgress.child === current.child) {
242 + // We use workInProgress.child since that lets Flow know that it can't be
243 + // null since we validated that already. However, as the line above suggests
244 + // they're actually the same thing.
245 + const currentChild = workInProgress.child;
246 + // TODO: This used to reset the pending priority. Not sure if that is needed.
247 + // workInProgress.pendingWorkPriority = current.pendingWorkPriority;
248 + // TODO: The below priority used to be set to NoWork which would've
249 + // dropped work. This is currently unobservable but will become
250 + // observable when the first sibling has lower priority work remaining
251 + // than the next sibling. At that point we should add tests that catches
252 + // this.
253 + const newChild = cloneFiber(currentChild, currentChild.pendingWorkPriority);
254 + workInProgress.child = newChild;
255 + cloneSiblings(currentChild, newChild, workInProgress);
256 }
255 - // TODO: This used to reset the pending priority. Not sure if that is needed.
256 - // workInProgress.pendingWorkPriority = current.pendingWorkPriority;
257
258 - // TODO: The below priority used to be set to NoWork which would've
259 - // dropped work. This is currently unobservable but will become
260 - // observable when the first sibling has lower priority work remaining
261 - // than the next sibling. At that point we should add tests that catches
262 - // this.
263 -
264 - const currentChild = workInProgress.child;
265 - if (!currentChild) {
266 - return;
258 + // If there is no alternate, then we don't need to clone the children.
259 + // If the children of the alternate fiber is a different set, then we don't
260 + // need to clone. We need to reset the return fiber though since we'll
261 + // traverse down into them.
262 + let child = workInProgress.child;
263 + while (child) {
264 + child.return = workInProgress;
265 + child = child.sibling;
266 }
268 - workInProgress.child = cloneFiber(
269 - currentChild,
270 - currentChild.pendingWorkPriority
271 - );
272 - cloneSiblings(currentChild, workInProgress.child, workInProgress);
267 };