@@ -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,68 @@ 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
+ // eslint-disable-next-line react-internal/safe-string-coercion
325
+ const name = String ( invalidChild ) ;
326
+
327
+ if ( returnFiber . tag === HostRoot ) {
328
+ console . error (
329
+ 'Symbols are not valid as a React child.\n' + ' root.render(%s)' ,
330
+ name ,
331
+ ) ;
332
+ } else {
333
+ console . error (
334
+ 'Symbols are not valid as a React child.\n' + ' <%s>%s</%s>' ,
335
+ parentName ,
336
+ name ,
337
+ parentName ,
338
+ ) ;
339
+ }
284
340
}
285
341
}
286
342
@@ -656,7 +712,10 @@ function createChildReconciler(
656
712
657
713
if ( __DEV__ ) {
658
714
if ( typeof newChild === 'function' ) {
659
- warnOnFunctionType ( returnFiber ) ;
715
+ warnOnFunctionType ( returnFiber , newChild ) ;
716
+ }
717
+ if ( typeof newChild === 'symbol' ) {
718
+ warnOnSymbolType ( returnFiber , newChild ) ;
660
719
}
661
720
}
662
721
@@ -778,7 +837,10 @@ function createChildReconciler(
778
837
779
838
if ( __DEV__ ) {
780
839
if ( typeof newChild === 'function' ) {
781
- warnOnFunctionType ( returnFiber ) ;
840
+ warnOnFunctionType ( returnFiber , newChild ) ;
841
+ }
842
+ if ( typeof newChild === 'symbol' ) {
843
+ warnOnSymbolType ( returnFiber , newChild ) ;
782
844
}
783
845
}
784
846
@@ -894,7 +956,10 @@ function createChildReconciler(
894
956
895
957
if ( __DEV__ ) {
896
958
if ( typeof newChild === 'function' ) {
897
- warnOnFunctionType ( returnFiber ) ;
959
+ warnOnFunctionType ( returnFiber , newChild ) ;
960
+ }
961
+ if ( typeof newChild === 'symbol' ) {
962
+ warnOnSymbolType ( returnFiber , newChild ) ;
898
963
}
899
964
}
900
965
@@ -1621,7 +1686,10 @@ function createChildReconciler(
1621
1686
1622
1687
if ( __DEV__ ) {
1623
1688
if ( typeof newChild === 'function' ) {
1624
- warnOnFunctionType ( returnFiber ) ;
1689
+ warnOnFunctionType ( returnFiber , newChild ) ;
1690
+ }
1691
+ if ( typeof newChild === 'symbol' ) {
1692
+ warnOnSymbolType ( returnFiber , newChild ) ;
1625
1693
}
1626
1694
}
1627
1695
0 commit comments