diff --git a/packages/react-reconciler/src/ReactFiberContext.js b/packages/react-reconciler/src/ReactFiberContext.js index ea8fdfd67f7ff..cdb066afcf59e 100644 --- a/packages/react-reconciler/src/ReactFiberContext.js +++ b/packages/react-reconciler/src/ReactFiberContext.js @@ -101,11 +101,6 @@ function getMaskedContext( context[key] = unmaskedContext[key]; } - if (__DEV__) { - const name = getComponentNameFromFiber(workInProgress) || 'Unknown'; - checkPropTypes(contextTypes, context, 'context', name); - } - // Cache unmasked context so we can avoid recreating masked context unless necessary. // Context is created before the class component is instantiated so check for instance. if (instance) { @@ -212,10 +207,6 @@ function processChildContext( ); } } - if (__DEV__) { - const name = getComponentNameFromFiber(fiber) || 'Unknown'; - checkPropTypes(childContextTypes, childContext, 'child context', name); - } return {...parentContext, ...childContext}; } diff --git a/packages/react/src/__tests__/ReactContextValidator-test.js b/packages/react/src/__tests__/ReactContextValidator-test.js index c2c97e0c87a9d..148d658b98c5e 100644 --- a/packages/react/src/__tests__/ReactContextValidator-test.js +++ b/packages/react/src/__tests__/ReactContextValidator-test.js @@ -159,136 +159,6 @@ describe('ReactContextValidator', () => { expect(componentDidUpdateContext).toEqual({foo: 'def'}); }); - // @gate !disableLegacyContext || !__DEV__ - it('should check context types', () => { - class Component extends React.Component { - render() { - return
; - } - } - Component.contextTypes = { - foo: PropTypes.string.isRequired, - }; - - expect(() => ReactTestUtils.renderIntoDocument()).toErrorDev( - 'Warning: Failed context type: ' + - 'The context `foo` is marked as required in `Component`, but its value ' + - 'is `undefined`.\n' + - ' in Component (at **)', - ); - - class ComponentInFooStringContext extends React.Component { - getChildContext() { - return { - foo: this.props.fooValue, - }; - } - - render() { - return ; - } - } - ComponentInFooStringContext.childContextTypes = { - foo: PropTypes.string, - }; - - // No additional errors expected - ReactTestUtils.renderIntoDocument( - , - ); - - class ComponentInFooNumberContext extends React.Component { - getChildContext() { - return { - foo: this.props.fooValue, - }; - } - - render() { - return ; - } - } - ComponentInFooNumberContext.childContextTypes = { - foo: PropTypes.number, - }; - - expect(() => - ReactTestUtils.renderIntoDocument( - , - ), - ).toErrorDev( - 'Warning: Failed context type: ' + - 'Invalid context `foo` of type `number` supplied ' + - 'to `Component`, expected `string`.\n' + - ' in Component (at **)\n' + - ' in ComponentInFooNumberContext (at **)', - ); - }); - - // @gate !disableLegacyContext || !__DEV__ - it('should check child context types', () => { - class Component extends React.Component { - getChildContext() { - return this.props.testContext; - } - - render() { - return
; - } - } - Component.childContextTypes = { - foo: PropTypes.string.isRequired, - bar: PropTypes.number, - }; - - expect(() => - ReactTestUtils.renderIntoDocument(), - ).toErrorDev( - 'Warning: Failed child context type: ' + - 'The child context `foo` is marked as required in `Component`, but its ' + - 'value is `undefined`.\n' + - ' in Component (at **)', - ); - - expect(() => - ReactTestUtils.renderIntoDocument(), - ).toErrorDev( - 'Warning: Failed child context type: ' + - 'Invalid child context `foo` of type `number` ' + - 'supplied to `Component`, expected `string`.\n' + - ' in Component (at **)', - ); - - // No additional errors expected - ReactTestUtils.renderIntoDocument( - , - ); - - ReactTestUtils.renderIntoDocument(); - }); - - it('warns of incorrect prop types on context provider', () => { - const TestContext = React.createContext(); - - TestContext.Provider.propTypes = { - value: PropTypes.string.isRequired, - }; - - ReactTestUtils.renderIntoDocument(); - - class Component extends React.Component { - render() { - return ; - } - } - - expect(() => ReactTestUtils.renderIntoDocument()).toErrorDev( - 'Warning: Failed prop type: The prop `value` is marked as required in ' + - '`Context.Provider`, but its value is `undefined`.\n' + - ' in Component (at **)', - ); - }); - // TODO (bvaughn) Remove this test and the associated behavior in the future. // It has only been added in Fiber to match the (unintentional) behavior in Stack. // @gate !disableLegacyContext || !__DEV__ @@ -371,8 +241,6 @@ describe('ReactContextValidator', () => { 'Warning: MiddleMissingContext.childContextTypes is specified but there is no ' + 'getChildContext() method on the instance. You can either define getChildContext() ' + 'on MiddleMissingContext or remove childContextTypes from it.', - 'Warning: Failed context type: The context `bar` is marked as required ' + - 'in `ChildContextConsumer`, but its value is `undefined`.', ]); expect(childContext.bar).toBeUndefined(); expect(childContext.foo).toBe('FOO'); @@ -699,24 +567,4 @@ describe('ReactContextValidator', () => { 'Warning: ComponentB: Function components do not support contextType.', ); }); - - it('should honor a displayName if set on the context type', () => { - const Context = React.createContext(null); - Context.displayName = 'MyContextType'; - function Validator() { - return null; - } - Validator.propTypes = {dontPassToSeeErrorStack: PropTypes.bool.isRequired}; - - expect(() => { - ReactDOMServer.renderToStaticMarkup( - - {() => } - , - ); - }).toErrorDev( - 'Warning: Failed prop type: The prop `dontPassToSeeErrorStack` is marked as required in `Validator`, but its value is `undefined`.\n' + - ' in Validator (at **)', - ); - }); });