Skip to content

Commit 2646272

Browse files
committed
Remove unnecessary warning for invalid node
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.
1 parent 243d245 commit 2646272

File tree

2 files changed

+11
-28
lines changed

2 files changed

+11
-28
lines changed

src/renderers/shared/shared/__tests__/ReactStatelessComponent-test.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -119,30 +119,24 @@ describe('ReactStatelessComponent', () => {
119119
);
120120
});
121121

122-
it('should warn when stateless component returns array', () => {
123-
spyOn(console, 'error');
122+
it('should throw when stateless component returns array', () => {
124123
function NotAComponent() {
125124
return [<div />, <div />];
126125
}
127126
expect(function() {
128127
ReactTestUtils.renderIntoDocument(<div><NotAComponent /></div>);
129-
}).toThrow();
130-
expectDev(console.error.calls.count()).toBe(1);
131-
expectDev(console.error.calls.argsFor(0)[0]).toContain(
128+
}).toThrowError(
132129
'NotAComponent(...): A valid React element (or null) must be returned. ' +
133130
'You may have returned undefined, an array or some other invalid object.'
134131
);
135132
});
136133

137-
it('should warn when stateless component returns undefined', () => {
138-
spyOn(console, 'error');
134+
it('should throw when stateless component returns undefined', () => {
139135
function NotAComponent() {
140136
}
141137
expect(function() {
142138
ReactTestUtils.renderIntoDocument(<div><NotAComponent /></div>);
143-
}).toThrow();
144-
expectDev(console.error.calls.count()).toBe(1);
145-
expectDev(console.error.calls.argsFor(0)[0]).toContain(
139+
}).toThrowError(
146140
'NotAComponent(...): A valid React element (or null) must be returned. ' +
147141
'You may have returned undefined, an array or some other invalid object.'
148142
);

src/renderers/shared/stack/reconciler/ReactCompositeComponent.js

+7-18
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,9 @@ function StatelessComponent(Component) {
4444
StatelessComponent.prototype.render = function() {
4545
var Component = ReactInstanceMap.get(this)._currentElement.type;
4646
var element = Component(this.props, this.context, this.updater);
47-
warnIfInvalidElement(Component, element);
4847
return element;
4948
};
5049

51-
function warnIfInvalidElement(Component, element) {
52-
if (__DEV__) {
53-
warning(
54-
element === null || element === false || React.isValidElement(element),
55-
'%s(...): A valid React element (or null) must be returned. You may have ' +
56-
'returned undefined, an array or some other invalid object.',
57-
Component.displayName || Component.name || 'Component'
58-
);
59-
warning(
60-
!Component.childContextTypes,
61-
'%s(...): childContextTypes cannot be defined on a functional component.',
62-
Component.displayName || Component.name || 'Component'
63-
);
64-
}
65-
}
66-
6750
function shouldConstruct(Component) {
6851
return !!(Component.prototype && Component.prototype.isReactComponent);
6952
}
@@ -210,7 +193,13 @@ var ReactCompositeComponent = {
210193
// Support functional components
211194
if (!doConstruct && (inst == null || inst.render == null)) {
212195
renderedElement = inst;
213-
warnIfInvalidElement(Component, renderedElement);
196+
if (__DEV__) {
197+
warning(
198+
!Component.childContextTypes,
199+
'%s(...): childContextTypes cannot be defined on a functional component.',
200+
Component.displayName || Component.name || 'Component'
201+
);
202+
}
214203
invariant(
215204
inst === null ||
216205
inst === false ||

0 commit comments

Comments
 (0)