Skip to content

Commit

Permalink
Add persistent, Static subtreeTag
Browse files Browse the repository at this point in the history
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 28, 2020
1 parent d45b066 commit c45bc43
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
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;

// 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;

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;

0 comments on commit c45bc43

Please sign in to comment.