1
1
import type { ElementType , MemoExoticComponent , ReactElement } from 'react'
2
+ import * as React from 'react'
2
3
3
4
// Directly ported from:
4
- // https://unpkg.com/browse/react-is@18.3.0-canary-ee68446ff-20231115 /cjs/react-is.production.js
5
+ // https://unpkg.com/browse/react-is@19.0.0 /cjs/react-is.production.js
5
6
// It's very possible this could change in the future, but given that
6
7
// we only use these in `connect`, this is a low priority.
7
8
8
- const REACT_ELEMENT_TYPE = /* @__PURE__ */ Symbol . for ( 'react.element' )
9
+ export const IS_REACT_19 = /* @__PURE__ */ React . version . startsWith ( '19' )
10
+
11
+ const REACT_ELEMENT_TYPE = /* @__PURE__ */ Symbol . for (
12
+ IS_REACT_19 ? 'react.transitional.element' : 'react.element' ,
13
+ )
9
14
const REACT_PORTAL_TYPE = /* @__PURE__ */ Symbol . for ( 'react.portal' )
10
15
const REACT_FRAGMENT_TYPE = /* @__PURE__ */ Symbol . for ( 'react.fragment' )
11
16
const REACT_STRICT_MODE_TYPE = /* @__PURE__ */ Symbol . for ( 'react.strict_mode' )
12
17
const REACT_PROFILER_TYPE = /* @__PURE__ */ Symbol . for ( 'react.profiler' )
13
- const REACT_PROVIDER_TYPE = /* @__PURE__ */ Symbol . for ( 'react.provider ' )
18
+ const REACT_CONSUMER_TYPE = /* @__PURE__ */ Symbol . for ( 'react.consumer ' )
14
19
const REACT_CONTEXT_TYPE = /* @__PURE__ */ Symbol . for ( 'react.context' )
15
- const REACT_SERVER_CONTEXT_TYPE = /* @__PURE__ */ Symbol . for (
16
- 'react.server_context' ,
17
- )
18
20
const REACT_FORWARD_REF_TYPE = /* @__PURE__ */ Symbol . for ( 'react.forward_ref' )
19
21
const REACT_SUSPENSE_TYPE = /* @__PURE__ */ Symbol . for ( 'react.suspense' )
20
22
const REACT_SUSPENSE_LIST_TYPE = /* @__PURE__ */ Symbol . for (
@@ -31,87 +33,63 @@ export const ForwardRef = REACT_FORWARD_REF_TYPE
31
33
export const Memo = REACT_MEMO_TYPE
32
34
33
35
export function isValidElementType ( type : any ) : type is ElementType {
34
- if ( typeof type === 'string' || typeof type === 'function' ) {
35
- return true
36
- } // Note: typeof might be other than 'symbol' or 'number' (e.g. if it's a polyfill).
37
-
38
- if (
36
+ return typeof type === 'string' ||
37
+ typeof type === 'function' ||
39
38
type === REACT_FRAGMENT_TYPE ||
40
39
type === REACT_PROFILER_TYPE ||
41
40
type === REACT_STRICT_MODE_TYPE ||
42
41
type === REACT_SUSPENSE_TYPE ||
43
42
type === REACT_SUSPENSE_LIST_TYPE ||
44
- type === REACT_OFFSCREEN_TYPE
45
- ) {
46
- return true
47
- }
48
-
49
- if ( typeof type === 'object' && type !== null ) {
50
- if (
51
- type . $$typeof === REACT_LAZY_TYPE ||
52
- type . $$typeof === REACT_MEMO_TYPE ||
53
- type . $$typeof === REACT_PROVIDER_TYPE ||
54
- type . $$typeof === REACT_CONTEXT_TYPE ||
55
- type . $$typeof === REACT_FORWARD_REF_TYPE || // This needs to include all possible module reference object
56
- // types supported by any Flight configuration anywhere since
57
- // we don't know which Flight build this will end up being used
58
- // with.
59
- type . $$typeof === REACT_CLIENT_REFERENCE ||
60
- type . getModuleId !== undefined
61
- ) {
62
- return true
63
- }
64
- }
65
-
66
- return false
43
+ type === REACT_OFFSCREEN_TYPE ||
44
+ ( typeof type === 'object' &&
45
+ type !== null &&
46
+ ( type . $$typeof === REACT_LAZY_TYPE ||
47
+ type . $$typeof === REACT_MEMO_TYPE ||
48
+ type . $$typeof === REACT_CONTEXT_TYPE ||
49
+ type . $$typeof === REACT_CONSUMER_TYPE ||
50
+ type . $$typeof === REACT_FORWARD_REF_TYPE ||
51
+ type . $$typeof === REACT_CLIENT_REFERENCE ||
52
+ type . getModuleId !== undefined ) )
53
+ ? ! 0
54
+ : ! 1
67
55
}
68
56
69
57
function typeOf ( object : any ) : symbol | undefined {
70
58
if ( typeof object === 'object' && object !== null ) {
71
- const $$typeof = object . $$typeof
59
+ const { $$typeof } = object
72
60
73
61
switch ( $$typeof ) {
74
- case REACT_ELEMENT_TYPE : {
75
- const type = object . type
76
-
77
- switch ( type ) {
62
+ case REACT_ELEMENT_TYPE :
63
+ switch ( ( ( object = object . type ) , object ) ) {
78
64
case REACT_FRAGMENT_TYPE :
79
65
case REACT_PROFILER_TYPE :
80
66
case REACT_STRICT_MODE_TYPE :
81
67
case REACT_SUSPENSE_TYPE :
82
68
case REACT_SUSPENSE_LIST_TYPE :
83
- return type
84
-
85
- default : {
86
- const $$typeofType = type && type . $$typeof
87
-
88
- switch ( $$typeofType ) {
89
- case REACT_SERVER_CONTEXT_TYPE :
69
+ return object
70
+ default :
71
+ switch ( ( ( object = object && object . $$typeof ) , object ) ) {
90
72
case REACT_CONTEXT_TYPE :
91
73
case REACT_FORWARD_REF_TYPE :
92
74
case REACT_LAZY_TYPE :
93
75
case REACT_MEMO_TYPE :
94
- case REACT_PROVIDER_TYPE :
95
- return $$typeofType
96
-
76
+ return object
77
+ case REACT_CONSUMER_TYPE :
78
+ return object
97
79
default :
98
80
return $$typeof
99
81
}
100
- }
101
82
}
102
- }
103
-
104
- case REACT_PORTAL_TYPE : {
83
+ case REACT_PORTAL_TYPE :
105
84
return $$typeof
106
- }
107
85
}
108
86
}
109
-
110
- return undefined
111
87
}
112
88
113
89
export function isContextConsumer ( object : any ) : object is ReactElement {
114
- return typeOf ( object ) === REACT_CONTEXT_TYPE
90
+ return IS_REACT_19
91
+ ? typeOf ( object ) === REACT_CONSUMER_TYPE
92
+ : typeOf ( object ) === REACT_CONTEXT_TYPE
115
93
}
116
94
117
95
export function isMemo ( object : any ) : object is MemoExoticComponent < any > {
0 commit comments