-
Notifications
You must be signed in to change notification settings - Fork 50.4k
Remove ad-hoc forks of getComponentName() and fix it #13197
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
Conversation
It doesn't actually need the whole Fiber.
| ? type | ||
| : typeof type === 'function' ? type.displayName || type.name : null; | ||
| } | ||
|
|
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.
One fork down.
| return type.displayName || type.name || 'Unknown'; | ||
| } | ||
| }; | ||
|
|
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.
Two forks down.
| false, | ||
| 'Received an unexpected object in getComponentName(). ' + | ||
| 'This is likely a bug in React. Please file an issue.', | ||
| ); |
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.
Protect against passing Fibers by habit.
| return 'ReactPortal'; | ||
| return 'Portal'; | ||
| case REACT_PROFILER_TYPE: | ||
| return `Profiler(${fiber.pendingProps.id})`; |
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.
If you feel strongly about keeping this, I can add an optional props argument. I'm not sure this is important. I like that having a type is sufficient (which lets us use this utility in SSR, for example).
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'm not sure what this is used for and I see no comments anywhere from before?
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.
No, it's fine. I was just following the forward ref precedent. I think it's mildly useful, but not enough to warrant making the callsites more complicated.
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.
It provided a slightly more detailed entry in the component stack for Profiler components. I don't think it's very important, and I think we can drop this.
|
ReactDOM: size: -0.0%, gzip: -0.0% Details of bundled changes.Comparing: 32f6f25...71590b7 react
react-dom
react-test-renderer
react-art
react-native-renderer
Generated by 🚫 dangerJS |
bvaughn
left a comment
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.
This is a nice cleanup! Thanks for removing those forks.
| return 'ReactPortal'; | ||
| return 'Portal'; | ||
| case REACT_PROFILER_TYPE: | ||
| return `Profiler(${fiber.pendingProps.id})`; |
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.
No, it's fine. I was just following the forward ref precedent. I think it's mildly useful, but not enough to warrant making the callsites more complicated.
* Fix getComponentName() for types with nested $$typeof * Temporarily remove Profiler ID from messages * Change getComponentName() signature to take just type It doesn't actually need the whole Fiber. * Remove getComponentName() forks in isomorphic and SSR * Remove unnecessary .type access where we already have a type * Remove unused type
getComponentName()for a few cases where it was incorrectly reading the type (a482fb4). We didn't notice because we rarely call it for anything other than user-defined components.typealone rather than the Fiber. This might seem like it makes the calling code longer. However we often already have the type destructured anyway when we call it. I also remember from writing some of that code that it was awkward to always have to pass a Fiber around when I only needed a type.getComponentName()that don't handle all the cases it does.