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