Skip to content

Commit 24dbe85

Browse files
zthxxxBrian Vaughn
authored and
Brian Vaughn
committed
fix(dev-tools): fix show correct displayName with forwardRef in Dev Tools (#17613)
* fix(dev-tools): fix show correct displayName with forwardRef in Dev Tools allow set `displayName` after `React.forwardRef()`, makesure Dev Tools show displayName as same as `getWrappedName` in `shared/getComponentName.js` * Removed a little unnecessary/redundant code. * Fixed lint error (removed unused var)
1 parent bb75a4f commit 24dbe85

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

packages/react-devtools-shared/src/backend/renderer.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ export function getInternalReactConstants(
347347

348348
// NOTICE Keep in sync with shouldFilterFiber() and other get*ForFiber methods
349349
function getDisplayNameForFiber(fiber: Fiber): string | null {
350-
const {elementType, type, tag} = fiber;
350+
const {type, tag} = fiber;
351351

352352
let resolvedType = type;
353353
if (typeof type === 'object' && type !== null) {
@@ -364,8 +364,10 @@ export function getInternalReactConstants(
364364
case IndeterminateComponent:
365365
return getDisplayName(resolvedType);
366366
case ForwardRef:
367+
// Mirror https://github.com/facebook/react/blob/7c21bf72ace77094fd1910cc350a548287ef8350/packages/shared/getComponentName.js#L27-L37
367368
return (
368-
resolvedType.displayName || getDisplayName(resolvedType, 'Anonymous')
369+
(type && type.displayName) ||
370+
getDisplayName(resolvedType, 'Anonymous')
369371
);
370372
case HostRoot:
371373
return null;
@@ -377,11 +379,7 @@ export function getInternalReactConstants(
377379
return null;
378380
case MemoComponent:
379381
case SimpleMemoComponent:
380-
if (elementType.displayName) {
381-
return elementType.displayName;
382-
} else {
383-
return getDisplayName(resolvedType, 'Anonymous');
384-
}
382+
return getDisplayName(resolvedType, 'Anonymous');
385383
case SuspenseComponent:
386384
return 'Suspense';
387385
case SuspenseListComponent:

0 commit comments

Comments
 (0)