Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions src/renderers/shared/fiber/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,11 +518,49 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
} else if (nextCoroutine === null || workInProgress.memoizedProps === nextCoroutine) {
return bailoutOnAlreadyFinishedWork(current, workInProgress);
}
reconcileChildren(current, workInProgress, nextCoroutine.children);

const nextChildren = nextCoroutine.children;
const priorityLevel = workInProgress.pendingWorkPriority;

// The following is a fork of reconcileChildrenAtPriority but using
// stateNode to store the child.

// At this point any memoization is no longer valid since we'll have changed
// the children.
workInProgress.memoizedProps = null;
if (!current) {
workInProgress.stateNode = mountChildFibersInPlace(
workInProgress,
workInProgress.stateNode,
nextChildren,
priorityLevel
);
} else if (current.child === workInProgress.child) {
clearDeletions(workInProgress);

workInProgress.stateNode = reconcileChildFibers(
workInProgress,
workInProgress.stateNode,
nextChildren,
priorityLevel
);

transferDeletions(workInProgress);
} else {
workInProgress.stateNode = reconcileChildFibersInPlace(
workInProgress,
workInProgress.stateNode,
nextChildren,
priorityLevel
);

transferDeletions(workInProgress);
}

memoizeProps(workInProgress, nextCoroutine);
// This doesn't take arbitrary time so we could synchronously just begin
// eagerly do the work of workInProgress.child as an optimization.
return workInProgress.child;
return workInProgress.stateNode;
}

function updatePortalComponent(current, workInProgress) {
Expand Down
4 changes: 0 additions & 4 deletions src/renderers/shared/fiber/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
while (node.tag !== HostComponent && node.tag !== HostText) {
// If it is not host node and, we might have a host node inside it.
// Try to search down until we find one.
// TODO: For coroutines, this will have to search the stateNode.
if (node.effectTag & Placement) {
// If we don't have a child, try the siblings instead.
continue siblings;
Expand Down Expand Up @@ -198,7 +197,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
// down its children. Instead, we'll get insertions from each child in
// the portal directly.
} else if (node.child) {
// TODO: Coroutines need to visit the stateNode.
node.child.return = node;
node = node.child;
continue;
Expand Down Expand Up @@ -229,7 +227,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
// Visit children because they may contain more composite or host nodes.
// Skip portals because commitUnmount() currently visits them recursively.
if (node.child && node.tag !== HostPortal) {
// TODO: Coroutines need to visit the stateNode.
node.child.return = node;
node = node.child;
continue;
Expand Down Expand Up @@ -273,7 +270,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
commitUnmount(node);
// Visit children because we may find more host components below.
if (node.child) {
// TODO: Coroutines need to visit the stateNode.
node.child.return = node;
node = node.child;
continue;
Expand Down
23 changes: 17 additions & 6 deletions src/renderers/shared/fiber/ReactFiberCompleteWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,33 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
popHostContainer,
} = hostContext;

function markChildAsProgressed(current, workInProgress, priorityLevel) {
// We now have clones. Let's store them as the currently progressed work.
workInProgress.progressedChild = workInProgress.child;
workInProgress.progressedPriority = priorityLevel;
if (current) {
// We also store it on the current. When the alternate swaps in we can
// continue from this point.
current.progressedChild = workInProgress.progressedChild;
current.progressedPriority = workInProgress.progressedPriority;
}
}

function markUpdate(workInProgress : Fiber) {
// Tag the fiber with an update effect. This turns a Placement into
// an UpdateAndPlacement.
workInProgress.effectTag |= Update;
}

function appendAllYields(yields : Array<ReifiedYield>, workInProgress : Fiber) {
let node = workInProgress.child;
let node = workInProgress.stateNode;
while (node) {
if (node.tag === HostComponent || node.tag === HostText ||
node.tag === HostPortal) {
throw new Error('A coroutine cannot have host component children.');
} else if (node.tag === YieldComponent) {
yields.push(node.type);
} else if (node.child) {
// TODO: Coroutines need to visit the stateNode.
node.child.return = node;
node = node.child;
continue;
Expand Down Expand Up @@ -123,16 +134,17 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
var props = coroutine.props;
var nextChildren = fn(props, yields);

var currentFirstChild = current ? current.stateNode : null;
var currentFirstChild = current ? current.child : null;
// Inherit the priority of the returnFiber.
const priority = workInProgress.pendingWorkPriority;
workInProgress.stateNode = reconcileChildFibers(
workInProgress.child = reconcileChildFibers(
workInProgress,
currentFirstChild,
nextChildren,
priority
);
return workInProgress.stateNode;
markChildAsProgressed(current, workInProgress, priority);
return workInProgress.child;
}

function appendAllChildren(parent : I, workInProgress : Fiber) {
Expand All @@ -147,7 +159,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
// down its children. Instead, we'll get insertions from each child in
// the portal directly.
} else if (node.child) {
// TODO: Coroutines need to visit the stateNode.
node = node.child;
continue;
}
Expand Down
2 changes: 2 additions & 0 deletions src/renderers/shared/fiber/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
newPriority = getPendingPriority(queue);
}

// TODO: Coroutines need to visit stateNode

// progressedChild is going to be the child set with the highest priority.
// Either it is the same as child, or it just bailed out because it choose
// not to do the work.
Expand Down
1 change: 0 additions & 1 deletion src/renderers/shared/fiber/ReactFiberTreeReflection.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ exports.findCurrentHostFiber = function(parent : Fiber) : Fiber | null {
return node;
} else if (node.child) {
// TODO: If we hit a Portal, we're supposed to skip it.
// TODO: Coroutines need to visit the stateNode.
node.child.return = node;
node = node.child;
continue;
Expand Down
4 changes: 1 addition & 3 deletions src/renderers/shared/fiber/__tests__/ReactCoroutine-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,8 @@ describe('ReactCoroutine', () => {

expect(ops).toEqual([
'Unmount Parent',
// TODO: This should happen in the order Child, Continuation which it
// will once we swap stateNode and child positions of these.
'Unmount Continuation',
'Unmount Child',
'Unmount Continuation',
]);

});
Expand Down
1 change: 0 additions & 1 deletion src/test/ReactTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ function findAllInRenderedFiberTreeInternal(fiber, test) {
}
}
if (node.child) {
// TODO: Coroutines need to visit the stateNode.
node.child.return = node;
node = node.child;
continue;
Expand Down