Skip to content

Commit

Permalink
Remove unnecessary warning for invalid node
Browse files Browse the repository at this point in the history
We have an invariant that checks the same case right afterwards.

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

However it was later changed to the same wording as the invariant in facebook#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.
  • Loading branch information
gaearon authored and acdlite committed Jan 12, 2017
1 parent 33c3121 commit df0532b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
);
Expand Down
25 changes: 7 additions & 18 deletions src/renderers/shared/stack/reconciler/ReactCompositeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 ||
Expand Down

0 comments on commit df0532b

Please sign in to comment.