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 type {ReactNodeList, OffscreenMode, Wakeable} from 'shared/ReactTypes';
    
  11. import type {Lanes} from './ReactFiberLane';
    
  12. import type {SpawnedCachePool} from './ReactFiberCacheComponent';
    
  13. import type {Fiber} from './ReactInternalTypes';
    
  14. import type {
    
  15.   Transition,
    
  16.   TracingMarkerInstance,
    
  17. } from './ReactFiberTracingMarkerComponent';
    
  18. import type {RetryQueue} from './ReactFiberSuspenseComponent';
    
  19. 
    
  20. export type OffscreenProps = {
    
  21.   // TODO: Pick an API before exposing the Offscreen type. I've chosen an enum
    
  22.   // for now, since we might have multiple variants. For example, hiding the
    
  23.   // content without changing the layout.
    
  24.   //
    
  25.   // Default mode is visible. Kind of a weird default for a component
    
  26.   // called "Offscreen." Possible alt: <Visibility />?
    
  27.   mode?: OffscreenMode | null | void,
    
  28.   children?: ReactNodeList,
    
  29. };
    
  30. 
    
  31. // We use the existence of the state object as an indicator that the component
    
  32. // is hidden.
    
  33. export type OffscreenState = {
    
  34.   // TODO: This doesn't do anything, yet. It's always NoLanes. But eventually it
    
  35.   // will represent the pending work that must be included in the render in
    
  36.   // order to unhide the component.
    
  37.   baseLanes: Lanes,
    
  38.   cachePool: SpawnedCachePool | null,
    
  39. };
    
  40. 
    
  41. export type OffscreenQueue = {
    
  42.   transitions: Array<Transition> | null,
    
  43.   markerInstances: Array<TracingMarkerInstance> | null,
    
  44.   retryQueue: RetryQueue | null,
    
  45. };
    
  46. 
    
  47. type OffscreenVisibility = number;
    
  48. 
    
  49. export const OffscreenVisible = /*                     */ 0b001;
    
  50. export const OffscreenDetached = /*                    */ 0b010;
    
  51. export const OffscreenPassiveEffectsConnected = /*     */ 0b100;
    
  52. 
    
  53. export type OffscreenInstance = {
    
  54.   _pendingVisibility: OffscreenVisibility,
    
  55.   _visibility: OffscreenVisibility,
    
  56.   _pendingMarkers: Set<TracingMarkerInstance> | null,
    
  57.   _transitions: Set<Transition> | null,
    
  58.   _retryCache: WeakSet<Wakeable> | Set<Wakeable> | null,
    
  59. 
    
  60.   // Represents the current Offscreen fiber
    
  61.   _current: Fiber | null,
    
  62.   detach: () => void,
    
  63.   attach: () => void,
    
  64. };
    
  65. 
    
  66. export function isOffscreenManual(offscreenFiber: Fiber): boolean {
    
  67.   return (
    
  68.     offscreenFiber.memoizedProps !== null &&
    
  69.     offscreenFiber.memoizedProps.mode === 'manual'
    
  70.   );
    
  71. }