From a7afc064bd0909933119ffb491198df13872bfa9 Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Tue, 6 Sep 2016 14:05:26 -0700 Subject: [PATCH] Pass current instead of picking it up from alternate This colocates the reliance on alternate with the scheduler, so that we have the option to not use this, or more easily break apart the initial mount phase into an optimized path. --- src/renderers/shared/fiber/ReactChildFiber.js | 3 +-- src/renderers/shared/fiber/ReactFiberBeginWork.js | 10 +++++----- src/renderers/shared/fiber/ReactFiberCommitWork.js | 5 ++--- src/renderers/shared/fiber/ReactFiberScheduler.js | 3 ++- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/renderers/shared/fiber/ReactChildFiber.js b/src/renderers/shared/fiber/ReactChildFiber.js index 699b0e7883..7d9fe2e1d1 100644 --- a/src/renderers/shared/fiber/ReactChildFiber.js +++ b/src/renderers/shared/fiber/ReactChildFiber.js @@ -236,11 +236,10 @@ function cloneSiblings(current : Fiber, workInProgress : Fiber, returnFiber : Fi workInProgress.sibling = null; } -exports.cloneChildFibers = function(workInProgress : Fiber) { +exports.cloneChildFibers = function(current : ?Fiber, workInProgress : Fiber) { if (!workInProgress.child) { return; } - const current = workInProgress.alternate; if (!current || workInProgress.child !== current.child) { // If there is no alternate, then we don't need to clone the children. // If the children of the alternate fiber is a different set, then we don't diff --git a/src/renderers/shared/fiber/ReactFiberBeginWork.js b/src/renderers/shared/fiber/ReactFiberBeginWork.js index feabc7838b..a21bd4059a 100644 --- a/src/renderers/shared/fiber/ReactFiberBeginWork.js +++ b/src/renderers/shared/fiber/ReactFiberBeginWork.js @@ -166,15 +166,15 @@ module.exports = function(config : HostConfig) { if (typeof value === 'object' && value && typeof value.render === 'function') { // Proceed under the assumption that this is a class instance workInProgress.tag = ClassComponent; - if (workInProgress.alternate) { - workInProgress.alternate.tag = ClassComponent; + if (current) { + current.tag = ClassComponent; } value = value.render(); } else { // Proceed under the assumption that this is a functional component workInProgress.tag = FunctionalComponent; - if (workInProgress.alternate) { - workInProgress.alternate.tag = FunctionalComponent; + if (current) { + current.tag = FunctionalComponent; } } reconcileChildren(current, workInProgress, value); @@ -225,7 +225,7 @@ module.exports = function(config : HostConfig) { // return null; // } - cloneChildFibers(workInProgress); + cloneChildFibers(current, workInProgress); markChildAsProgressed(current, workInProgress, priorityLevel); return workInProgress.child; } diff --git a/src/renderers/shared/fiber/ReactFiberCommitWork.js b/src/renderers/shared/fiber/ReactFiberCommitWork.js index c7a9f2f710..2e3e8ae3d0 100644 --- a/src/renderers/shared/fiber/ReactFiberCommitWork.js +++ b/src/renderers/shared/fiber/ReactFiberCommitWork.js @@ -28,7 +28,7 @@ module.exports = function(config : HostConfig) { const updateContainer = config.updateContainer; const commitUpdate = config.commitUpdate; - function commitWork(finishedWork : Fiber) : void { + function commitWork(current : ?Fiber, finishedWork : Fiber) : void { switch (finishedWork.tag) { case ClassComponent: { // TODO: Fire componentDidMount/componentDidUpdate, update refs @@ -43,14 +43,13 @@ module.exports = function(config : HostConfig) { return; } case HostComponent: { - if (finishedWork.stateNode == null || !finishedWork.alternate) { + if (finishedWork.stateNode == null || !current) { throw new Error('This should only be done during updates.'); } // Commit the work prepared earlier. const child = finishedWork.child; const children = (child && !child.sibling) ? (child.output : ?Fiber | I) : child; const newProps = finishedWork.memoizedProps; - const current = finishedWork.alternate; const oldProps = current.memoizedProps; const instance : I = finishedWork.stateNode; commitUpdate(instance, oldProps, newProps, children); diff --git a/src/renderers/shared/fiber/ReactFiberScheduler.js b/src/renderers/shared/fiber/ReactFiberScheduler.js index 057f9f7455..e04c846f20 100644 --- a/src/renderers/shared/fiber/ReactFiberScheduler.js +++ b/src/renderers/shared/fiber/ReactFiberScheduler.js @@ -89,7 +89,8 @@ module.exports = function(config : HostConfig) { // TODO: Error handling. let effectfulFiber = finishedWork.firstEffect; while (effectfulFiber) { - commitWork(effectfulFiber); + const current = effectfulFiber.alternate; + commitWork(current, effectfulFiber); const next = effectfulFiber.nextEffect; // Ensure that we clean these up so that we don't accidentally keep them. // I'm not actually sure this matters because we can't reset firstEffect