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 {Fiber} from './ReactFiber';
    
  11. 
    
  12. import ReactSharedInternals from 'shared/ReactSharedInternals';
    
  13. 
    
  14. import {warnsIfNotActing} from './ReactFiberConfig';
    
  15. 
    
  16. const {ReactCurrentActQueue} = ReactSharedInternals;
    
  17. 
    
  18. export function isLegacyActEnvironment(fiber: Fiber): boolean {
    
  19.   if (__DEV__) {
    
  20.     // Legacy mode. We preserve the behavior of React 17's act. It assumes an
    
  21.     // act environment whenever `jest` is defined, but you can still turn off
    
  22.     // spurious warnings by setting IS_REACT_ACT_ENVIRONMENT explicitly
    
  23.     // to false.
    
  24. 
    
  25.     const isReactActEnvironmentGlobal =
    
  26.       // $FlowFixMe[cannot-resolve-name] Flow doesn't know about IS_REACT_ACT_ENVIRONMENT global
    
  27.       typeof IS_REACT_ACT_ENVIRONMENT !== 'undefined'
    
  28.         ? // $FlowFixMe[cannot-resolve-name]
    
  29.           IS_REACT_ACT_ENVIRONMENT
    
  30.         : undefined;
    
  31. 
    
  32.     // $FlowFixMe[cannot-resolve-name] - Flow doesn't know about jest
    
  33.     const jestIsDefined = typeof jest !== 'undefined';
    
  34.     return (
    
  35.       warnsIfNotActing && jestIsDefined && isReactActEnvironmentGlobal !== false
    
  36.     );
    
  37.   }
    
  38.   return false;
    
  39. }
    
  40. 
    
  41. export function isConcurrentActEnvironment(): void | boolean {
    
  42.   if (__DEV__) {
    
  43.     const isReactActEnvironmentGlobal =
    
  44.       // $FlowFixMe[cannot-resolve-name] Flow doesn't know about IS_REACT_ACT_ENVIRONMENT global
    
  45.       typeof IS_REACT_ACT_ENVIRONMENT !== 'undefined'
    
  46.         ? // $FlowFixMe[cannot-resolve-name]
    
  47.           IS_REACT_ACT_ENVIRONMENT
    
  48.         : undefined;
    
  49. 
    
  50.     if (!isReactActEnvironmentGlobal && ReactCurrentActQueue.current !== null) {
    
  51.       // TODO: Include link to relevant documentation page.
    
  52.       console.error(
    
  53.         'The current testing environment is not configured to support ' +
    
  54.           'act(...)',
    
  55.       );
    
  56.     }
    
  57.     return isReactActEnvironmentGlobal;
    
  58.   }
    
  59.   return false;
    
  60. }