@@ -44,16 +44,20 @@ function StatelessComponent(Component) {
44
44
StatelessComponent . prototype . render = function ( ) {
45
45
var Component = ReactInstanceMap . get ( this ) . _currentElement . type ;
46
46
var element = Component ( this . props , this . context , this . updater ) ;
47
+ warnIfInvalidElement ( Component , element ) ;
48
+ return element ;
49
+ } ;
50
+
51
+ function warnIfInvalidElement ( Component , element ) {
47
52
if ( __DEV__ ) {
48
53
warning (
49
54
element === null || element === false || ReactElement . isValidElement ( element ) ,
50
- '%s must be a class extending React.Component or be a stateless ' +
51
- 'function that returns a valid React 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 .' ,
52
57
Component . displayName || Component . name || 'Component'
53
58
) ;
54
59
}
55
- return element ;
56
- } ;
60
+ }
57
61
58
62
/**
59
63
* ------------------ The Life-Cycle of a Composite Component ------------------
@@ -168,7 +172,29 @@ var ReactCompositeComponentMixin = {
168
172
inst = new Component ( publicProps , publicContext , ReactUpdateQueue ) ;
169
173
}
170
174
} else {
171
- inst = new StatelessComponent ( Component ) ;
175
+ if ( __DEV__ ) {
176
+ ReactCurrentOwner . current = this ;
177
+ try {
178
+ inst = Component ( publicProps , publicContext , ReactUpdateQueue ) ;
179
+ } finally {
180
+ ReactCurrentOwner . current = null ;
181
+ }
182
+ } else {
183
+ inst = Component ( publicProps , publicContext , ReactUpdateQueue ) ;
184
+ }
185
+ if ( inst == null || inst . render == null ) {
186
+ renderedElement = inst ;
187
+ warnIfInvalidElement ( Component , renderedElement ) ;
188
+ invariant (
189
+ inst === null ||
190
+ inst === false ||
191
+ ReactElement . isValidElement ( inst ) ,
192
+ '%s(...): A valid React element (or null) must be returned. You may have ' +
193
+ 'returned undefined, an array or some other invalid object.' ,
194
+ Component . displayName || Component . name || 'Component'
195
+ ) ;
196
+ inst = new StatelessComponent ( Component ) ;
197
+ }
172
198
}
173
199
174
200
if ( __DEV__ ) {
@@ -869,7 +895,7 @@ var ReactCompositeComponentMixin = {
869
895
// TODO: An `isValidNode` function would probably be more appropriate
870
896
renderedComponent === null || renderedComponent === false ||
871
897
ReactElement . isValidElement ( renderedComponent ) ,
872
- '%s.render(): A valid ReactComponent must be returned. You may have ' +
898
+ '%s.render(): A valid React element (or null) must be returned. You may have ' +
873
899
'returned undefined, an array or some other invalid object.' ,
874
900
this . getName ( ) || 'ReactCompositeComponent'
875
901
) ;
0 commit comments