New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
devtools: Remove ForwardRef/Memo from display name if displayName is set
#21952
devtools: Remove ForwardRef/Memo from display name if displayName is set
#21952
Conversation
| (elementType && elementType.displayName) || | ||
| (type && type.displayName) || | ||
| getDisplayName(resolvedType, 'Anonymous') | ||
| // Display name in React does not use `Memo` as a wrapper but fallback name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should sync the display names for memo as well. React will compute Component while devtools will display it as Memo(Component). No strong opinion whether we want to use Memo as a wrapper or fallback. For me personally React.memo is used like a higher-order component i.e. Memo as a wrapper is intuitive for me.
|
See #21939 (comment) |
|
I think, DevTools should be there based on @bvaughn decided in previous conversation. But I think problem root is library implementation. most of React library overused HOC Context value injection layer, ReactDevTools right. As a result, causing noises against actual view component by invisible component that's just a library interface doesn't appear screen but existing on screen as a empty layer. DevTools |
|
This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated. |
|
Bump |
8789464
to
d3bd393
Compare
|
@eps1lon any updates for this? |
d3bd393
to
db8187d
Compare
Rebased and added screenshots and a digest of the diff in display names in devtools. |
| ): string { | ||
| const functionName = getDisplayName(innerType, fallbackName); | ||
| return (outerType: any).displayName || `${wrapperName}(${functionName})`; | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Could just inline this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea was to just copy the logic from whatever React packages are using so that it's easier to sync it. But then Devtools cover a bunch of React versions so it's probably fine to do things differently. Will check if this is trivial to do (i.e. do I remember how this one year old PR works ;D )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. It actually save potentially wasted work if outerType.displayName is set.
aa717ab
to
6f0ccb5
Compare


Summary
The displayed name of e.g.
will no longer include the
ForwardRefbadge in the element tree. This also applies toReact.memo.This matches how display names are computed in
getComponentNameFromTypee.g. in warnings.Closes #21939
Test Plan
linked codesandboxes produce desired display nameSeeForwardRefComponentWithCustomDisplayNameinreact-devtools-shellBefore:
After: