Skip to content

Commit df0532b

Browse files
gaearonacdlite
authored andcommitted
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 33c3121 commit df0532b

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
@@ -123,30 +123,24 @@ describe('ReactStatelessComponent', () => {
123123
);
124124
});
125125

126-
it('should warn when stateless component returns array', () => {
127-
spyOn(console, 'error');
126+
it('should throw when stateless component returns array', () => {
128127
function NotAComponent() {
129128
return [<div />, <div />];
130129
}
131130
expect(function() {
132131
ReactTestUtils.renderIntoDocument(<div><NotAComponent /></div>);
133-
}).toThrow();
134-
expectDev(console.error.calls.count()).toBe(1);
135-
expectDev(console.error.calls.argsFor(0)[0]).toContain(
132+
}).toThrowError(
136133
'NotAComponent(...): A valid React element (or null) must be returned. ' +
137134
'You may have returned undefined, an array or some other invalid object.'
138135
);
139136
});
140137

141-
it('should warn when stateless component returns undefined', () => {
142-
spyOn(console, 'error');
138+
it('should throw when stateless component returns undefined', () => {
143139
function NotAComponent() {
144140
}
145141
expect(function() {
146142
ReactTestUtils.renderIntoDocument(<div><NotAComponent /></div>);
147-
}).toThrow();
148-
expectDev(console.error.calls.count()).toBe(1);
149-
expectDev(console.error.calls.argsFor(0)[0]).toContain(
143+
}).toThrowError(
150144
'NotAComponent(...): A valid React element (or null) must be returned. ' +
151145
'You may have returned undefined, an array or some other invalid object.'
152146
);

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

+7-18
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,9 @@ function StatelessComponent(Component) {
3939
StatelessComponent.prototype.render = function() {
4040
var Component = ReactInstanceMap.get(this)._currentElement.type;
4141
var element = Component(this.props, this.context, this.updater);
42-
warnIfInvalidElement(Component, element);
4342
return element;
4443
};
4544

46-
function warnIfInvalidElement(Component, element) {
47-
if (__DEV__) {
48-
warning(
49-
element === null || element === false || React.isValidElement(element),
50-
'%s(...): A valid React element (or null) must be returned. You may have ' +
51-
'returned undefined, an array or some other invalid object.',
52-
Component.displayName || Component.name || 'Component'
53-
);
54-
warning(
55-
!Component.childContextTypes,
56-
'%s(...): childContextTypes cannot be defined on a functional component.',
57-
Component.displayName || Component.name || 'Component'
58-
);
59-
}
60-
}
61-
6245
function shouldConstruct(Component) {
6346
return !!(Component.prototype && Component.prototype.isReactComponent);
6447
}
@@ -205,7 +188,13 @@ var ReactCompositeComponent = {
205188
// Support functional components
206189
if (!doConstruct && (inst == null || inst.render == null)) {
207190
renderedElement = inst;
208-
warnIfInvalidElement(Component, renderedElement);
191+
if (__DEV__) {
192+
warning(
193+
!Component.childContextTypes,
194+
'%s(...): childContextTypes cannot be defined on a functional component.',
195+
Component.displayName || Component.name || 'Component'
196+
);
197+
}
209198
invariant(
210199
inst === null ||
211200
inst === false ||

0 commit comments

Comments
 (0)