Remove unnecessary warning for invalid node

We have an invariant that checks the same case right afterwards.

The warning was originally added in #5884 with a distinct wording.

However it was later changed to the same wording as the invariant in #6008.

I don't see why we would want to have both since they're saying the same thing and with (almost) the same internal stack.
This commit is contained in:
Dan Abramov
2017-01-11 17:11:02 -08:00
committed by Andrew Clark
parent 33c3121f43
commit df0532b0c3
2 changed files with 11 additions and 28 deletions
@@ -123,30 +123,24 @@ describe('ReactStatelessComponent', () => {
);
});
it('should warn when stateless component returns array', () => {
spyOn(console, 'error');
it('should throw when stateless component returns array', () => {
function NotAComponent() {
return [<div />, <div />];
}
expect(function() {
ReactTestUtils.renderIntoDocument(<div><NotAComponent /></div>);
}).toThrow();
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
}).toThrowError(
'NotAComponent(...): A valid React element (or null) must be returned. ' +
'You may have returned undefined, an array or some other invalid object.'
);
});
it('should warn when stateless component returns undefined', () => {
spyOn(console, 'error');
it('should throw when stateless component returns undefined', () => {
function NotAComponent() {
}
expect(function() {
ReactTestUtils.renderIntoDocument(<div><NotAComponent /></div>);
}).toThrow();
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
}).toThrowError(
'NotAComponent(...): A valid React element (or null) must be returned. ' +
'You may have returned undefined, an array or some other invalid object.'
);
@@ -39,26 +39,9 @@ function StatelessComponent(Component) {
StatelessComponent.prototype.render = function() {
var Component = ReactInstanceMap.get(this)._currentElement.type;
var element = Component(this.props, this.context, this.updater);
warnIfInvalidElement(Component, element);
return element;
};
function warnIfInvalidElement(Component, element) {
if (__DEV__) {
warning(
element === null || element === false || React.isValidElement(element),
'%s(...): A valid React element (or null) must be returned. You may have ' +
'returned undefined, an array or some other invalid object.',
Component.displayName || Component.name || 'Component'
);
warning(
!Component.childContextTypes,
'%s(...): childContextTypes cannot be defined on a functional component.',
Component.displayName || Component.name || 'Component'
);
}
}
function shouldConstruct(Component) {
return !!(Component.prototype && Component.prototype.isReactComponent);
}
@@ -205,7 +188,13 @@ var ReactCompositeComponent = {
// Support functional components
if (!doConstruct && (inst == null || inst.render == null)) {
renderedElement = inst;
warnIfInvalidElement(Component, renderedElement);
if (__DEV__) {
warning(
!Component.childContextTypes,
'%s(...): childContextTypes cannot be defined on a functional component.',
Component.displayName || Component.name || 'Component'
);
}
invariant(
inst === null ||
inst === false ||