Reset invalid UpdateQueue fields when cloning from current

Similar to what cloneFiber does. No change in behavior, but it's more
consistent this way.
This commit is contained in:
Andrew Clark
2017-01-09 17:14:09 -08:00
parent d4e971a266
commit 288a4c4d6d
2 changed files with 16 additions and 12 deletions
+1 -1
View File
@@ -277,7 +277,7 @@ exports.cloneFiber = function(fiber : Fiber, priorityLevel : PriorityLevel) : Fi
// pendingProps is here for symmetry but is unnecessary in practice for now.
// TODO: Pass in the new pendingProps as an argument maybe?
alt.pendingProps = fiber.pendingProps;
cloneUpdateQueue(alt, fiber);
cloneUpdateQueue(fiber, alt);
alt.pendingWorkPriority = priorityLevel;
alt.memoizedProps = fiber.memoizedProps;
@@ -113,21 +113,25 @@ function ensureUpdateQueue(fiber : Fiber) : UpdateQueue {
}
// Clones an update queue from a source fiber onto its alternate.
function cloneUpdateQueue(alt : Fiber, fiber : Fiber) : UpdateQueue | null {
const sourceQueue = fiber.updateQueue;
if (!sourceQueue) {
function cloneUpdateQueue(current : Fiber, workInProgress : Fiber) : UpdateQueue | null {
const currentQueue = current.updateQueue;
if (!currentQueue) {
// The source fiber does not have an update queue.
alt.updateQueue = null;
workInProgress.updateQueue = null;
return null;
}
// If the alternate already has a queue, reuse the previous object.
const altQueue = alt.updateQueue || {};
altQueue.first = sourceQueue.first;
altQueue.last = sourceQueue.last;
altQueue.hasForceUpdate = sourceQueue.hasForceUpdate;
altQueue.callbackList = sourceQueue.callbackList;
altQueue.isProcessing = sourceQueue.isProcessing;
alt.updateQueue = altQueue;
const altQueue = workInProgress.updateQueue || {};
altQueue.first = currentQueue.first;
altQueue.last = currentQueue.last;
// These fields are invalid by the time we clone from current. Reset them.
altQueue.hasForceUpdate = false;
altQueue.callbackList = null;
altQueue.isProcessing = false;
workInProgress.updateQueue = altQueue;
return altQueue;
}
exports.cloneUpdateQueue = cloneUpdateQueue;