@@ -33,7 +33,13 @@ import {
33
33
REACT_LAZY_TYPE ,
34
34
REACT_CONTEXT_TYPE ,
35
35
} from 'shared/ReactSymbols' ;
36
- import { ClassComponent , HostText , HostPortal , Fragment } from './ReactWorkTags' ;
36
+ import {
37
+ ClassComponent ,
38
+ HostRoot ,
39
+ HostText ,
40
+ HostPortal ,
41
+ Fragment ,
42
+ } from './ReactWorkTags' ;
37
43
import isArray from 'shared/isArray' ;
38
44
import { checkPropStringCoercion } from 'shared/CheckStringCoercion' ;
39
45
@@ -79,6 +85,7 @@ let didWarnAboutGenerators;
79
85
let didWarnAboutStringRefs ;
80
86
let ownerHasKeyUseWarning ;
81
87
let ownerHasFunctionTypeWarning ;
88
+ let ownerHasSymbolTypeWarning ;
82
89
let warnForMissingKey = ( child : mixed , returnFiber : Fiber ) => { } ;
83
90
84
91
if ( __DEV__ ) {
@@ -93,6 +100,7 @@ if (__DEV__) {
93
100
*/
94
101
ownerHasKeyUseWarning = ( { } : { [ string ] : boolean } ) ;
95
102
ownerHasFunctionTypeWarning = ( { } : { [ string ] : boolean } ) ;
103
+ ownerHasSymbolTypeWarning = ( { } : { [ string ] : boolean } ) ;
96
104
97
105
warnForMissingKey = ( child : mixed , returnFiber : Fiber ) => {
98
106
if ( child === null || typeof child !== 'object' ) {
@@ -267,20 +275,67 @@ function throwOnInvalidObjectType(returnFiber: Fiber, newChild: Object) {
267
275
) ;
268
276
}
269
277
270
- function warnOnFunctionType ( returnFiber : Fiber ) {
278
+ function warnOnFunctionType ( returnFiber : Fiber , invalidChild : Function ) {
271
279
if ( __DEV__ ) {
272
- const componentName = getComponentNameFromFiber ( returnFiber ) || 'Component' ;
280
+ const parentName = getComponentNameFromFiber ( returnFiber ) || 'Component' ;
273
281
274
- if ( ownerHasFunctionTypeWarning [ componentName ] ) {
282
+ if ( ownerHasFunctionTypeWarning [ parentName ] ) {
275
283
return ;
276
284
}
277
- ownerHasFunctionTypeWarning [ componentName ] = true ;
285
+ ownerHasFunctionTypeWarning [ parentName ] = true ;
286
+
287
+ const name = invalidChild . displayName || invalidChild . name || 'Component' ;
288
+
289
+ if ( returnFiber . tag === HostRoot ) {
290
+ console . error (
291
+ 'Functions are not valid as a React child. This may happen if ' +
292
+ 'you return %s instead of <%s /> from render. ' +
293
+ 'Or maybe you meant to call this function rather than return it.\n' +
294
+ ' root.render(%s)' ,
295
+ name ,
296
+ name ,
297
+ name ,
298
+ ) ;
299
+ } else {
300
+ console . error (
301
+ 'Functions are not valid as a React child. This may happen if ' +
302
+ 'you return %s instead of <%s /> from render. ' +
303
+ 'Or maybe you meant to call this function rather than return it.\n' +
304
+ ' <%s>{%s}</%s>' ,
305
+ name ,
306
+ name ,
307
+ parentName ,
308
+ name ,
309
+ parentName ,
310
+ ) ;
311
+ }
312
+ }
313
+ }
278
314
279
- console . error (
280
- 'Functions are not valid as a React child. This may happen if ' +
281
- 'you return a Component instead of <Component /> from render. ' +
282
- 'Or maybe you meant to call this function rather than return it.' ,
283
- ) ;
315
+ function warnOnSymbolType ( returnFiber : Fiber , invalidChild : symbol ) {
316
+ if ( __DEV__ ) {
317
+ const parentName = getComponentNameFromFiber ( returnFiber ) || 'Component' ;
318
+
319
+ if ( ownerHasSymbolTypeWarning [ parentName ] ) {
320
+ return ;
321
+ }
322
+ ownerHasSymbolTypeWarning [ parentName ] = true ;
323
+
324
+ const name = String ( invalidChild ) ;
325
+
326
+ if ( returnFiber . tag === HostRoot ) {
327
+ console . error (
328
+ 'Symbols are not valid as a React child.\n' + ' root.render(%s)' ,
329
+ name ,
330
+ ) ;
331
+ } else {
332
+ console . error (
333
+ 'Symbols are not valid as a React child.\n' + ' <%s>%s</%s>' ,
334
+ parentName ,
335
+ name ,
336
+ parentName ,
337
+ ) ;
338
+ }
284
339
}
285
340
}
286
341
@@ -656,7 +711,10 @@ function createChildReconciler(
656
711
657
712
if ( __DEV__ ) {
658
713
if ( typeof newChild === 'function' ) {
659
- warnOnFunctionType ( returnFiber ) ;
714
+ warnOnFunctionType ( returnFiber , newChild ) ;
715
+ }
716
+ if ( typeof newChild === 'symbol' ) {
717
+ warnOnSymbolType ( returnFiber , newChild ) ;
660
718
}
661
719
}
662
720
@@ -778,7 +836,10 @@ function createChildReconciler(
778
836
779
837
if ( __DEV__ ) {
780
838
if ( typeof newChild === 'function' ) {
781
- warnOnFunctionType ( returnFiber ) ;
839
+ warnOnFunctionType ( returnFiber , newChild ) ;
840
+ }
841
+ if ( typeof newChild === 'symbol' ) {
842
+ warnOnSymbolType ( returnFiber , newChild ) ;
782
843
}
783
844
}
784
845
@@ -894,7 +955,10 @@ function createChildReconciler(
894
955
895
956
if ( __DEV__ ) {
896
957
if ( typeof newChild === 'function' ) {
897
- warnOnFunctionType ( returnFiber ) ;
958
+ warnOnFunctionType ( returnFiber , newChild ) ;
959
+ }
960
+ if ( typeof newChild === 'symbol' ) {
961
+ warnOnSymbolType ( returnFiber , newChild ) ;
898
962
}
899
963
}
900
964
@@ -1621,7 +1685,10 @@ function createChildReconciler(
1621
1685
1622
1686
if ( __DEV__ ) {
1623
1687
if ( typeof newChild === 'function' ) {
1624
- warnOnFunctionType ( returnFiber ) ;
1688
+ warnOnFunctionType ( returnFiber , newChild ) ;
1689
+ }
1690
+ if ( typeof newChild === 'symbol' ) {
1691
+ warnOnSymbolType ( returnFiber , newChild ) ;
1625
1692
}
1626
1693
}
1627
1694
0 commit comments