@@ -24,9 +24,20 @@ import {
24
24
REACT_SUSPENSE_TYPE ,
25
25
REACT_SUSPENSE_LIST_TYPE ,
26
26
REACT_VIEW_TRANSITION_TYPE ,
27
+ REACT_SCOPE_TYPE ,
28
+ REACT_LEGACY_HIDDEN_TYPE ,
29
+ REACT_TRACING_MARKER_TYPE ,
27
30
} 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' ) ;
30
41
31
42
export function typeOf ( object : any ) : mixed {
32
43
if ( typeof object === 'object' && object !== null ) {
@@ -91,7 +102,47 @@ export const StrictMode = REACT_STRICT_MODE_TYPE;
91
102
export const Suspense = REACT_SUSPENSE_TYPE ;
92
103
export const SuspenseList = REACT_SUSPENSE_LIST_TYPE ;
93
104
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
+ }
95
146
96
147
export function isContextConsumer ( object : any ) : boolean {
97
148
if ( enableRenderableContext ) {
0 commit comments