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

[core] Remove some rootRef properties #9676

Merged
merged 2 commits into from
Dec 31, 2017

Conversation

cherniavskii
Copy link
Member

@cherniavskii cherniavskii commented Dec 30, 2017

Currently there is no way to get Typography node ref.
Passing ref to Typography returns component instance, returned by withStyles.
There is findDOMNode, but it's not recommended.

Breaking changes

  • Remove the rootRef property from the Grow and List component.
    Instead, you can use the ref property in combinaison with findDOMNode().

@oliviertassinari
Copy link
Member

@cherniavskii What's your use case? Have you tried innerRef?

@cherniavskii
Copy link
Member Author

cherniavskii commented Dec 30, 2017

@oliviertassinari yes, but innerRef returns a class instance without withStyles wrapper. I need a reference to Typography DOM node (for scrolling)

@oliviertassinari
Copy link
Member

oliviertassinari commented Dec 30, 2017

@cherniavskii I'm very tempted to refuse this pull-request and to remove the rootRef property from the Grow and List components. It seems both components have no valid reason for using them. We can save bundle size.
The React team hasn't deprecated findDOMNode() yet for a reason. I'm assuming it's because it's still a useful escape hatch. I would rather wait for facebook/react#11401. Still, you are right, it's not recommended.
cc @mui-org/core-contributors

@oliviertassinari oliviertassinari added the component: Typography The React component. label Dec 30, 2017
@oliviertassinari
Copy link
Member

oliviertassinari commented Dec 30, 2017

Deprecate the "ref" prop entirely

This facebook/react#11401 (comment)! It would even make sense to expose such API on our side.

@oliviertassinari
Copy link
Member

@cherniavskii Ok, react-bootstrap maintainers have the same position on the topic facebook/react#11401 (comment). Let's remove those two refs props. The less we have them, the better we anticipate the future. The ref property might just get away.

@oliviertassinari oliviertassinari added PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI good first issue Great for first contributions. Enable to learn the contribution process. labels Dec 30, 2017
@oliviertassinari oliviertassinari self-assigned this Dec 31, 2017
@oliviertassinari oliviertassinari changed the title [Typography] ad rootRef prop [core] Remove some rootRef properties Dec 31, 2017
@oliviertassinari oliviertassinari added breaking change core and removed component: Typography The React component. good first issue Great for first contributions. Enable to learn the contribution process. PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Dec 31, 2017
@oliviertassinari oliviertassinari merged commit 56e79df into mui:v1-beta Dec 31, 2017
@oliviertassinari
Copy link
Member

oliviertassinari commented Dec 31, 2017

@cherniavskii Thank you for raising the concern!

@cherniavskii
Copy link
Member Author

@oliviertassinari so solution is to use findDOMNode for now?

@cherniavskii cherniavskii deleted the typography-rootRef-prop branch January 1, 2018 11:50
@oliviertassinari
Copy link
Member

@cherniavskii Yes, and you can abstract it away with:

class RootNodeWrapper extends React.Component {
  componentDidMount() {
    this.props.rootRef(ReactDOM.findDOMNode(this))
  }
  componentWillUnmount() {
    this.props.rootRef(null)
  }
  render() {
    return <this.props.children />
  }
}

// usage
<RootNodeWrapper rootRef={...}><SomeChildComponent /></RootNodeWrapper>

If you prefer.

@cherniavskii
Copy link
Member Author

@oliviertassinari Thanks!

@mbrookes
Copy link
Member

mbrookes commented Jan 1, 2018

@oliviertassinari Might be worth documenting...

@oliviertassinari
Copy link
Member

@mbrookes This is idiomatic React. What do you want to document?

@mbrookes
Copy link
Member

mbrookes commented Jan 1, 2018

Just thinking for users who have been depending on the rootRef prop, it could be a useful reminder. Perhaps in the release notes?

@oliviertassinari
Copy link
Member

oliviertassinari commented Jan 1, 2018

@mbrookes Yes, the "Breaking changes" section of this pull request description will end up in the release notes 👍 .

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.

3 participants