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