main
js 150 lines 7.24 KB
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @flow
8 */
9
10 import {
11 enableCreateEventHandleAPI,
12 enableEffectEventMutationPhase,
13 } from 'shared/ReactFeatureFlags';
14
15 export type Flags = number;
16
17 // Don't change these values. They're used by React Dev Tools.
18 export const NoFlags = /* */ 0b0000000000000000000000000000000;
19 export const PerformedWork = /* */ 0b0000000000000000000000000000001;
20 export const Placement = /* */ 0b0000000000000000000000000000010;
21 export const DidCapture = /* */ 0b0000000000000000000000010000000;
22 export const Hydrating = /* */ 0b0000000000000000001000000000000;
23
24 // You can change the rest (and add more).
25 export const Update = /* */ 0b0000000000000000000000000000100;
26 export const Cloned = /* */ 0b0000000000000000000000000001000;
27
28 export const ChildDeletion = /* */ 0b0000000000000000000000000010000;
29 export const ContentReset = /* */ 0b0000000000000000000000000100000;
30 export const Callback = /* */ 0b0000000000000000000000001000000;
31 /* Used by DidCapture: 0b0000000000000000000000010000000; */
32
33 export const ForceClientRender = /* */ 0b0000000000000000000000100000000;
34 export const Ref = /* */ 0b0000000000000000000001000000000;
35 export const Snapshot = /* */ 0b0000000000000000000010000000000;
36 export const Passive = /* */ 0b0000000000000000000100000000000;
37 /* Used by Hydrating: 0b0000000000000000001000000000000; */
38
39 export const Visibility = /* */ 0b0000000000000000010000000000000;
40 export const StoreConsistency = /* */ 0b0000000000000000100000000000000;
41
42 // It's OK to reuse these bits because these flags are mutually exclusive for
43 // different fiber types. We should really be doing this for as many flags as
44 // possible, because we're about to run out of bits.
45 export const Hydrate = Callback;
46 export const ScheduleRetry = StoreConsistency;
47 export const ShouldSuspendCommit = Visibility;
48 export const ViewTransitionNamedMount = ShouldSuspendCommit;
49 export const DidDefer = ContentReset;
50 export const FormReset = Snapshot;
51 export const AffectedParentLayout = ContentReset;
52
53 export const LifecycleEffectMask =
54 Passive | Update | Callback | Ref | Snapshot | StoreConsistency;
55
56 // Union of all commit flags (flags with the lifetime of a particular commit)
57 export const HostEffectMask = /* */ 0b0000000000000000111111111111111;
58
59 // These are not really side effects, but we still reuse this field.
60 export const Incomplete = /* */ 0b0000000000000001000000000000000;
61 export const ShouldCapture = /* */ 0b0000000000000010000000000000000;
62 export const ForceUpdateForLegacySuspense = /* */ 0b0000000000000100000000000000000;
63 export const DidPropagateContext = /* */ 0b0000000000001000000000000000000;
64 export const NeedsPropagation = /* */ 0b0000000000010000000000000000000;
65
66 // Static tags describe aspects of a fiber that are not specific to a render,
67 // e.g. a fiber uses a passive effect (even if there are no updates on this particular render).
68 // This enables us to defer more work in the unmount case,
69 // since we can defer traversing the tree during layout to look for Passive effects,
70 // and instead rely on the static flag as a signal that there may be cleanup work.
71 export const Forked = /* */ 0b0000000000100000000000000000000;
72 export const SnapshotStatic = /* */ 0b0000000001000000000000000000000;
73 export const LayoutStatic = /* */ 0b0000000010000000000000000000000;
74 export const RefStatic = LayoutStatic;
75 export const PassiveStatic = /* */ 0b0000000100000000000000000000000;
76 export const MaySuspendCommit = /* */ 0b0000001000000000000000000000000;
77 // ViewTransitionNamedStatic tracks explicitly name ViewTransition components deeply
78 // that might need to be visited during clean up. This is similar to SnapshotStatic
79 // if there was any other use for it. It also needs to run in the same phase as
80 // MaySuspendCommit tracking.
81 export const ViewTransitionNamedStatic =
82 /* */ SnapshotStatic | MaySuspendCommit;
83 // ViewTransitionStatic tracks whether there are an ViewTransition components from
84 // the nearest HostComponent down. It resets at every HostComponent level.
85 export const ViewTransitionStatic = /* */ 0b0000010000000000000000000000000;
86 // ViewTransitionStaticParent tracks whether there are ViewTransition components
87 // with parentEnter/parentExit props. Unlike ViewTransitionStatic, this is NOT
88 // cleared by HostComponents so it can be used to skip subtrees in parent walks.
89 export const ViewTransitionStaticParent = /* */ 0b1000000000000000000000000000000;
90 // Tracks whether a HostPortal is present in the tree.
91 export const PortalStatic = /* */ 0b0000100000000000000000000000000;
92
93 // Flag used to identify newly inserted fibers. It isn't reset after commit unlike `Placement`.
94 export const PlacementDEV = /* */ 0b0001000000000000000000000000000;
95 export const MountLayoutDev = /* */ 0b0010000000000000000000000000000;
96 export const MountPassiveDev = /* */ 0b0100000000000000000000000000000;
97
98 // Groups of flags that are used in the commit phase to skip over trees that
99 // don't contain effects, by checking subtreeFlags.
100
101 export const BeforeMutationMask: number =
102 Snapshot |
103 (enableCreateEventHandleAPI
104 ? // createEventHandle needs to visit deleted and hidden trees to
105 // fire beforeblur
106 // TODO: Only need to visit Deletions during BeforeMutation phase if an
107 // element is focused.
108 Update | ChildDeletion | Visibility
109 : // useEffectEvent uses the snapshot phase,
110 // but we're moving it to the mutation phase.
111 enableEffectEventMutationPhase
112 ? 0
113 : Update);
114
115 // For View Transition support we use the snapshot phase to scan the tree for potentially
116 // affected ViewTransition components.
117 export const BeforeAndAfterMutationTransitionMask: number =
118 Snapshot | Update | Placement | ChildDeletion | Visibility | ContentReset;
119
120 export const MutationMask =
121 Placement |
122 Update |
123 ChildDeletion |
124 ContentReset |
125 Ref |
126 Hydrating |
127 Visibility |
128 FormReset;
129 export const LayoutMask = Update | Callback | Ref | Visibility;
130
131 // TODO: Split into PassiveMountMask and PassiveUnmountMask
132 export const PassiveMask = Passive | Visibility | ChildDeletion;
133
134 // For View Transitions we need to visit anything we visited in the snapshot phase to
135 // restore the view-transition-name after committing the transition.
136 export const PassiveTransitionMask: number = PassiveMask | Update | Placement;
137
138 // Union of tags that don't get reset on clones.
139 // This allows certain concepts to persist without recalculating them,
140 // e.g. whether a subtree contains passive effects or portals.
141 export const StaticMask =
142 LayoutStatic |
143 PassiveStatic |
144 RefStatic |
145 MaySuspendCommit |
146 ViewTransitionStatic |
147 ViewTransitionStaticParent |
148 ViewTransitionNamedStatic |
149 PortalStatic |
150 Forked;