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 committed Dec 28, 2016
1 parent 243d245 commit 2646272
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 @@ -119,30 +119,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 @@ -44,26 +44,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 @@ -210,7 +193,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 2646272

Please sign in to comment.