text: /**
   * Copyright (c) Facebook, Inc. and its affiliates.
   *
   * This source code is licensed under the MIT license found in the
   * LICENSE file in the root directory of this source tree.
   *
   * @flow
   */
  
  import type {FiberRoot, SuspenseHydrationCallbacks} from './ReactInternalTypes';
  import type {RootTag} from './ReactRootTags';
  
  import {noTimeout} from './ReactFiberHostConfig';
  import {createHostRootFiber} from './ReactFiber.new';
  import {
    NoLanes,
    NoLanePriority,
    NoTimestamp,
    createLaneMap,
  } from './ReactFiberLane';
  import {
    enableSchedulerTracing,
    enableSuspenseCallback,
  } from 'shared/ReactFeatureFlags';
  import {unstable_getThreadID} from 'scheduler/tracing';
  import {initializeUpdateQueue} from './ReactUpdateQueue.new';
  
  function FiberRootNode(containerInfo, tag, hydrate) {
    this.tag = tag;
    this.containerInfo = containerInfo;
    this.pendingChildren = null;
    this.current = null;
    this.pingCache = null;
    this.finishedWork = null;
    this.timeoutHandle = noTimeout;
    this.context = null;
    this.pendingContext = null;
    this.hydrate = hydrate;
    this.callbackNode = null;
    this.callbackId = NoLanes;
    this.callbackPriority_new = NoLanePriority;
    this.expirationTimes = createLaneMap(NoTimestamp);
  
    this.pendingLanes = NoLanes;
    this.suspendedLanes = NoLanes;
    this.pingedLanes = NoLanes;
    this.expiredLanes = NoLanes;
    this.mutableReadLanes = NoLanes;
  
    this.finishedLanes = NoLanes;
  
    if (enableSchedulerTracing) {
      this.interactionThreadID = unstable_getThreadID();
      this.memoizedInteractions = new Set();
      this.pendingInteractionMap_new = new Map();
    }
    if (enableSuspenseCallback) {
      this.hydrationCallbacks = null;
    }
  }
  
  export function createFiberRoot(
    containerInfo: any,
    tag: RootTag,
    hydrate: boolean,
    hydrationCallbacks: null | SuspenseHydrationCallbacks,
  ): FiberRoot {
    const root: FiberRoot = (new FiberRootNode(containerInfo, tag, hydrate): any);
    if (enableSuspenseCallback) {
      root.hydrationCallbacks = hydrationCallbacks;
    }
  
    // Cyclic construction. This cheats the type system right now because
    // stateNode is any.
    const uninitializedFiber = createHostRootFiber(tag);
    root.current = uninitializedFiber;
    uninitializedFiber.stateNode = root;
  
    initializeUpdateQueue(uninitializedFiber);
  
    return root;
  }
  