React Fiber Flags
导出一些 React Fiber 标志,标记当前的状态。
// Don't change these values. They're used by React Dev Tools.
// 不要更改这些值。它们被 React 开发者工具使用。
// 无标志
export const NoFlags = 0b0000000000000000000000000000000;
// 已完成的工作
export const PerformedWork = 0b0000000000000000000000000000001;
// 安置
export const Placement = 0b0000000000000000000000000000010;
// 已捕获
export const DidCapture = 0b0000000000000000000000010000000;
// 水合中
export const Hydrating = 0b0000000000000000001000000000000;
// You can change the rest (and add more).
// 你可以更改其余部分(并添加更多)。
// 更新
export const Update = 0b0000000000000000000000000000100;
// 复制
export const Cloned = 0b0000000000000000000000000001000;
// 子删除
export const ChildDeletion = 0b0000000000000000000000000010000;
// 重置上下文
export const ContentReset = 0b0000000000000000000000000100000;
// 回调
export const Callback = 0b0000000000000000000000001000000;
/* Used by DidCapture: 0b0000000000000000000000010000000; */
/* 由 DidCapture 使用: 0b0000000000000000000000010000000; */
// 强制客户端渲染
export const ForceClientRender = 0b0000000000000000000000100000000;
// Ref
export const Ref = 0b0000000000000000000001000000000;
// 快照
export const Snapshot = 0b0000000000000000000010000000000;
// 被动
export const Passive = 0b0000000000000000000100000000000;
/* Used by Hydrating: 0b0000000000000000001000000000000; */
/* 由 Hydrating 使用: 0b0000000000000000001000000000000; */
// 可见
export const Visibility = 0b0000000000000000010000000000000;
// 存储一致性
export const StoreConsistency = 0b0000000000000000100000000000000;
// It's OK to reuse these bits because these flags are mutually exclusive for
// different fiber types. We should really be doing this for as many flags as
// possible, because we're about to run out of bits.
// 重用这些位是可以的,因为这些标志对于不同的 fiber 类型是互斥的。
// 我们实际上应该尽可能多地这样做,因为我们很快就会用完这些位。
// 水合
export const Hydrate = Callback;
// 安排调度重试
export const ScheduleRetry = StoreConsistency;
// 是否应暂停提交
export const ShouldSuspendCommit = Visibility;
// 查看过渡命名挂载
export const ViewTransitionNamedMount = ShouldSuspendCommit;
// 已推迟
export const DidDefer = ContentReset;
// 表单重置
export const FormReset = Snapshot;
// 受影响的父布局
export const AffectedParentLayout = ContentReset;
// 生命周期效果掩码
export const LifecycleEffectMask =
Passive | Update | Callback | Ref | Snapshot | StoreConsistency;
// Union of all commit flags (flags with the lifetime of a particular commit)
// 所有提交标志的联合(具有特定提交生命周期的标志)
export const HostEffectMask = 0b0000000000000000111111111111111;
// These are not really side effects, but we still reuse this field.
// 这些其实不是真正的副作用,但我们仍然重用这个字段。
// 不完整
export const Incomplete = 0b0000000000000001000000000000000;
// 是否捕捉
export const ShouldCapture = 0b0000000000000010000000000000000;
// 为旧版 Suspense 强制更新
export const ForceUpdateForLegacySuspense = 0b0000000000000100000000000000000;
// 已传播上下文
export const DidPropagateContext = 0b0000000000001000000000000000000;
// 需要传播
export const NeedsPropagation = 0b0000000000010000000000000000000;
// 分叉
export const Forked = 0b0000000000100000000000000000000;
// Static tags describe aspects of a fiber that are not specific to a render,
// e.g. a fiber uses a passive effect (even if there are no updates on this particular render).
// This enables us to defer more work in the unmount case,
// since we can defer traversing the tree during layout to look for Passive effects,
// and instead rely on the static flag as a signal that there may be cleanup work.
// 静态标签描述了 fiber 的一些与渲染无关的方面,
// 例如,一个 fiber 使用了被动效果(即使在这个特定渲染中没有更新)。
// 这使我们能够在卸载情况下推迟更多工作,
// 因为我们可以在布局期间推迟遍历树以查找被动效果,
// 而是依赖静态标志作为可能存在清理工作的信号。
// 静态快照
export const SnapshotStatic = 0b0000000001000000000000000000000;
// 静态布局
export const LayoutStatic = 0b0000000010000000000000000000000;
// 静态引用
export const RefStatic = LayoutStatic;
// 被动静态
export const PassiveStatic = 0b0000000100000000000000000000000;
// 可能暂停提交
export const MaySuspendCommit = 0b0000001000000000000000000000000;
// ViewTransitionNamedStatic tracks explicitly name ViewTransition components deeply
// that might need to be visited during clean up. This is similar to SnapshotStatic
// if there was any other use for it. It also needs to run in the same phase as
// MaySuspendCommit tracking.
// ViewTransitionNamedStatic 会显式跟踪命名的 ViewTransition 组件,
// 可能需要在清理时访问这些组件。这与 SnapshotStatic 类似
// 如果它还有其他用途的话。它还需要在与 MaySuspendCommit 跟踪相同的阶段运行。
// 查看静态命名的过渡
export const ViewTransitionNamedStatic = SnapshotStatic | MaySuspendCommit;
// ViewTransitionStatic tracks whether there are an ViewTransition components from
// the nearest HostComponent down. It resets at every HostComponent level.
// ViewTransitionStatic 用于跟踪从最近的 HostComponent 向下是否存在
// 任何 ViewTransition 组件。它会在每个 HostComponent 层级重置。
// 视图过渡静态
export const ViewTransitionStatic = 0b0000010000000000000000000000000;
// Flag used to identify newly inserted fibers. It isn't reset after commit unlike `Placement`.
// 用于标识新插入的 fiber 的标志。与 `Placement` 不同,它在提交后不会被重置。
// 环境部署(开发)
export const PlacementDEV = 0b0000100000000000000000000000000;
// 挂载布局(开发)
export const MountLayoutDev = 0b0001000000000000000000000000000;
// 挂载被动(开发)
export const MountPassiveDev = 0b0010000000000000000000000000000;
// Groups of flags that are used in the commit phase to skip over trees that
// don't contain effects, by checking subtreeFlags.
// 在提交阶段用于跳过不包含副作用的树的标志组,通过检查 subtreeFlags。
// 突变前掩码
export const BeforeMutationMask: number =
Snapshot |
(enableCreateEventHandleAPI
? // createEventHandle needs to visit deleted and hidden trees to
// fire beforeblur
// TODO: Only need to visit Deletions during BeforeMutation phase if an
// element is focused.
// createEventHandle 需要访问已删除和隐藏的树以触发 beforeblur
// TODO:只有在 BeforeMutation 阶段,
// 如果有元素被聚焦时,才需要访问已删除的内容。
Update | ChildDeletion | Visibility
: enableUseEffectEventHook
? // TODO: The useEffectEvent hook uses the snapshot phase for clean up but it
// really should use the mutation phase for this or at least schedule an
// explicit Snapshot phase flag for this.
// TODO: useEffectEvent 钩子在清理时使用了快照阶段,
// 但实际上它应该使用变更阶段,或者至少为此安排一个明确的快照阶段标志。
Update
: 0);
// For View Transition support we use the snapshot phase to scan the tree for potentially
// affected ViewTransition components.
// 对于视图过渡支持,我们使用快照阶段扫描树以查找可能受影响的 ViewTransition 组件。
// 突变前后过渡掩码
export const BeforeAndAfterMutationTransitionMask: number =
Snapshot | Update | Placement | ChildDeletion | Visibility | ContentReset;
// 突变面具
export const MutationMask =
Placement |
Update |
ChildDeletion |
ContentReset |
Ref |
Hydrating |
Visibility |
FormReset;
// 布局掩码
export const LayoutMask = Update | Callback | Ref | Visibility;
// TODO: Split into PassiveMountMask and PassiveUnmountMask
// 待办:拆分为 PassiveMountMask 和 PassiveUnmountMask
export const PassiveMask = Passive | Visibility | ChildDeletion;
// For View Transitions we need to visit anything we visited in the snapshot phase to
// restore the view-transition-name after committing the transition.
// 对于视图过渡,我们需要访问在快照阶段访问过的任何内容,
// 以便在提交过渡后恢复 view-transition-name。
// 被动过渡遮罩
export const PassiveTransitionMask: number = PassiveMask | Update | Placement;
// Union of tags that don't get reset on clones.
// This allows certain concepts to persist without recalculating them,
// e.g. whether a subtree contains passive effects or portals.
// 不会在克隆时重置的标签集合。
// 这允许某些概念保持不变,而无需重新计算,
// 例如子树是否包含被动效果或门户。
// 静态掩码
export const StaticMask =
LayoutStatic |
PassiveStatic |
RefStatic |
MaySuspendCommit |
ViewTransitionStatic |
ViewTransitionNamedStatic;