-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
displayName set on forwardRef is not honored #1810
Comments
Hmm, does react itself respect .displayName on a forwardRef? |
@ljharb It doesn't in the devtools as of right now... but it's a weird case since it's a metacomponent thingy and doesn't have a renderable |
cc @gaearon |
If it doesn't show up in the dev tools, then I wouldn't expect it to make any sense to have a displayName - typically only custom components have displayNames, and forwardRef produces a special kind of component that's not a class or an SFC. |
Yeah, I’m not really sure what to do about it honestly. Usage of the ref
forwarding API is incredibly awkward, but the functionality is super
compelling.
…On Fri, Sep 7, 2018 at 5:58 PM Jordan Harband ***@***.***> wrote:
If it doesn't show up in the dev tools, then I wouldn't expect it to make
any sense to have a displayName - typically only custom components have
displayNames, and forwardRef produces a special kind of component that's
not a class or an SFC.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1810 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAiy1vD5c-j1-midQWwLTBpnVl69XG4wks5uYvorgaJpZM4WflEw>
.
|
If DevTools doesn't show it that sounds more like a bug with DevTools that we can fix. |
Do React warnings show it? |
I'll experiment and get back to you |
@gaearon I don't believe it does:
|
@gaearon this will be a problem with react-native too since they started doing the same thing we are: facebook/react-native@e708010#diff-e250436371d8e58356be701ad28b37caR268 |
Made a PR against React to support this: facebook/react#13615 |
…yName` on the forwardRef Fixes #1810.
…yName` on the forwardRef Fixes #1810.
@probablyup I'm running into the issue you're describing. When using |
@jackson-sandland what version of react and enzyme and enzyme adapter are you using? |
@ljharb I figured out how to set the Just found a comment by @lencioni over at AirBnb saying finding by component reference instead of string is preferred. |
Finding by reference is preferred; so in that case, you can find by the wrapped component constructor itself. Setting the displayName should make it show up in |
@ljharb
The approach that produced the above result is:
The code below worked in the unit tests where Button is a
|
@jackson-sandland would you mind filing a new issue covering all this? I'll be happy to take a look at it ASAP. |
Describe the bug
In styled-components v4 beta we started decorating the forwardRef wrapper with displayName and various other statics to reduce the amount of interim component layers during rendering and preserve various library behaviors. https://github.com/styled-components/styled-components/blob/30c372cf635e0db77f74c0aaacf60deda729581c/src/models/StyledComponent.js#L249-L311
However, it doesn't seem like enzyme surfaces a
displayName
set on a forwardRef component.To Reproduce
See this codesandbox: https://codesandbox.io/s/yv7l2p76q9
Expected behavior
The test expectations should work since name and displayName are set on the forwardRef node.
It would be really great if this could work for a few reasons:
Shallow rendering does not currently render the immediate child of ForwardRef, so if we modified our library so the wrapped child of ForwardRef had all the statics etc it still wouldn't work without diving
The components don't show up at all when using "find" off of "mount" since ForwardRef isn't honoring displayName
Sidebar: I really wish ref forwarding was implemented as a decorator or class mixin... sigh.
The text was updated successfully, but these errors were encountered: