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

[ClickAwayListener] Remove findDOMNode usage #15179

Merged
merged 14 commits into from
Apr 5, 2019

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented Apr 3, 2019

Removes findDOMNode calls.

Breaking change

The child element of ClickAwayListener needs to be able to hold a ref.

@mui-pr-bot
Copy link

mui-pr-bot commented Apr 3, 2019

Details of bundle changes.

Comparing: ae24eea...aee82dc

bundle parsed diff gzip diff prev parsed current parsed prev gzip current gzip
@material-ui/core -0.06% +0.06% 🔺 349,543 349,346 89,881 89,933
@material-ui/core/Paper 0.00% 0.00% 67,853 67,853 19,809 19,809
@material-ui/core/Paper.esm 0.00% 0.00% 60,184 60,184 18,558 18,558
@material-ui/core/Popper +0.30% 🔺 +0.30% 🔺 34,825 34,930 11,883 11,919
@material-ui/core/styles/createMuiTheme 0.00% 0.00% 17,364 17,364 5,726 5,726
@material-ui/core/useMediaQuery 0.00% 0.00% 2,469 2,469 1,042 1,042
@material-ui/lab +0.07% 🔺 +0.06% 🔺 147,331 147,436 43,555 43,581
@material-ui/styles 0.00% 0.00% 53,105 53,105 15,424 15,424
@material-ui/system 0.00% 0.00% 17,136 17,136 4,525 4,525
Button +0.12% 🔺 +0.11% 🔺 87,919 88,024 26,055 26,083
Modal +0.13% 🔺 +0.12% 🔺 82,035 82,140 24,553 24,582
colorManipulator 0.00% 0.00% 3,232 3,232 1,301 1,301
docs.landing 0.00% 0.00% 49,914 49,914 10,815 10,815
docs.main -0.03% +0.03% 🔺 645,251 645,055 200,422 200,482
packages/material-ui/build/umd/material-ui.production.min.js -0.06% +0.05% 🔺 297,961 297,772 82,664 82,704

Generated by 🚫 dangerJS against aee82dc

@eps1lon eps1lon marked this pull request as ready for review April 3, 2019 15:42
@oliviertassinari
Copy link
Member

@eps1lon We have to solve the same problem with the Tooltip and TrapFocus components. How does this approach scale? The approach has a none negligeable downside for the developer experience. What other options to we have?

  1. use cloneElement + ref
  2. Wait v5 and RFC: createElement changes and surrounding deprecations reactjs/rfcs#107
  3. ?

@eps1lon
Copy link
Member Author

eps1lon commented Apr 3, 2019

How does this approach scale?

What is scaling here?

none negligeable downside

What's the downside? I would rather add some code to avoid subtle bugs with findDOMNode.

use cloneElement + ref

I don't trust this approach to be honest. I'm not sure this properly updates if the ref value of the children changes.

@oliviertassinari
Copy link
Member

oliviertassinari commented Apr 3, 2019

What is scaling here?

Can we apply the same approach everywhere? Or will we have with an inconsistent mix of solutions for the same problem?

What's the downside?

Our users might see this Capture d’écran 2019-04-03 à 18 32 11
as "unnecessary" boilerplate (if we don't need it for 80% of the cases, and can warn for 20% of the time).

I don't trust this approach to be honest. I'm not sure this properly updates if the ref value of the children changes.

Have you tried it?

@eps1lon
Copy link
Member Author

eps1lon commented Apr 3, 2019

Have you tried it?

That's why I said I don't trust it not that it doesn't work.

Can we apply the same approach everywhere?

Why do we need this everywhere?

@oliviertassinari
Copy link
Member

That's why I said I don't trust it not that it doesn't work.

Do you want me to prepare a test?

Why do we need this everywhere?

Because we want to make the usage of findDOMNode() safe in the whole code base.
The Tooltip and the Modal have the same code architecture as the ClickAwayLister. They need to access the host element of their PropTypes.element child.

@eps1lon
Copy link
Member Author

eps1lon commented Apr 3, 2019

That's why I said I don't trust it not that it doesn't work.

Do you want me to prepare a test?

I wouldn't be satisfied by any tests since it won't include concurrent react. What I was hoping for was some official docs for it.

I thought about it a bit more and it seems obvious that this "just" works: https://codesandbox.io/s/n730ozwrrl. I'm just a little bit uncomfortable with all the ref forking without proper cleanup.

@eps1lon eps1lon force-pushed the feat/ClickAwayListener/no-findDOMNode branch 2 times, most recently from 0a18925 to dc7cb3d Compare April 3, 2019 18:48
@eps1lon eps1lon force-pushed the feat/ClickAwayListener/no-findDOMNode branch 3 times, most recently from a47a796 to 4ad6c94 Compare April 3, 2019 19:05
@eps1lon eps1lon force-pushed the feat/ClickAwayListener/no-findDOMNode branch from 4ad6c94 to 1caa634 Compare April 3, 2019 19:06
@eps1lon eps1lon requested a review from oliviertassinari April 3, 2019 19:36
Premature optimization but child refs could contain side-effects
so we dont't want to reduce wasteful calls for them as much as possible
return (
<React.Fragment>
{React.cloneElement(children, { ref: handleRef })}
<EventListener target="document" {...listenerProps} {...other} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we will be able to kill this :)

@eps1lon eps1lon requested a review from oliviertassinari April 4, 2019 11:21
@eps1lon eps1lon merged commit 1db59b0 into mui:next Apr 5, 2019
@eps1lon eps1lon deleted the feat/ClickAwayListener/no-findDOMNode branch April 5, 2019 15:15
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