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: passive effects traversal #19374

Merged
merged 11 commits into from
Jul 29, 2020
Prev Previous commit
Next Next commit
Add persistent, Static subtreeTag
This allows certain concepts to persist without recalculting them, e.g. whether a subtree contains passive effects or portals. This helps for cases like nested unmounts that contain deep passive effects.
  • Loading branch information
Brian Vaughn committed Jul 29, 2020
commit fe2e311db5db1ae3ed2b1263ac577438e45bb204
7 changes: 5 additions & 2 deletions packages/react-reconciler/src/ReactFiber.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ import {
enableBlocksAPI,
} from 'shared/ReactFeatureFlags';
import {NoEffect, Placement} from './ReactSideEffectTags';
import {NoEffect as NoSubtreeEffect} from './ReactSubtreeTags';
import {
NoEffect as NoSubtreeEffect,
Static as StaticSubtreeEffects,
} from './ReactSubtreeTags';
import {ConcurrentRoot, BlockingRoot} from './ReactRootTags';
import {
IndeterminateComponent,
Expand Down Expand Up @@ -290,7 +293,6 @@ export function createWorkInProgress(current: Fiber, pendingProps: any): Fiber {
// We already have an alternate.
// Reset the effect tag.
workInProgress.effectTag = NoEffect;
workInProgress.subtreeTag = NoSubtreeEffect;
workInProgress.deletions = null;

// The effect list is no longer valid.
Expand All @@ -308,6 +310,7 @@ export function createWorkInProgress(current: Fiber, pendingProps: any): Fiber {
}
}

workInProgress.subtreeTag = current.subtreeTag & StaticSubtreeEffects;
workInProgress.childLanes = current.childLanes;
workInProgress.lanes = current.lanes;

Expand Down
13 changes: 0 additions & 13 deletions packages/react-reconciler/src/ReactFiberCommitWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -881,19 +881,6 @@ function commitUnmount(
if ((tag & HookPassive) !== NoHookEffect) {
effect.tag |= HookHasEffect;
bvaughn marked this conversation as resolved.
Show resolved Hide resolved

// subtreeTags bubble in resetChildLanes which doens't get called for unmounted subtrees.
// So in the case of unmounts, we need to bubble passive effects explicitly.
let ancestor = current.return;
while (ancestor !== null) {
ancestor.subtreeTag |= PassiveSubtreeTag;
const alternate = ancestor.alternate;
if (alternate !== null) {
alternate.subtreeTag |= PassiveSubtreeTag;
}

ancestor = ancestor.return;
}

current.effectTag |= Passive;
bvaughn marked this conversation as resolved.
Show resolved Hide resolved

if (__DEV__) {
Expand Down
5 changes: 5 additions & 0 deletions packages/react-reconciler/src/ReactSubtreeTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ export const BeforeMutation = /* */ 0b0001;
export const Mutation = /* */ 0b0010;
export const Layout = /* */ 0b0100;
export const Passive = /* */ 0b1000;

// Union of tags that don't get reset on clones.
// This allows certain concepts to persist without recalculting them,
// e.g. whether a subtree contains passive effects or portals.
export const Static = /* */ 0b1000;