Skip to content

Commit

Permalink
Made deletions field nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Jul 7, 2020
1 parent 1033552 commit 2631117
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 13 deletions.
6 changes: 5 additions & 1 deletion packages/react-reconciler/src/ReactChildFiber.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,11 @@ function ChildReconciler(shouldTrackSideEffects) {
} else {
returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
}
returnFiber.deletions.push(childToDelete);
if (returnFiber.deletions === null) {
returnFiber.deletions = [childToDelete];
} else {
returnFiber.deletions.push(childToDelete);
}
childToDelete.nextEffect = null;
childToDelete.effectTag = Deletion;
}
Expand Down
12 changes: 10 additions & 2 deletions packages/react-reconciler/src/ReactFiberBeginWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -2066,7 +2066,11 @@ function updateSuspensePrimaryChildren(
currentFallbackChildFragment.nextEffect = null;
currentFallbackChildFragment.effectTag = Deletion;
workInProgress.firstEffect = workInProgress.lastEffect = currentFallbackChildFragment;
workInProgress.deletions.push(currentFallbackChildFragment);
if (workInProgress.deletions === null) {
workInProgress.deletions = [currentFallbackChildFragment];
} else {
workInProgress.deletions.push(currentFallbackChildFragment);
}
}

workInProgress.child = primaryChildFragment;
Expand Down Expand Up @@ -3043,7 +3047,11 @@ function remountFiber(
} else {
returnFiber.firstEffect = returnFiber.lastEffect = current;
}
returnFiber.deletions.push(current);
if (returnFiber.deletions === null) {
returnFiber.deletions = [current];
} else {
returnFiber.deletions.push(current);
}
current.nextEffect = null;
current.effectTag = Deletion;

Expand Down
4 changes: 1 addition & 3 deletions packages/react-reconciler/src/ReactFiberCompleteWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -1066,9 +1066,7 @@ function completeWork(
// TODO (effects) This probably isn't the best approach. Discuss with Brian
let child = workInProgress.child;
while (child !== null) {
if (child.deletions.length > 0) {
child.deletions = [];
}
child.deletions = null;
child = child.sibling;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ function deleteHydratableInstance(
childToDelete.stateNode = instance;
childToDelete.return = returnFiber;
childToDelete.effectTag = Deletion;
returnFiber.deletions.push(childToDelete);
if (returnFiber.deletions === null) {
returnFiber.deletions = [childToDelete];
} else {
returnFiber.deletions.push(childToDelete);
}

// This might seem like it belongs on progressedFirstDeletion. However,
// these children are not part of the reconciliation list of children.
Expand Down
14 changes: 9 additions & 5 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -1728,7 +1728,7 @@ function completeUnitOfWork(unitOfWork: Fiber): void {
returnFiber.firstEffect = returnFiber.lastEffect = null;
returnFiber.effectTag |= Incomplete;
returnFiber.subtreeTag = NoEffect;
returnFiber.deletions = [];
returnFiber.deletions = null;
}
}

Expand Down Expand Up @@ -1789,7 +1789,7 @@ function resetChildLanes(completedWork: Fiber) {

subtreeTag |= child.subtreeTag;
subtreeTag |= child.effectTag & HostEffectMask;
if (child.deletions.length > 0) {
if (child.deletions !== null) {
subtreeTag |= Deletion;
}

Expand Down Expand Up @@ -1834,7 +1834,7 @@ function resetChildLanes(completedWork: Fiber) {

subtreeTag |= child.subtreeTag;
subtreeTag |= child.effectTag & HostEffectMask;
if (child.deletions.length > 0) {
if (child.deletions !== null) {
subtreeTag |= Deletion;
}

Expand Down Expand Up @@ -2125,7 +2125,9 @@ function commitRootImpl(root, renderPriorityLevel) {
}

function commitBeforeMutationEffects(fiber: Fiber) {
commitBeforeMutationEffectsDeletions(fiber.deletions);
if (fiber.deletions !== null) {
commitBeforeMutationEffectsDeletions(fiber.deletions);
}

if (fiber.child !== null) {
const primarySubtreeTag =
Expand Down Expand Up @@ -2213,7 +2215,9 @@ function commitMutationEffects(
root: FiberRoot,
renderPriorityLevel,
) {
commitMutationEffectsDeletions(fiber.deletions, root, renderPriorityLevel);
if (fiber.deletions !== null) {
commitMutationEffectsDeletions(fiber.deletions, root, renderPriorityLevel);
}

if (fiber.child !== null) {
const primarySubtreeTag =
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactInternalTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export type Fiber = {|
// Effect
effectTag: SideEffectTag,
subtreeTag: SideEffectTag,
deletions: Array<Fiber>,
deletions: Array<Fiber> | null,

// Singly linked list fast path to the next fiber with side-effects.
nextEffect: Fiber | null,
Expand Down

0 comments on commit 2631117

Please sign in to comment.