@@ -49,6 +49,7 @@ import {
49
49
patch as patchConsole ,
50
50
registerRenderer as registerRendererWithConsole ,
51
51
} from './console' ;
52
+ import { isMemo , isForwardRef } from 'react-is' ;
52
53
53
54
import type { Fiber } from 'react-reconciler/src/ReactFiber' ;
54
55
import type {
@@ -326,17 +327,28 @@ export function getInternalReactConstants(
326
327
SCOPE_SYMBOL_STRING ,
327
328
} = ReactSymbols ;
328
329
330
+ function resolveFiberType ( type : any ) {
331
+ // This is to support lazy components with a Promise as the type.
332
+ // see https://github.com/facebook/react/pull/13397
333
+ if ( typeof type . then === 'function' ) {
334
+ return type . _reactResult ;
335
+ }
336
+ if ( isMemo ( type ) ) {
337
+ return resolveFiberType ( type . type ) ;
338
+ }
339
+ if ( isForwardRef ( type ) ) {
340
+ return resolveFiberType ( type . render ) ;
341
+ }
342
+ return type ;
343
+ }
344
+
329
345
// NOTICE Keep in sync with shouldFilterFiber() and other get*ForFiber methods
330
346
function getDisplayNameForFiber ( fiber : Fiber ) : string | null {
331
- const { type, tag} = fiber ;
347
+ const { elementType , type, tag} = fiber ;
332
348
333
- // This is to support lazy components with a Promise as the type.
334
- // see https://github.com/facebook/react/pull/13397
335
349
let resolvedType = type ;
336
350
if ( typeof type === 'object' && type !== null ) {
337
- if ( typeof type . then === 'function' ) {
338
- resolvedType = type . _reactResult ;
339
- }
351
+ resolvedType = resolveFiberType ( type ) ;
340
352
}
341
353
342
354
let resolvedContext : any = null ;
@@ -348,8 +360,6 @@ export function getInternalReactConstants(
348
360
case FunctionComponent :
349
361
case IndeterminateComponent :
350
362
return getDisplayName ( resolvedType ) ;
351
- case MemoComponent :
352
- case SimpleMemoComponent :
353
363
case ForwardRef :
354
364
return (
355
365
resolvedType . displayName || getDisplayName ( resolvedType , 'Anonymous' )
@@ -362,6 +372,13 @@ export function getInternalReactConstants(
362
372
case HostText :
363
373
case Fragment :
364
374
return null ;
375
+ case MemoComponent :
376
+ case SimpleMemoComponent :
377
+ if ( elementType . displayName ) {
378
+ return elementType . displayName ;
379
+ } else {
380
+ return getDisplayName ( resolvedType , 'Anonymous' ) ;
381
+ }
365
382
case SuspenseComponent :
366
383
return 'Suspense' ;
367
384
case SuspenseListComponent :
0 commit comments