Skip to content

Commit 93a0c28

Browse files
authored
Add static version of Passive subtree tag (#19510)
Creates new subtree tag, PassiveStatic, that represents whether a tree contains any passive effect hooks. It corresponds to the PassiveStatic effect tag, which represents the same concept for an individual fiber. This allows us to remove the PassiveStatic effect tag from PassiveMask. Its presence was causing us to schedule a passive effect phase callback on every render, instead of only when something changed. That's now fixed; this is reflected in the SchedulerProfiler tests. (The naming is getting really confusing. Need to do some bikeshedding.)
1 parent a1c0864 commit 93a0c28

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

packages/react-reconciler/src/ReactFiberWorkLoop.new.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ import {
149149
Mutation as MutationSubtreeTag,
150150
Layout as LayoutSubtreeTag,
151151
Passive as PassiveSubtreeTag,
152+
PassiveStatic as PassiveStaticSubtreeTag,
152153
} from './ReactSubtreeTags';
153154
import {
154155
NoLanePriority,
@@ -1901,6 +1902,9 @@ function resetChildLanes(completedWork: Fiber) {
19011902
if ((effectTag & PassiveMask) !== NoEffect) {
19021903
subtreeTag |= PassiveSubtreeTag;
19031904
}
1905+
if ((effectTag & PassiveStatic) !== NoEffect) {
1906+
subtreeTag |= PassiveStaticSubtreeTag;
1907+
}
19041908

19051909
// When a fiber is cloned, its actualDuration is reset to 0. This value will
19061910
// only be updated if work is done on the fiber (i.e. it doesn't bailout).
@@ -1951,6 +1955,9 @@ function resetChildLanes(completedWork: Fiber) {
19511955
if ((effectTag & PassiveMask) !== NoEffect) {
19521956
subtreeTag |= PassiveSubtreeTag;
19531957
}
1958+
if ((effectTag & PassiveStatic) !== NoEffect) {
1959+
subtreeTag |= PassiveStaticSubtreeTag;
1960+
}
19541961

19551962
child = child.sibling;
19561963
}
@@ -2784,8 +2791,9 @@ function flushPassiveUnmountEffects(firstChild: Fiber): void {
27842791
for (let i = 0; i < deletions.length; i++) {
27852792
const fiberToDelete = deletions[i];
27862793
// If this fiber (or anything below it) has passive effects then traverse the subtree.
2787-
const primaryEffectTag = fiberToDelete.effectTag & PassiveMask;
2788-
const primarySubtreeTag = fiberToDelete.subtreeTag & PassiveSubtreeTag;
2794+
const primaryEffectTag = fiberToDelete.effectTag & PassiveStatic;
2795+
const primarySubtreeTag =
2796+
fiberToDelete.subtreeTag & PassiveStaticSubtreeTag;
27892797
if (
27902798
primarySubtreeTag !== NoSubtreeTag ||
27912799
primaryEffectTag !== NoEffect
@@ -2837,7 +2845,7 @@ function flushPassiveUnmountEffectsInsideOfDeletedTree(
28372845
// Note that this requires checking subtreeTag of the current Fiber,
28382846
// rather than the subtreeTag/effectsTag of the first child,
28392847
// since that would not cover passive effects in siblings.
2840-
const primarySubtreeTag = fiber.subtreeTag & PassiveSubtreeTag;
2848+
const primarySubtreeTag = fiber.subtreeTag & PassiveStaticSubtreeTag;
28412849
if (primarySubtreeTag !== NoSubtreeTag) {
28422850
flushPassiveUnmountEffectsInsideOfDeletedTree(child);
28432851
}

packages/react-reconciler/src/ReactSideEffectTags.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const PassiveStatic = /* */ 0b1000000000000000;
5151
export const BeforeMutationMask = /* */ 0b0000001100001010;
5252
export const MutationMask = /* */ 0b0000010010011110;
5353
export const LayoutMask = /* */ 0b0000000010100100;
54-
export const PassiveMask = /* */ 0b1000001000001000;
54+
export const PassiveMask = /* */ 0b0000001000001000;
5555

5656
// Union of tags that don't get reset on clones.
5757
// This allows certain concepts to persist without recalculting them,

packages/react-reconciler/src/ReactSubtreeTags.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010
export type SubtreeTag = number;
1111

12-
export const NoEffect = /* */ 0b0000;
13-
export const BeforeMutation = /* */ 0b0001;
14-
export const Mutation = /* */ 0b0010;
15-
export const Layout = /* */ 0b0100;
16-
export const Passive = /* */ 0b1000;
12+
export const NoEffect = /* */ 0b00000;
13+
export const BeforeMutation = /* */ 0b00001;
14+
export const Mutation = /* */ 0b00010;
15+
export const Layout = /* */ 0b00100;
16+
export const Passive = /* */ 0b01000;
17+
export const PassiveStatic = /* */ 0b10000;

packages/react-reconciler/src/__tests__/SchedulingProfiler-test.internal.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,6 @@ describe('SchedulingProfiler', () => {
526526
'--layout-effects-start-1024',
527527
'--layout-effects-stop',
528528
'--commit-stop',
529-
'--passive-effects-start-1024',
530-
'--passive-effects-stop',
531529
]);
532530
}
533531
});

0 commit comments

Comments
 (0)