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 {
    
  11.   REACT_CONTEXT_TYPE,
    
  12.   REACT_FORWARD_REF_TYPE,
    
  13.   REACT_FRAGMENT_TYPE,
    
  14.   REACT_PROFILER_TYPE,
    
  15.   REACT_PROVIDER_TYPE,
    
  16.   REACT_DEBUG_TRACING_MODE_TYPE,
    
  17.   REACT_STRICT_MODE_TYPE,
    
  18.   REACT_SUSPENSE_TYPE,
    
  19.   REACT_SUSPENSE_LIST_TYPE,
    
  20.   REACT_MEMO_TYPE,
    
  21.   REACT_LAZY_TYPE,
    
  22.   REACT_SCOPE_TYPE,
    
  23.   REACT_LEGACY_HIDDEN_TYPE,
    
  24.   REACT_OFFSCREEN_TYPE,
    
  25.   REACT_CACHE_TYPE,
    
  26.   REACT_TRACING_MARKER_TYPE,
    
  27. } from 'shared/ReactSymbols';
    
  28. import {
    
  29.   enableScopeAPI,
    
  30.   enableCacheElement,
    
  31.   enableTransitionTracing,
    
  32.   enableDebugTracing,
    
  33.   enableLegacyHidden,
    
  34. } from './ReactFeatureFlags';
    
  35. 
    
  36. const REACT_CLIENT_REFERENCE: symbol = Symbol.for('react.client.reference');
    
  37. 
    
  38. export default function isValidElementType(type: mixed): boolean {
    
  39.   if (typeof type === 'string' || typeof type === 'function') {
    
  40.     return true;
    
  41.   }
    
  42. 
    
  43.   // Note: typeof might be other than 'symbol' or 'number' (e.g. if it's a polyfill).
    
  44.   if (
    
  45.     type === REACT_FRAGMENT_TYPE ||
    
  46.     type === REACT_PROFILER_TYPE ||
    
  47.     (enableDebugTracing && type === REACT_DEBUG_TRACING_MODE_TYPE) ||
    
  48.     type === REACT_STRICT_MODE_TYPE ||
    
  49.     type === REACT_SUSPENSE_TYPE ||
    
  50.     type === REACT_SUSPENSE_LIST_TYPE ||
    
  51.     (enableLegacyHidden && type === REACT_LEGACY_HIDDEN_TYPE) ||
    
  52.     type === REACT_OFFSCREEN_TYPE ||
    
  53.     (enableScopeAPI && type === REACT_SCOPE_TYPE) ||
    
  54.     (enableCacheElement && type === REACT_CACHE_TYPE) ||
    
  55.     (enableTransitionTracing && type === REACT_TRACING_MARKER_TYPE)
    
  56.   ) {
    
  57.     return true;
    
  58.   }
    
  59. 
    
  60.   if (typeof type === 'object' && type !== null) {
    
  61.     if (
    
  62.       type.$$typeof === REACT_LAZY_TYPE ||
    
  63.       type.$$typeof === REACT_MEMO_TYPE ||
    
  64.       type.$$typeof === REACT_PROVIDER_TYPE ||
    
  65.       type.$$typeof === REACT_CONTEXT_TYPE ||
    
  66.       type.$$typeof === REACT_FORWARD_REF_TYPE ||
    
  67.       // This needs to include all possible module reference object
    
  68.       // types supported by any Flight configuration anywhere since
    
  69.       // we don't know which Flight build this will end up being used
    
  70.       // with.
    
  71.       type.$$typeof === REACT_CLIENT_REFERENCE ||
    
  72.       type.getModuleId !== undefined
    
  73.     ) {
    
  74.       return true;
    
  75.     }
    
  76.   }
    
  77. 
    
  78.   return false;
    
  79. }