From 3979bb9e247f1da9e906be22857898e28d6ff052 Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Tue, 20 Sep 2016 18:12:20 -0700 Subject: [PATCH] Don't track side-effects unless needed We don't need to track side-effects for a parent that has never been mounted before. It will simply inject all its children when it completes. --- src/renderers/shared/fiber/ReactChildFiber.js | 100 +++++++++--------- 1 file changed, 49 insertions(+), 51 deletions(-) diff --git a/src/renderers/shared/fiber/ReactChildFiber.js b/src/renderers/shared/fiber/ReactChildFiber.js index 8e6a2a5ef7..169f09e4ee 100644 --- a/src/renderers/shared/fiber/ReactChildFiber.js +++ b/src/renderers/shared/fiber/ReactChildFiber.js @@ -56,63 +56,61 @@ const { NoWork, } = ReactPriorityLevel; - -function deleteChild( - returnFiber : Fiber, - childToDelete : Fiber -) { - if (!shouldTrackSideEffects) { - // Noop. - return; - } - - // TODO: Add this child to the side-effect queue for deletion. -} - -function deleteRemainingChildren( - returnFiber : Fiber, - currentFirstChild : ?Fiber -) { - if (!shouldTrackSideEffects) { - // Noop. - return null; - } - // TODO: Add these children to the side-effect queue for deletion. - return null; -} - -function mapAndDeleteRemainingChildren( - returnFiber : Fiber, - currentFirstChild : ?Fiber -) : Map { - // Add the remaining children to a temporary map so that we can find them by - // keys quickly. At the same time, we'll flag them all for deletion. However, - // we will then undo the deletion as we restore children. Implicit (null) keys - // don't get added to this set. - const existingChildren : Map = new Map(); - let existingChild = currentFirstChild; - while (existingChild) { - if (existingChild.key !== null) { - existingChildren.set(existingChild.key, existingChild); - } - // Add everything to the delete queue - // Actually... It is not possible to delete things from the queue since - // we don't have access to the previous link. Does that mean we need a - // second pass to add them? We should be able to keep track of the - // previous deletion as we're iterating through the list the next time. - // That way we know which item to patch when we delete a deletion. - existingChild = existingChild.sibling; - } - return existingChildren; -} - - // This wrapper function exists because I expect to clone the code in each path // to be able to optimize each path individually by branching early. This needs // a compiler or we can do it manually. Helpers that don't need this branching // live outside of this function. function ChildReconciler(shouldClone, shouldTrackSideEffects) { + function deleteChild( + returnFiber : Fiber, + childToDelete : Fiber + ) { + if (!shouldTrackSideEffects) { + // Noop. + return; + } + + // TODO: Add this child to the side-effect queue for deletion. + } + + function deleteRemainingChildren( + returnFiber : Fiber, + currentFirstChild : ?Fiber + ) { + if (!shouldTrackSideEffects) { + // Noop. + return null; + } + // TODO: Add these children to the side-effect queue for deletion. + return null; + } + + function mapAndDeleteRemainingChildren( + returnFiber : Fiber, + currentFirstChild : ?Fiber + ) : Map { + // Add the remaining children to a temporary map so that we can find them by + // keys quickly. At the same time, we'll flag them all for deletion. However, + // we will then undo the deletion as we restore children. Implicit (null) keys + // don't get added to this set. + const existingChildren : Map = new Map(); + let existingChild = currentFirstChild; + while (existingChild) { + if (existingChild.key !== null) { + existingChildren.set(existingChild.key, existingChild); + } + // Add everything to the delete queue + // Actually... It is not possible to delete things from the queue since + // we don't have access to the previous link. Does that mean we need a + // second pass to add them? We should be able to keep track of the + // previous deletion as we're iterating through the list the next time. + // That way we know which item to patch when we delete a deletion. + existingChild = existingChild.sibling; + } + return existingChildren; + } + function useFiber(fiber : Fiber, priority : PriorityLevel) { // We currently set sibling to null and index to 0 here because it is easy // to forget to do before returning it. E.g. for the single child case.