@samitouri / QOS-React-2 / commits / df0532b0c3

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.

Dan Abramov committed Dec 28, 2016 at 00:31 UTC df0532b0c38fc3579a9993ea58abd5ed33cd16a6
2 files changed +11 -28
src/renderers/shared/shared/__tests__/ReactStatelessComponent-test.js
+4 -10
@@ -123,30 +123,24 @@ describe('ReactStatelessComponent', () => {
123 );
124 });
125
126 - it('should warn when stateless component returns array', () => {
127 - spyOn(console, 'error');
126 + it('should throw when stateless component returns array', () => {
127 function NotAComponent() {
128 return [<div />, <div />];
129 }
130 expect(function() {
131 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(
133 'NotAComponent(...): A valid React element (or null) must be returned. ' +
134 'You may have returned undefined, an array or some other invalid object.'
135 );
136 });
137
141 - it('should warn when stateless component returns undefined', () => {
142 - spyOn(console, 'error');
138 + it('should throw when stateless component returns undefined', () => {
139 function NotAComponent() {
140 }
141 expect(function() {
142 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(
144 'NotAComponent(...): A valid React element (or null) must be returned. ' +
145 'You may have returned undefined, an array or some other invalid object.'
146 );
src/renderers/shared/stack/reconciler/ReactCompositeComponent.js
+7 -18
@@ -39,26 +39,9 @@ function StatelessComponent(Component) {
39 StatelessComponent.prototype.render = function() {
40 var Component = ReactInstanceMap.get(this)._currentElement.type;
41 var element = Component(this.props, this.context, this.updater);
42 - warnIfInvalidElement(Component, element);
42 return element;
43 };
44
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 -
45 function shouldConstruct(Component) {
46 return !!(Component.prototype && Component.prototype.isReactComponent);
47 }
@@ -205,7 +188,13 @@ var ReactCompositeComponent = {
188 // Support functional components
189 if (!doConstruct && (inst == null || inst.render == null)) {
190 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 + }
198 invariant(
199 inst === null ||
200 inst === false ||