@@ -24,9 +24,20 @@ import {
2424 REACT_SUSPENSE_TYPE ,
2525 REACT_SUSPENSE_LIST_TYPE ,
2626 REACT_VIEW_TRANSITION_TYPE ,
27+ REACT_SCOPE_TYPE ,
28+ REACT_LEGACY_HIDDEN_TYPE ,
29+ REACT_TRACING_MARKER_TYPE ,
2730} from 'shared/ReactSymbols' ;
28- import isValidElementType from 'shared/isValidElementType' ;
29- import { enableRenderableContext } from 'shared/ReactFeatureFlags' ;
31+
32+ import {
33+ enableRenderableContext ,
34+ enableScopeAPI ,
35+ enableTransitionTracing ,
36+ enableLegacyHidden ,
37+ enableViewTransition ,
38+ } from 'shared/ReactFeatureFlags' ;
39+
40+ const REACT_CLIENT_REFERENCE : symbol = Symbol . for ( 'react.client.reference' ) ;
3041
3142export function typeOf ( object : any ) : mixed {
3243 if ( typeof object === 'object' && object !== null ) {
@@ -91,7 +102,47 @@ export const StrictMode = REACT_STRICT_MODE_TYPE;
91102export const Suspense = REACT_SUSPENSE_TYPE ;
92103export const SuspenseList = REACT_SUSPENSE_LIST_TYPE ;
93104
94- export { isValidElementType } ;
105+ export function isValidElementType ( type : mixed ) : boolean {
106+ if ( typeof type === 'string' || typeof type === 'function' ) {
107+ return true ;
108+ }
109+
110+ // Note: typeof might be other than 'symbol' or 'number' (e.g. if it's a polyfill).
111+ if (
112+ type === REACT_FRAGMENT_TYPE ||
113+ type === REACT_PROFILER_TYPE ||
114+ type === REACT_STRICT_MODE_TYPE ||
115+ type === REACT_SUSPENSE_TYPE ||
116+ type === REACT_SUSPENSE_LIST_TYPE ||
117+ ( enableLegacyHidden && type === REACT_LEGACY_HIDDEN_TYPE ) ||
118+ ( enableScopeAPI && type === REACT_SCOPE_TYPE ) ||
119+ ( enableTransitionTracing && type === REACT_TRACING_MARKER_TYPE ) ||
120+ ( enableViewTransition && type === REACT_VIEW_TRANSITION_TYPE )
121+ ) {
122+ return true ;
123+ }
124+
125+ if ( typeof type === 'object' && type !== null ) {
126+ if (
127+ type . $$typeof === REACT_LAZY_TYPE ||
128+ type . $$typeof === REACT_MEMO_TYPE ||
129+ type . $$typeof === REACT_CONTEXT_TYPE ||
130+ ( ! enableRenderableContext && type . $$typeof === REACT_PROVIDER_TYPE ) ||
131+ ( enableRenderableContext && type . $$typeof === REACT_CONSUMER_TYPE ) ||
132+ type . $$typeof === REACT_FORWARD_REF_TYPE ||
133+ // This needs to include all possible module reference object
134+ // types supported by any Flight configuration anywhere since
135+ // we don't know which Flight build this will end up being used
136+ // with.
137+ type . $$typeof === REACT_CLIENT_REFERENCE ||
138+ type . getModuleId !== undefined
139+ ) {
140+ return true ;
141+ }
142+ }
143+
144+ return false ;
145+ }
95146
96147export function isContextConsumer ( object : any ) : boolean {
97148 if ( enableRenderableContext ) {
0 commit comments