@samitouri / QOS-React-2 / commits / a7afc064bd

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.

Sebastian Markbage committed Sep 6, 2016 at 14:05 UTC a7afc064bd0909933119ffb491198df13872bfa9
4 files changed +10 -11
src/renderers/shared/fiber/ReactChildFiber.js
+1 -2
@@ -236,11 +236,10 @@ function cloneSiblings(current : Fiber, workInProgress : Fiber, returnFiber : Fi
236 workInProgress.sibling = null;
237 }
238
239 -exports.cloneChildFibers = function(workInProgress : Fiber) {
239 +exports.cloneChildFibers = function(current : ?Fiber, workInProgress : Fiber) {
240 if (!workInProgress.child) {
241 return;
242 }
243 - const current = workInProgress.alternate;
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
src/renderers/shared/fiber/ReactFiberBeginWork.js
+5 -5
@@ -166,15 +166,15 @@ module.exports = function<T, P, I, C>(config : HostConfig<T, P, I, C>) {
166 if (typeof value === 'object' && value && typeof value.render === 'function') {
167 // Proceed under the assumption that this is a class instance
168 workInProgress.tag = ClassComponent;
169 - if (workInProgress.alternate) {
170 - workInProgress.alternate.tag = ClassComponent;
169 + if (current) {
170 + current.tag = ClassComponent;
171 }
172 value = value.render();
173 } else {
174 // Proceed under the assumption that this is a functional component
175 workInProgress.tag = FunctionalComponent;
176 - if (workInProgress.alternate) {
177 - workInProgress.alternate.tag = FunctionalComponent;
176 + if (current) {
177 + current.tag = FunctionalComponent;
178 }
179 }
180 reconcileChildren(current, workInProgress, value);
@@ -225,7 +225,7 @@ module.exports = function<T, P, I, C>(config : HostConfig<T, P, I, C>) {
225 // return null;
226 // }
227
228 - cloneChildFibers(workInProgress);
228 + cloneChildFibers(current, workInProgress);
229 markChildAsProgressed(current, workInProgress, priorityLevel);
230 return workInProgress.child;
231 }
src/renderers/shared/fiber/ReactFiberCommitWork.js
+2 -3
@@ -28,7 +28,7 @@ module.exports = function<T, P, I, C>(config : HostConfig<T, P, I, C>) {
28 const updateContainer = config.updateContainer;
29 const commitUpdate = config.commitUpdate;
30
31 - function commitWork(finishedWork : Fiber) : void {
31 + function commitWork(current : ?Fiber, finishedWork : Fiber) : void {
32 switch (finishedWork.tag) {
33 case ClassComponent: {
34 // TODO: Fire componentDidMount/componentDidUpdate, update refs
@@ -43,14 +43,13 @@ module.exports = function<T, P, I, C>(config : HostConfig<T, P, I, C>) {
43 return;
44 }
45 case HostComponent: {
46 - if (finishedWork.stateNode == null || !finishedWork.alternate) {
46 + if (finishedWork.stateNode == null || !current) {
47 throw new Error('This should only be done during updates.');
48 }
49 // Commit the work prepared earlier.
50 const child = finishedWork.child;
51 const children = (child && !child.sibling) ? (child.output : ?Fiber | I) : child;
52 const newProps = finishedWork.memoizedProps;
53 - const current = finishedWork.alternate;
53 const oldProps = current.memoizedProps;
54 const instance : I = finishedWork.stateNode;
55 commitUpdate(instance, oldProps, newProps, children);
src/renderers/shared/fiber/ReactFiberScheduler.js
+2 -1
@@ -89,7 +89,8 @@ module.exports = function<T, P, I, C>(config : HostConfig<T, P, I, C>) {
89 // TODO: Error handling.
90 let effectfulFiber = finishedWork.firstEffect;
91 while (effectfulFiber) {
92 - commitWork(effectfulFiber);
92 + const current = effectfulFiber.alternate;
93 + commitWork(current, effectfulFiber);
94 const next = effectfulFiber.nextEffect;
95 // Ensure that we clean these up so that we don't accidentally keep them.
96 // I'm not actually sure this matters because we can't reset firstEffect