44 * @flow
55 */
66
7- import type { LazyComponent , ReactContext , ReactProviderType } from 'react' ;
7+ import type { Context , StatelessFunctionalComponent } from 'react' ;
88import { Fragment } from 'react' ;
99import {
1010 ContextConsumer ,
@@ -20,6 +20,16 @@ import {
2020 Lazy ,
2121} from 'react-is' ;
2222
23+ /**
24+ * didn't export the type in React
25+ * same as https://github.com/facebook/react/blob/310187264d01a31bc3079358f13662d31a079d9e/packages/react/index.js
26+ */
27+ type LazyComponent < T , P > = {
28+ $$typeof : Symbol | number ,
29+ _payload : P ,
30+ _init : ( payload : P ) => T ,
31+ } ;
32+
2333// Keep in sync with react-reconciler/getComponentNameFromFiber
2434function getWrappedName (
2535 outerType : mixed ,
@@ -35,7 +45,7 @@ function getWrappedName(
3545}
3646
3747// Keep in sync with react-reconciler/getComponentNameFromFiber
38- function getContextName ( type : ReactContext < any > ) {
48+ function getContextName ( type : Context < any > ) {
3949 return type . displayName || 'Context' ;
4050}
4151
@@ -72,23 +82,28 @@ function getComponentNameFromType(type: mixed): string | null {
7282 if ( typeof type === 'object' ) {
7383 // eslint-disable-next-line default-case
7484 switch ( type . $$typeof ) {
75- case ContextConsumer :
85+ case ContextConsumer : {
7686 /**
7787 * in DEV, should get context from `_context`.
7888 * https://github.com/facebook/react/blob/e16d61c3000e2de6217d06b9afad162e883f73c4/packages/react/src/ReactContext.js#L44-L125
7989 */
80- return `${ getContextName ( type . _context ?? type ) } .Consumer` ;
81- case ContextProvider :
82- return `${ getContextName ( type . _context ) } .Provider` ;
90+ const context : any = type . _context ?? type ;
91+ return `${ getContextName ( context ) } .Consumer` ;
92+ }
93+ case ContextProvider : {
94+ const context : any = type . _context ;
95+ return `${ getContextName ( context ) } .Provider` ;
96+ }
8397 case ForwardRef :
8498 // eslint-disable-next-line no-case-declarations
8599 return getWrappedName ( type , type . render , 'ForwardRef' ) ;
86- case Memo :
100+ case Memo : {
87101 const outerName = ( type : any ) . displayName || null ;
88102 if ( outerName !== null ) {
89103 return outerName ;
90104 }
91105 return getComponentNameFromType ( type . type ) || 'Memo' ;
106+ }
92107 case Lazy : {
93108 const lazyComponent : LazyComponent < any , any > = ( type : any ) ;
94109 const payload = lazyComponent . _payload ;
0 commit comments