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 {enableCreateEventHandleAPI} from 'shared/ReactFeatureFlags';
    
  11. 
    
  12. export type Flags = number;
    
  13. 
    
  14. // Don't change these values. They're used by React Dev Tools.
    
  15. export const NoFlags = /*                      */ 0b0000000000000000000000000000;
    
  16. export const PerformedWork = /*                */ 0b0000000000000000000000000001;
    
  17. export const Placement = /*                    */ 0b0000000000000000000000000010;
    
  18. export const DidCapture = /*                   */ 0b0000000000000000000010000000;
    
  19. export const Hydrating = /*                    */ 0b0000000000000001000000000000;
    
  20. 
    
  21. // You can change the rest (and add more).
    
  22. export const Update = /*                       */ 0b0000000000000000000000000100;
    
  23. /* Skipped value:                                 0b0000000000000000000000001000; */
    
  24. 
    
  25. export const ChildDeletion = /*                */ 0b0000000000000000000000010000;
    
  26. export const ContentReset = /*                 */ 0b0000000000000000000000100000;
    
  27. export const Callback = /*                     */ 0b0000000000000000000001000000;
    
  28. /* Used by DidCapture:                            0b0000000000000000000010000000; */
    
  29. 
    
  30. export const ForceClientRender = /*            */ 0b0000000000000000000100000000;
    
  31. export const Ref = /*                          */ 0b0000000000000000001000000000;
    
  32. export const Snapshot = /*                     */ 0b0000000000000000010000000000;
    
  33. export const Passive = /*                      */ 0b0000000000000000100000000000;
    
  34. /* Used by Hydrating:                             0b0000000000000001000000000000; */
    
  35. 
    
  36. export const Visibility = /*                   */ 0b0000000000000010000000000000;
    
  37. export const StoreConsistency = /*             */ 0b0000000000000100000000000000;
    
  38. 
    
  39. // It's OK to reuse these bits because these flags are mutually exclusive for
    
  40. // different fiber types. We should really be doing this for as many flags as
    
  41. // possible, because we're about to run out of bits.
    
  42. export const ScheduleRetry = StoreConsistency;
    
  43. export const ShouldSuspendCommit = Visibility;
    
  44. 
    
  45. export const LifecycleEffectMask =
    
  46.   Passive | Update | Callback | Ref | Snapshot | StoreConsistency;
    
  47. 
    
  48. // Union of all commit flags (flags with the lifetime of a particular commit)
    
  49. export const HostEffectMask = /*               */ 0b0000000000000111111111111111;
    
  50. 
    
  51. // These are not really side effects, but we still reuse this field.
    
  52. export const Incomplete = /*                   */ 0b0000000000001000000000000000;
    
  53. export const ShouldCapture = /*                */ 0b0000000000010000000000000000;
    
  54. export const ForceUpdateForLegacySuspense = /* */ 0b0000000000100000000000000000;
    
  55. export const DidPropagateContext = /*          */ 0b0000000001000000000000000000;
    
  56. export const NeedsPropagation = /*             */ 0b0000000010000000000000000000;
    
  57. export const Forked = /*                       */ 0b0000000100000000000000000000;
    
  58. 
    
  59. // Static tags describe aspects of a fiber that are not specific to a render,
    
  60. // e.g. a fiber uses a passive effect (even if there are no updates on this particular render).
    
  61. // This enables us to defer more work in the unmount case,
    
  62. // since we can defer traversing the tree during layout to look for Passive effects,
    
  63. // and instead rely on the static flag as a signal that there may be cleanup work.
    
  64. export const RefStatic = /*                    */ 0b0000001000000000000000000000;
    
  65. export const LayoutStatic = /*                 */ 0b0000010000000000000000000000;
    
  66. export const PassiveStatic = /*                */ 0b0000100000000000000000000000;
    
  67. export const MaySuspendCommit = /*             */ 0b0001000000000000000000000000;
    
  68. 
    
  69. // Flag used to identify newly inserted fibers. It isn't reset after commit unlike `Placement`.
    
  70. export const PlacementDEV = /*                 */ 0b0010000000000000000000000000;
    
  71. export const MountLayoutDev = /*               */ 0b0100000000000000000000000000;
    
  72. export const MountPassiveDev = /*              */ 0b1000000000000000000000000000;
    
  73. 
    
  74. // Groups of flags that are used in the commit phase to skip over trees that
    
  75. // don't contain effects, by checking subtreeFlags.
    
  76. 
    
  77. export const BeforeMutationMask: number =
    
  78.   // TODO: Remove Update flag from before mutation phase by re-landing Visibility
    
  79.   // flag logic (see #20043)
    
  80.   Update |
    
  81.   Snapshot |
    
  82.   (enableCreateEventHandleAPI
    
  83.     ? // createEventHandle needs to visit deleted and hidden trees to
    
  84.       // fire beforeblur
    
  85.       // TODO: Only need to visit Deletions during BeforeMutation phase if an
    
  86.       // element is focused.
    
  87.       ChildDeletion | Visibility
    
  88.     : 0);
    
  89. 
    
  90. export const MutationMask =
    
  91.   Placement |
    
  92.   Update |
    
  93.   ChildDeletion |
    
  94.   ContentReset |
    
  95.   Ref |
    
  96.   Hydrating |
    
  97.   Visibility;
    
  98. export const LayoutMask = Update | Callback | Ref | Visibility;
    
  99. 
    
  100. // TODO: Split into PassiveMountMask and PassiveUnmountMask
    
  101. export const PassiveMask = Passive | Visibility | ChildDeletion;
    
  102. 
    
  103. // Union of tags that don't get reset on clones.
    
  104. // This allows certain concepts to persist without recalculating them,
    
  105. // e.g. whether a subtree contains passive effects or portals.
    
  106. export const StaticMask =
    
  107.   LayoutStatic | PassiveStatic | RefStatic | MaySuspendCommit;