Revert "feat: honor displayName of context types (#18035)" (#18223)
This reverts commit 45c172d948eee1a8533908267ec8be70bbb00c55.
Dominic Gannaway committed
Mar 5, 2020 at 15:58 UTC
3ee812e6b67d52a6f262144e78721f9340c36a04
3 files changed
+2
-38
packages/react/src/ReactContext.js
-5
@@ -120,11 +120,6 @@ export function createContext<T>(
120
return context.Consumer;
121
},
122
},
123
- displayName: {
124
- get() {
125
- return context.displayName;
126
- },
127
- },
123
});
124
// $FlowFixMe: Flow complains about missing properties because it doesn't understand defineProperty
125
context.Consumer = Consumer;
packages/react/src/__tests__/ReactContextValidator-test.js
-24
@@ -18,7 +18,6 @@
18
let PropTypes;
19
let React;
20
let ReactDOM;
21
-let ReactDOMServer;
21
let ReactTestUtils;
22
23
describe('ReactContextValidator', () => {
@@ -28,7 +27,6 @@ describe('ReactContextValidator', () => {
27
PropTypes = require('prop-types');
28
React = require('react');
29
ReactDOM = require('react-dom');
31
- ReactDOMServer = require('react-dom/server');
30
ReactTestUtils = require('react-dom/test-utils');
31
});
32
@@ -673,26 +671,4 @@ describe('ReactContextValidator', () => {
671
'Warning: ComponentB: Function components do not support contextType.',
672
);
673
});
676
-
677
- it('should honor a displayName if set on the context type', () => {
678
- const Context = React.createContext(null);
679
- Context.displayName = 'MyContextType';
680
- function Validator() {
681
- return null;
682
- }
683
- Validator.propTypes = {dontPassToSeeErrorStack: PropTypes.bool.isRequired};
684
-
685
- expect(() => {
686
- ReactDOMServer.renderToStaticMarkup(
687
- <Context.Provider>
688
- <Context.Consumer>{() => <Validator />}</Context.Consumer>
689
- </Context.Provider>,
690
- );
691
- }).toErrorDev(
692
- 'Warning: Failed prop type: The prop `dontPassToSeeErrorStack` is marked as required in `Validator`, but its value is `undefined`.\n' +
693
- ' in Validator (at **)\n' +
694
- ' in MyContextType.Consumer (at **)\n' +
695
- ' in MyContextType.Provider (at **)',
696
- );
697
- });
674
});
packages/shared/getComponentName.js
+2
-9
@@ -24,7 +24,6 @@ import {
24
REACT_BLOCK_TYPE,
25
} from 'shared/ReactSymbols';
26
import {refineResolvedLazyComponent} from 'shared/ReactLazyComponent';
27
-import type {ReactContext, ReactProviderType} from 'shared/ReactTypes';
27
28
function getWrappedName(
29
outerType: mixed,
@@ -38,10 +37,6 @@ function getWrappedName(
37
);
38
}
39
41
-function getContextName(type: ReactContext<any>) {
42
- return type.displayName || 'Context';
43
-}
44
-
40
function getComponentName(type: mixed): string | null {
41
if (type == null) {
42
// Host root, text node or just invalid type.
@@ -78,11 +73,9 @@ function getComponentName(type: mixed): string | null {
73
if (typeof type === 'object') {
74
switch (type.$$typeof) {
75
case REACT_CONTEXT_TYPE:
81
- const context: ReactContext<any> = (type: any);
82
- return getContextName(context) + '.Consumer';
76
+ return 'Context.Consumer';
77
case REACT_PROVIDER_TYPE:
84
- const provider: ReactProviderType<any> = (type: any);
85
- return getContextName(provider._context) + '.Provider';
78
+ return 'Context.Provider';
79
case REACT_FORWARD_REF_TYPE:
80
return getWrappedName(type, type.render, 'ForwardRef');
81
case REACT_MEMO_TYPE: