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

[withWidth] Broken innerRef property #12518

Closed
2 tasks done
alimo opened this issue Aug 14, 2018 · 4 comments
Closed
2 tasks done

[withWidth] Broken innerRef property #12518

alimo opened this issue Aug 14, 2018 · 4 comments
Labels
good first issue Great for first contributions. Enable to learn the contribution process.

Comments

@alimo
Copy link

alimo commented Aug 14, 2018

Regarding #12216, innerRef property was implemented for withWidth and withTheme HOCs. But since withWidth itself uses withTheme as its wrapper, innerRef will not be propagated through both of them.

Since we're not using forwardRef API at the moment (#10825 (comment)), i think we should come up with a solution for the existing HOCs to forward the innerRef property.

A solution would be to add an options argument to withTheme to set an optional flag (like forwardInnerRef) so the innerRef property provided to WithTheme component would be forwarded to the wrapped component (WithWidth in this case) as its innerRef property.

  • This is a v1.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

We should be able to access the component wrapped with withWidth.

Current Behavior

By using innerRef, we get the WithWidth component.

Steps to Reproduce

Edit 94w6qpoqly
(See console output)

Your Environment

Tech Version
Material-UI v1.5.0
React v16.4.2
Browser Chrome 56
@oliviertassinari
Copy link
Member

oliviertassinari commented Aug 14, 2018

@alimo What do you think of removing the innerRef dead code from the withWidth and wait for #10825 so we made it clear it's not supported?

@oliviertassinari oliviertassinari added core good first issue Great for first contributions. Enable to learn the contribution process. labels Aug 14, 2018
@alimo
Copy link
Author

alimo commented Aug 14, 2018

@oliviertassinari as you mentioned, using forwardRef is a breaking change and #10825 has a v2 milestone. So it might be a long time until we are able to use this API in our projects. The problem of using multiple HOCs remains unsolved until then.

I suggest an enhancement on the current innerRef API as I mentioned in the issue description. Something like how react-redux/connect takes a withRef option. But in this case, when a certain flag is provided, we will be forwarding the provided innerRef function to the wrapped component as its innerRef property (instead of ref).

@oliviertassinari
Copy link
Member

oliviertassinari commented Aug 15, 2018

@alimo I understand your suggestion but I don't think that it worth pushing the story forward. I think that we should go the other way around, cleaning the property from the component. v2 should come by early 2019.

People should avoid relying on ref as much as possible. If you have this requirement, surely you are doing something custom, you should be willing to make your own ref forwarding logic. This issue isn't a blocker, there are ways to workaround it.

@alimo
Copy link
Author

alimo commented Aug 15, 2018

@oliviertassinari You're right. It would make things more complicated than it should be. Thank you for your response. Keep up the good work 😊

oliviertassinari added a commit that referenced this issue Aug 15, 2018
As it was raised in #12518 this property isn't doing anything, withTheme is taking precedence.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Great for first contributions. Enable to learn the contribution process.
Projects
None yet
Development

No branches or pull requests

2 participants