2018-03-30 02:45:41 +08:00
|
|
|
/**
|
2022-10-18 23:19:24 +08:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2018-03-30 02:45:41 +08:00
|
|
|
*
|
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
|
*
|
|
|
|
|
* @flow
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
REACT_CONTEXT_TYPE,
|
|
|
|
|
REACT_FORWARD_REF_TYPE,
|
2018-05-11 06:25:32 +08:00
|
|
|
REACT_FRAGMENT_TYPE,
|
|
|
|
|
REACT_PROFILER_TYPE,
|
|
|
|
|
REACT_PROVIDER_TYPE,
|
2020-04-16 10:10:15 +08:00
|
|
|
REACT_DEBUG_TRACING_MODE_TYPE,
|
2018-05-11 06:25:32 +08:00
|
|
|
REACT_STRICT_MODE_TYPE,
|
2018-10-11 00:02:04 +08:00
|
|
|
REACT_SUSPENSE_TYPE,
|
2019-06-20 10:34:28 +08:00
|
|
|
REACT_SUSPENSE_LIST_TYPE,
|
2018-10-21 00:46:23 +08:00
|
|
|
REACT_MEMO_TYPE,
|
2018-10-19 10:57:12 +08:00
|
|
|
REACT_LAZY_TYPE,
|
2019-08-29 19:06:51 +08:00
|
|
|
REACT_SCOPE_TYPE,
|
2020-05-12 11:02:08 +08:00
|
|
|
REACT_LEGACY_HIDDEN_TYPE,
|
2021-06-02 03:46:08 +08:00
|
|
|
REACT_OFFSCREEN_TYPE,
|
2020-12-19 02:57:24 +08:00
|
|
|
REACT_CACHE_TYPE,
|
2022-02-12 00:42:55 +08:00
|
|
|
REACT_TRACING_MARKER_TYPE,
|
2018-03-30 02:45:41 +08:00
|
|
|
} from 'shared/ReactSymbols';
|
2022-02-12 00:42:55 +08:00
|
|
|
import {
|
|
|
|
|
enableScopeAPI,
|
2022-03-21 11:41:02 +08:00
|
|
|
enableCacheElement,
|
2022-02-12 00:42:55 +08:00
|
|
|
enableTransitionTracing,
|
2022-03-08 13:13:22 +08:00
|
|
|
enableDebugTracing,
|
2022-03-10 00:48:03 +08:00
|
|
|
enableLegacyHidden,
|
2022-02-12 00:42:55 +08:00
|
|
|
} from './ReactFeatureFlags';
|
2018-03-30 02:45:41 +08:00
|
|
|
|
2022-09-08 23:46:07 +08:00
|
|
|
const REACT_MODULE_REFERENCE: symbol = Symbol.for('react.module.reference');
|
2020-10-30 08:57:31 +08:00
|
|
|
|
2022-09-14 05:57:38 +08:00
|
|
|
export default function isValidElementType(type: mixed): boolean {
|
2020-07-09 02:25:24 +08:00
|
|
|
if (typeof type === 'string' || typeof type === 'function') {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Note: typeof might be other than 'symbol' or 'number' (e.g. if it's a polyfill).
|
|
|
|
|
if (
|
2018-03-30 02:45:41 +08:00
|
|
|
type === REACT_FRAGMENT_TYPE ||
|
2018-05-11 06:25:32 +08:00
|
|
|
type === REACT_PROFILER_TYPE ||
|
2022-03-08 13:13:22 +08:00
|
|
|
(enableDebugTracing && type === REACT_DEBUG_TRACING_MODE_TYPE) ||
|
2018-03-30 02:45:41 +08:00
|
|
|
type === REACT_STRICT_MODE_TYPE ||
|
2018-10-11 00:02:04 +08:00
|
|
|
type === REACT_SUSPENSE_TYPE ||
|
2019-06-20 10:34:28 +08:00
|
|
|
type === REACT_SUSPENSE_LIST_TYPE ||
|
2022-03-10 00:48:03 +08:00
|
|
|
(enableLegacyHidden && type === REACT_LEGACY_HIDDEN_TYPE) ||
|
2021-06-02 03:46:08 +08:00
|
|
|
type === REACT_OFFSCREEN_TYPE ||
|
2020-12-19 02:57:24 +08:00
|
|
|
(enableScopeAPI && type === REACT_SCOPE_TYPE) ||
|
2022-03-21 11:41:02 +08:00
|
|
|
(enableCacheElement && type === REACT_CACHE_TYPE) ||
|
2022-02-12 00:42:55 +08:00
|
|
|
(enableTransitionTracing && type === REACT_TRACING_MARKER_TYPE)
|
2020-07-09 02:25:24 +08:00
|
|
|
) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof type === 'object' && type !== null) {
|
|
|
|
|
if (
|
|
|
|
|
type.$$typeof === REACT_LAZY_TYPE ||
|
|
|
|
|
type.$$typeof === REACT_MEMO_TYPE ||
|
|
|
|
|
type.$$typeof === REACT_PROVIDER_TYPE ||
|
|
|
|
|
type.$$typeof === REACT_CONTEXT_TYPE ||
|
|
|
|
|
type.$$typeof === REACT_FORWARD_REF_TYPE ||
|
2020-10-30 08:57:31 +08:00
|
|
|
// This needs to include all possible module reference object
|
|
|
|
|
// types supported by any Flight configuration anywhere since
|
|
|
|
|
// we don't know which Flight build this will end up being used
|
|
|
|
|
// with.
|
|
|
|
|
type.$$typeof === REACT_MODULE_REFERENCE ||
|
2020-10-31 14:03:45 +08:00
|
|
|
type.getModuleId !== undefined
|
2020-07-09 02:25:24 +08:00
|
|
|
) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2018-03-30 02:45:41 +08:00
|
|
|
}
|