@@ -122,32 +122,43 @@ function traverseAllChildrenImpl(
122122) {
123123 var type = typeof children ;
124124
125- if ( type === 'undefined' || type === 'boolean' ) {
126- // All of the above are perceived as null.
127- children = null ;
128- }
129-
130- if (
131- children === null ||
132- type === 'string' ||
133- type === 'number' ||
134- // The following is inlined from ReactElement. This means we can optimize
135- // some checks. React Fiber also inlines this logic for similar purposes.
136- ( type === 'object' && children . $$typeof === REACT_ELEMENT_TYPE ) ||
137- ( type === 'object' && children . $$typeof === REACT_CALL_TYPE ) ||
138- ( type === 'object' && children . $$typeof === REACT_RETURN_TYPE ) ||
139- ( type === 'object' && children . $$typeof === REACT_PORTAL_TYPE )
140- ) {
125+ const invokeCallback = ( ) => {
141126 callback (
142127 traverseContext ,
143128 children ,
144129 // If it's the only child, treat the name as if it was wrapped in an array
145130 // so that it's consistent if the number of children grows.
146131 nameSoFar === '' ? SEPARATOR + getComponentKey ( children , 0 ) : nameSoFar ,
147132 ) ;
133+ } ;
134+
135+ if ( children === null ) {
136+ invokeCallback ( ) ;
148137 return 1 ;
149138 }
150139
140+ switch ( type ) {
141+ // All of the below are perceived as null.
142+ case 'undefined' :
143+ case 'boolean' :
144+ children = null ;
145+ case 'string' :
146+ case 'number' :
147+ invokeCallback ( ) ;
148+ return 1 ;
149+ // The following is inlined from ReactElement. This means we can optimize
150+ // some checks. React Fiber also inlines this logic for similar purposes.
151+ case 'object' :
152+ switch ( children . $$typeof ) {
153+ case REACT_ELEMENT_TYPE :
154+ case REACT_CALL_TYPE :
155+ case REACT_RETURN_TYPE :
156+ case REACT_PORTAL_TYPE :
157+ invokeCallback ( ) ;
158+ return 1 ;
159+ }
160+ }
161+
151162 var child ;
152163 var nextName ;
153164 var subtreeCount = 0 ; // Count of children found in the current subtree.
0 commit comments