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

[Popper] Refactor to more commonly known react patterns #16613

Merged
merged 2 commits into from
Jul 17, 2019

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented Jul 16, 2019

Makes the controlled/uncontrolled + derived state pattern more obvious which results in one less create callback (wasteful popper re-creation) and flipPlacement call.

Videos are taken with <Popper flip /> and we're about to scroll to a position where the placement needs to be flipped. When this happens we used to get this weird create-update-create-update chain that is now replaced by a continuous update.

https://material-ui.com/components/popper/#scroll-playground

mui-popper-before-placement

PR:
mui-popper-after-placement

And we even got less shipped code. Hope that makes the implementation more reasonable.

@eps1lon eps1lon added new feature New feature or request component: Popper The React component. See <Popup> for the latest version. labels Jul 16, 2019
@mui-pr-bot
Copy link

Details of bundle changes.

Comparing: 6dc4ca3...97d2ca4

bundle parsed diff gzip diff prev parsed current parsed prev gzip current gzip
@material-ui/core -0.01% -0.01% 327,481 327,435 90,327 90,317
@material-ui/core/Paper 0.00% 0.00% 68,477 68,477 20,410 20,410
@material-ui/core/Paper.esm 0.00% 0.00% 61,761 61,761 19,177 19,177
@material-ui/core/Popper -0.16% -0.07% 28,942 28,896 10,401 10,394
@material-ui/core/Textarea 0.00% 0.00% 5,505 5,505 2,362 2,362
@material-ui/core/TrapFocus 0.00% 0.00% 3,753 3,753 1,577 1,577
@material-ui/core/styles/createMuiTheme 0.00% 0.00% 16,156 16,156 5,816 5,816
@material-ui/core/useMediaQuery 0.00% 0.00% 3,098 3,098 1,310 1,310
@material-ui/lab -0.03% -0.03% 141,786 141,740 43,821 43,809
@material-ui/styles 0.00% 0.00% 51,886 51,886 15,380 15,380
@material-ui/system 0.00% 0.00% 15,576 15,576 4,445 4,445
Button 0.00% 0.00% 79,713 79,713 24,354 24,354
Modal 0.00% 0.00% 14,548 14,548 5,102 5,102
Portal 0.00% 0.00% 3,471 3,471 1,568 1,568
Rating 0.00% 0.00% 70,267 70,267 22,068 22,068
Slider 0.00% 0.00% 75,098 75,098 23,309 23,309
colorManipulator 0.00% 0.00% 3,904 3,904 1,543 1,543
docs.landing 0.00% 0.00% 54,338 54,338 13,762 13,762
docs.main -0.01% -0.01% 647,681 647,615 204,260 204,234
packages/material-ui/build/umd/material-ui.production.min.js -0.01% -0.01% 299,890 299,850 86,098 86,090

Generated by 🚫 dangerJS against 97d2ca4

@eps1lon eps1lon marked this pull request as ready for review July 16, 2019 17:48
Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

👌

@@ -102,11 +113,10 @@ const Popper = React.forwardRef(function Popper(props, ref) {
},
// We could have been using a custom modifier like react-popper is doing.
// But it seems this is the best public API for this use case.
onCreate: createChainedFunction(handlePopperUpdate, popperOptions.onCreate),
Copy link
Member

Choose a reason for hiding this comment

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

I can't remember why it was added in #12085. Let's try without 🤷‍♂️

Copy link
Member Author

Choose a reason for hiding this comment

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

In RTL you create the placement with flipPlacement so when you change placement in an RTL environment you only create a new PopperJS which wouldn't update the child prop. Since it's now immediately derived we no longer need this line.

/**
* Flips placement if in <body dir="rtl" />
* @param {string} placement
*/
function flipPlacement(placement) {
const direction = (typeof window !== 'undefined' && document.body.getAttribute('dir')) || 'ltr';
Copy link
Member

Choose a reason for hiding this comment

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

Oh, that's funny. I might have done it this way so we didn't have to bundle the default theme. As of today, we could probably use the useTheme from styles. But anyway, that's outside of the scope :).

Copy link
Member Author

Choose a reason for hiding this comment

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

Was thinking about this as well but would've required a test change. Wanted to be sure it's clear that this is only a refactor. Will follow-up.

@eps1lon eps1lon merged commit c54e545 into mui:master Jul 17, 2019
@eps1lon eps1lon deleted the fix/Popper-polish branch July 17, 2019 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: Popper The React component. See <Popup> for the latest version. new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants