Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Effects list refactor continued: did-bailout flag #19322

Merged
merged 18 commits into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Eagerly set Deletions effect on Fiber when adding child to deletions …
…array
  • Loading branch information
Brian Vaughn committed Jul 11, 2020
commit d34e3e5bd9bc260872d32eae1665c1e9e33894df
2 changes: 2 additions & 0 deletions packages/react-reconciler/src/ReactChildFiber.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ function ChildReconciler(shouldTrackSideEffects) {
} else {
returnFiber.deletions.push(childToDelete);
}
// TODO (effects) Rename this to better reflect its new usage (e.g. ChildDeletions)
returnFiber.effectTag |= Deletion;
bvaughn marked this conversation as resolved.
Show resolved Hide resolved
childToDelete.nextEffect = null;
childToDelete.effectTag = Deletion;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/react-reconciler/src/ReactFiberBeginWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -2071,6 +2071,8 @@ function updateSuspensePrimaryChildren(
} else {
workInProgress.deletions.push(currentFallbackChildFragment);
}
// TODO (effects) Rename this to better reflect its new usage (e.g. ChildDeletions)
workInProgress.effectTag |= Deletion;
}

workInProgress.child = primaryChildFragment;
Expand Down Expand Up @@ -3052,6 +3054,8 @@ function remountFiber(
} else {
returnFiber.deletions.push(current);
}
// TODO (effects) Rename this to better reflect its new usage (e.g. ChildDeletions)
returnFiber.effectTag |= Deletion;
bvaughn marked this conversation as resolved.
Show resolved Hide resolved
current.nextEffect = null;
current.effectTag = Deletion;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ function deleteHydratableInstance(
} else {
returnFiber.deletions.push(childToDelete);
}
// TODO (effects) Rename this to better reflect its new usage (e.g. ChildDeletions)
returnFiber.effectTag |= Deletion;

// This might seem like it belongs on progressedFirstDeletion. However,
// these children are not part of the reconciliation list of children.
Expand Down
44 changes: 4 additions & 40 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ let globalMostRecentFallbackTime: number = 0;
const FALLBACK_THROTTLE_MS: number = 500;
const DEFAULT_TIMEOUT_MS: number = 5000;

let nextEffect: Fiber | null = null;
let hasUncaughtError = false;
let firstUncaughtError = null;
let legacyErrorBoundariesThatAlreadyFailed: Set<mixed> | null = null;
Expand Down Expand Up @@ -1805,10 +1804,8 @@ function resetChildLanes(completedWork: Fiber) {
);

subtreeTag |= child.subtreeTag;
// TODO (effects) Document why this exception is important
subtreeTag |= child.effectTag & HostEffectMask;
if (child.deletions !== null) {
subtreeTag |= Deletion;
}

if ((child.effectTag & Incomplete) !== NoEffect) {
childrenDidNotComplete = true;
Expand Down Expand Up @@ -1850,10 +1847,8 @@ function resetChildLanes(completedWork: Fiber) {
);

subtreeTag |= child.subtreeTag;
// TODO (effects) Document why this exception is important
subtreeTag |= child.effectTag & HostEffectMask;
if (child.deletions !== null) {
subtreeTag |= Deletion;
}

if ((child.effectTag & Incomplete) !== NoEffect) {
childrenDidNotComplete = true;
Expand Down Expand Up @@ -2013,8 +2008,6 @@ function commitRootImpl(root, renderPriorityLevel) {
// layout, but class component lifecycles also fire here for legacy reasons.
commitLayoutEffects(finishedWork, root, lanes);

nextEffect = null;

// Tell Scheduler to yield at the end of the frame, so the browser has an
// opportunity to paint.
requestPaint();
Expand Down Expand Up @@ -2047,19 +2040,7 @@ function commitRootImpl(root, renderPriorityLevel) {
pendingPassiveEffectsLanes = lanes;
pendingPassiveEffectsRenderPriority = renderPriorityLevel;
} else {
// We are done with the effect chain at this point so let's clear the
// nextEffect pointers to assist with GC. If we have passive effects, we'll
// clear this in flushPassiveEffects.
// TODO (effects) Traverse with subtreeTag Deletion and detatch deletions array only
nextEffect = firstEffect;
while (nextEffect !== null) {
const nextNextEffect = nextEffect.nextEffect;
nextEffect.nextEffect = null;
if (nextEffect.effectTag & Deletion) {
detachFiberAfterEffects(nextEffect);
}
nextEffect = nextNextEffect;
}
// TODO (effects) Detach sibling pointers for deleted Fibers
}

// Read this again, since an effect might have updated it
Expand Down Expand Up @@ -2658,20 +2639,7 @@ function flushPassiveEffectsImpl() {
}
}

// Note: This currently assumes there are no passive effects on the root fiber
// because the root is not part of its own effect list.
// This could change in the future.
// TODO (effects) Traverse with subtreeTag Deletion and detatch deletions array only
let effect = root.current.firstEffect;
while (effect !== null) {
const nextNextEffect = effect.nextEffect;
// Remove nextEffect pointer to assist GC
effect.nextEffect = null;
if (effect.effectTag & Deletion) {
detachFiberAfterEffects(effect);
}
effect = nextNextEffect;
}
// TODO (effects) Detach sibling pointers for deleted Fibers

if (enableProfilerTimer && enableProfilerCommitHooks) {
const profilerEffects = pendingPassiveProfilerEffects;
Expand Down Expand Up @@ -3762,7 +3730,3 @@ export function act(callback: () => Thenable<mixed>): Thenable<void> {
};
}
}

function detachFiberAfterEffects(fiber: Fiber): void {
fiber.sibling = null;
}