Skip to content

Commit 3ee812e

Browse files
authored
Revert "feat: honor displayName of context types (#18035)" (#18223)
This reverts commit 45c172d.
1 parent 6a0efdd commit 3ee812e

File tree

3 files changed

+2
-38
lines changed

3 files changed

+2
-38
lines changed

packages/react/src/ReactContext.js

-5
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,6 @@ export function createContext<T>(
120120
return context.Consumer;
121121
},
122122
},
123-
displayName: {
124-
get() {
125-
return context.displayName;
126-
},
127-
},
128123
});
129124
// $FlowFixMe: Flow complains about missing properties because it doesn't understand defineProperty
130125
context.Consumer = Consumer;

packages/react/src/__tests__/ReactContextValidator-test.js

-24
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
let PropTypes;
1919
let React;
2020
let ReactDOM;
21-
let ReactDOMServer;
2221
let ReactTestUtils;
2322

2423
describe('ReactContextValidator', () => {
@@ -28,7 +27,6 @@ describe('ReactContextValidator', () => {
2827
PropTypes = require('prop-types');
2928
React = require('react');
3029
ReactDOM = require('react-dom');
31-
ReactDOMServer = require('react-dom/server');
3230
ReactTestUtils = require('react-dom/test-utils');
3331
});
3432

@@ -673,26 +671,4 @@ describe('ReactContextValidator', () => {
673671
'Warning: ComponentB: Function components do not support contextType.',
674672
);
675673
});
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-
});
698674
});

packages/shared/getComponentName.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
REACT_BLOCK_TYPE,
2525
} from 'shared/ReactSymbols';
2626
import {refineResolvedLazyComponent} from 'shared/ReactLazyComponent';
27-
import type {ReactContext, ReactProviderType} from 'shared/ReactTypes';
2827

2928
function getWrappedName(
3029
outerType: mixed,
@@ -38,10 +37,6 @@ function getWrappedName(
3837
);
3938
}
4039

41-
function getContextName(type: ReactContext<any>) {
42-
return type.displayName || 'Context';
43-
}
44-
4540
function getComponentName(type: mixed): string | null {
4641
if (type == null) {
4742
// Host root, text node or just invalid type.
@@ -78,11 +73,9 @@ function getComponentName(type: mixed): string | null {
7873
if (typeof type === 'object') {
7974
switch (type.$$typeof) {
8075
case REACT_CONTEXT_TYPE:
81-
const context: ReactContext<any> = (type: any);
82-
return getContextName(context) + '.Consumer';
76+
return 'Context.Consumer';
8377
case REACT_PROVIDER_TYPE:
84-
const provider: ReactProviderType<any> = (type: any);
85-
return getContextName(provider._context) + '.Provider';
78+
return 'Context.Provider';
8679
case REACT_FORWARD_REF_TYPE:
8780
return getWrappedName(type, type.render, 'ForwardRef');
8881
case REACT_MEMO_TYPE:

0 commit comments

Comments
 (0)