@@ -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,29 @@ 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 ( isForwardRef ( type ) ) {
337
+ return type . render ;
338
+ }
339
+ // recursively resolving memo type in case of memo(forwardRef(Component))
340
+ if ( isMemo ( type ) ) {
341
+ return resolveFiberType ( type . type ) ;
342
+ }
343
+ return type ;
344
+ }
345
+
329
346
// NOTICE Keep in sync with shouldFilterFiber() and other get*ForFiber methods
330
347
function getDisplayNameForFiber ( fiber : Fiber ) : string | null {
331
- const { type, tag} = fiber ;
348
+ const { elementType , type, tag} = fiber ;
332
349
333
- // This is to support lazy components with a Promise as the type.
334
- // see https://github.com/facebook/react/pull/13397
335
350
let resolvedType = type ;
336
351
if ( typeof type === 'object' && type !== null ) {
337
- if ( typeof type . then === 'function' ) {
338
- resolvedType = type . _reactResult ;
339
- }
352
+ resolvedType = resolveFiberType ( type ) ;
340
353
}
341
354
342
355
let resolvedContext : any = null ;
@@ -348,8 +361,6 @@ export function getInternalReactConstants(
348
361
case FunctionComponent :
349
362
case IndeterminateComponent :
350
363
return getDisplayName ( resolvedType ) ;
351
- case MemoComponent :
352
- case SimpleMemoComponent :
353
364
case ForwardRef :
354
365
return (
355
366
resolvedType . displayName || getDisplayName ( resolvedType , 'Anonymous' )
@@ -362,6 +373,13 @@ export function getInternalReactConstants(
362
373
case HostText :
363
374
case Fragment :
364
375
return null ;
376
+ case MemoComponent :
377
+ case SimpleMemoComponent :
378
+ if ( elementType . displayName ) {
379
+ return elementType . displayName ;
380
+ } else {
381
+ return getDisplayName ( resolvedType , 'Anonymous' ) ;
382
+ }
365
383
case SuspenseComponent :
366
384
return 'Suspense' ;
367
385
case SuspenseListComponent :
0 commit comments