File tree Expand file tree Collapse file tree 3 files changed +17
-5
lines changed Expand file tree Collapse file tree 3 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -120,6 +120,11 @@ export function createContext<T>(
120
120
return context . Consumer ;
121
121
} ,
122
122
} ,
123
+ displayName : {
124
+ get ( ) {
125
+ return context . displayName ;
126
+ } ,
127
+ } ,
123
128
} ) ;
124
129
// $FlowFixMe: Flow complains about missing properties because it doesn't understand defineProperty
125
130
context . Consumer = Consumer ;
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ describe('ReactContext', () => {
21
21
ReactDOMServer = require ( 'react-dom/server' ) ;
22
22
} ) ;
23
23
24
- it ( 'ignores displayName on the context type' , ( ) => {
24
+ it ( 'should honor a displayName if set on the context type' , ( ) => {
25
25
const Context = React . createContext ( null ) ;
26
26
Context . displayName = 'MyContextType' ;
27
27
function Validator ( ) {
@@ -38,8 +38,8 @@ describe('ReactContext', () => {
38
38
} ) . toErrorDev (
39
39
'Warning: Failed prop type: The prop `dontPassToSeeErrorStack` is marked as required in `Validator`, but its value is `undefined`.\n' +
40
40
' in Validator (at **)\n' +
41
- ' in Context .Consumer (at **)\n' +
42
- ' in Context .Provider (at **)' ,
41
+ ' in MyContextType .Consumer (at **)\n' +
42
+ ' in MyContextType .Provider (at **)' ,
43
43
) ;
44
44
} ) ;
45
45
} ) ;
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import {
24
24
REACT_BLOCK_TYPE ,
25
25
} from 'shared/ReactSymbols' ;
26
26
import { refineResolvedLazyComponent } from 'shared/ReactLazyComponent' ;
27
+ import type { ReactContext , ReactProviderType } from 'shared/ReactTypes' ;
27
28
28
29
function getWrappedName (
29
30
outerType : mixed ,
@@ -37,6 +38,10 @@ function getWrappedName(
37
38
) ;
38
39
}
39
40
41
+ function getContextName ( type : ReactContext < any > ) {
42
+ return type . displayName || 'Context' ;
43
+ }
44
+
40
45
function getComponentName ( type : mixed ) : string | null {
41
46
if ( type == null ) {
42
47
// Host root, text node or just invalid type.
@@ -73,9 +78,11 @@ function getComponentName(type: mixed): string | null {
73
78
if ( typeof type === 'object' ) {
74
79
switch ( type . $$typeof ) {
75
80
case REACT_CONTEXT_TYPE :
76
- return 'Context.Consumer' ;
81
+ const context : ReactContext < any > = ( type : any ) ;
82
+ return getContextName ( context ) + '.Consumer' ;
77
83
case REACT_PROVIDER_TYPE :
78
- return 'Context.Provider' ;
84
+ const provider : ReactProviderType < any > = ( type : any ) ;
85
+ return getContextName ( provider . _context ) + '.Provider' ;
79
86
case REACT_FORWARD_REF_TYPE :
80
87
return getWrappedName ( type , type . render , 'ForwardRef' ) ;
81
88
case REACT_MEMO_TYPE :
You can’t perform that action at this time.
0 commit comments