Skip to content
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

honor displayName set on ForwardRef if available #13615

Merged
merged 4 commits into from
Sep 11, 2018

Conversation

quantizor
Copy link
Contributor

@quantizor quantizor commented Sep 11, 2018

Since React.forwardRef returns a component object, some users
(including styled-components and react-native) are starting to
decorate it with various statics including displayName.

This adjusts React's various name-getters to honor this if set and
surface the name in warnings and hopefully DevTools.

Since React.forwardRef returns a component object, some users
(including styled-components and react-native) are starting to
decorate them with various statics including displayName.

This adjusts React's various name-getters to honor this if set and
surface the name in warnings and hopefully DevTools.
@pull-bot
Copy link

pull-bot commented Sep 11, 2018

Details of bundled changes.

Comparing: f6fb03e...7b1b7b7

schedule

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
schedule.development.js n/a n/a 0 B 19.17 KB 0 B 5.74 KB UMD_DEV
schedule.production.min.js n/a n/a 0 B 3.16 KB 0 B 1.53 KB UMD_PROD

Generated by 🚫 dangerJS

@gaearon
Copy link
Collaborator

gaearon commented Sep 11, 2018

@probablyup Can you describe your use case in more detail? What do you see in warnings/DevTools today, and what do you want to see instead?

@quantizor
Copy link
Contributor Author

quantizor commented Sep 11, 2018

@gaearon Sure.

So one of the current nuisances around the forwardRef API is it creates an interim component that is shown in the DevTools, component trees, etc. For many libraries, it makes shipping a component that is readily identifiable in tools like enzyme impossible because the top level component is no longer ours, but ForwardRef. Thus shallow rendering becomes relatively useless and targeting quite difficult.

To get around this, various libraries (styled-components and react-native that I've seen so far) have begun decorating the component returned by the forwardRef API with displayName, etc. This should allow a forwardRef-wrapped component to appear the same in tooling, while layering in that useful ref functionality.

This is all a workaround for the additional component layer. If forwardRef was available as a decorator or class extend target, I don't think this sort of thing would be needed.

@gaearon gaearon merged commit e49f3ca into facebook:master Sep 11, 2018
@gaearon
Copy link
Collaborator

gaearon commented Sep 11, 2018

Sounds good. Thanks.

@gaearon
Copy link
Collaborator

gaearon commented Sep 11, 2018

Also let's tweak this:

https://github.com/facebook/react-devtools/blob/0b9fc7fb42f232069b950a695665ebf22dbc044f/backend/attachRendererFiber.js#L193

quantizor added a commit to quantizor/react-devtools that referenced this pull request Sep 12, 2018
@quantizor quantizor deleted the use-displayName-forwardRef branch September 12, 2018 04:40
@gaearon gaearon mentioned this pull request Sep 13, 2018
bvaughn pushed a commit to facebook/react-devtools that referenced this pull request Sep 27, 2018
Simek pushed a commit to Simek/react that referenced this pull request Oct 25, 2018
* add failing test

* honor displayName set on ForwardRef if available

Since React.forwardRef returns a component object, some users
(including styled-components and react-native) are starting to
decorate them with various statics including displayName.

This adjusts React's various name-getters to honor this if set and
surface the name in warnings and hopefully DevTools.

* fix typing

* Refine later
jetoneza pushed a commit to jetoneza/react that referenced this pull request Jan 23, 2019
* add failing test

* honor displayName set on ForwardRef if available

Since React.forwardRef returns a component object, some users
(including styled-components and react-native) are starting to
decorate them with various statics including displayName.

This adjusts React's various name-getters to honor this if set and
surface the name in warnings and hopefully DevTools.

* fix typing

* Refine later
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants