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] Upgrade to popper.js to v2 #21761

Merged
merged 28 commits into from Oct 22, 2020
Merged

[Popper] Upgrade to popper.js to v2 #21761

merged 28 commits into from Oct 22, 2020

Conversation

joshwooding
Copy link
Member

@joshwooding joshwooding commented Jul 11, 2020

Breaking changes

  • Upgrade Popper.js from v1 to v2.
    This third-party library has introduced a lot of changes.

    You can read their migration guide or the following summary:

    • The CSS prefixes have changed:

      popper: {
        zIndex: 1,
      - '&[x-placement*="bottom"] $arrow': {
      + '&[data-popper-placement*="bottom"] $arrow': {
    • Method names have changed.

      -popperRef.current.scheduleUpdate()
      +popperRef.current.update()
      -popperRef.current.update()
      +popperRef.current.forceUpdate()
    • Modifiers' API has changed a lot. There are too many changes to be covered here.


Just wanted to see what kind of work was needed to migrate and have it run through the CI.

Relevant to: #19358
Closes #19358

Demo: https://deploy-preview-21761--material-ui.netlify.app/components/popper/

modifiers={{
flip: {
enabled: ${flip},
modifiers={[
Copy link
Member Author

Choose a reason for hiding this comment

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

Modifiers have changed a lot. I didn't want to make any decisions about what to include on this page yet so I included most of the functionality in the flip, preventOverflow and arrow modifiers.

| 'top-end'
| 'top-start'
| 'top';
export type PopperPlacementType = ComputedPlacement;
Copy link
Member Author

Choose a reason for hiding this comment

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

I thought it would be nicer to depend on their types. It would be more correct to use Placement instead of ComputedPlacement but I wasn't sure if auto placements were left out on purpose.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed this recently. I'd rather use the correct types

@oliviertassinari
Copy link
Member

oliviertassinari commented Jul 11, 2020

For context, I have been collecting resources (started to) around how we could drop Popper in https://trello.com/c/WOj1Oase/2277-remove-popperjs.

},
},
{
name: 'onUpdate',
Copy link
Member Author

Choose a reason for hiding this comment

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

onUpdate needs to be a custom modifier now

let popperModifiers = [
{
name: 'preventOverflow',
options: {
Copy link
Member Author

Choose a reason for hiding this comment

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

Before altBoundary also affected flip but the behaviour is now customisable in both places.

*/
modifiers: PropTypes.object,
modifiers: PropTypes.arrayOf(
Copy link
Member Author

Choose a reason for hiding this comment

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

Might, be too much info when using the correct types, but I would rather use the correct types and simplify for proptypes.

@mui-pr-bot
Copy link

mui-pr-bot commented Jul 11, 2020

@material-ui/core: parsed: -0.80% 😍, gzip: -0.70% 😍
@material-ui/lab: parsed: -1.29% 😍, gzip: -0.64% 😍

Details of bundle changes

Generated by 🚫 dangerJS against 7c0f612

@joshwooding
Copy link
Member Author

joshwooding commented Jul 11, 2020

@material-ui/core: parsed: -1.19% 😍, gzip: -1.61% 😍
@material-ui/lab: parsed: -1.88% 😍, gzip: -2.66% 😍

Details of bundle changes

Generated by 🚫 dangerJS against d272bf1

Nice to see the size decrease. We probably could drop this more using popper lite and importing the modifiers we use (https://popper.js.org/docs/v2/tree-shaking/#popper-lite) but we would only not import hide and offset I don't see a massive difference but will try it to see.

Nice work @FezVrasta

const [open, setOpen] = React.useState(false);
const [anchorEl, setAnchorEl] = React.useState<PopperProps['anchorEl']>(null);
const [anchorEl, setAnchorEl] = React.useState<PopperProps.anchorEl>(null);
Copy link
Member Author

Choose a reason for hiding this comment

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

For some reason, eslint always changes this for me...

Copy link
Member

Choose a reason for hiding this comment

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

eslint shouldn't touch this file to begin with. What IDE + extension are you using to run eslint on this file?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah looks like it's a webstorm feature:

When checking if ESLint should be run on a .ts files, WebStorm 2018.3 analyzes the root config statically to see if it includes the following plugins:

"parser":"babel-eslint" or
"parser":"typescript-eslint-parser" or
"eslint-plugin-typescript" or
"@typescript-eslint/parser"

I can turn it off by adding typescript files to .eslintignore

Copy link
Member

Choose a reason for hiding this comment

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

Can't you tell webstorm to ignore it? Though it might resolve itself after #21758

@FezVrasta

This comment has been minimized.

@eps1lon

This comment has been minimized.

@oliviertassinari
Copy link
Member

oliviertassinari commented Jul 12, 2020

We haven't had any discussion around dropping popper so I wouldn't bother with it in this PR

As we are investing time in improving the relative positioning logic, we might as well keep the broader picture in mind and consider all our options. The broader choice of options we have, the best decision we can make.

I think that now is a great opportunity to look at:

  • What can we hide from the public API?
  • Identify the minimum set of features we need from the position, identify bundle size-reduction opportunities.

Now, there are longer-term considerations:

  • We aim to solve all the hard problems developers don't want to solve themselves that are related to UI. The relative position logic is within this scope, so is the data grid, date picker, charting, focus trap, design, etc.
  • Is it worth the ROI? In other words, will it be worth spending $ on it? Unclear. There are a couple of alternatives UI libraries that went with a custom implementation, we can learn from them, how well is it turning out? (What the Trello card is about) What about the opportunity cost?

@joshwooding
Copy link
Member Author

As we are investing time in improving the relative positioning logic

What issues do you see with the relative position logic apart from #21661?

I've done some more investigation locally:

Variation Size Snapshot Visualizer package Size Visualizer popper Size Percentage Size Difference
next Computed sizes of "material-ui.production.min.js" with "umd" format

bundler parsing size: 933,823 B
browser parsing size (minified with terser): 327,527 B
download size (minified and gzipped): 94,923 B
857.29KB 86.42KB 10.08% 0%
new popper Computed sizes of "material-ui.production.min.js" with "umd" format

bundler parsing size: 898,034 B
browser parsing size (minified with terser): 323,206 B
download size (minified and gzipped): 93,054 B
823.98KB 53.1KB 6.44% -3.89%
new popper with arrow, flip and preventOverflow Computed sizes of "material-ui.production.min.js" with "umd" format

bundler parsing size: 894,463 B
browser parsing size (minified with terser): 321,900 B
download size (minified and gzipped): 92,632 B
820.68KB 49.66KB 6.05% -4.27%
new popper with arrow and flip Computed sizes of "material-ui.production.min.js" with "umd" format

bundler parsing size: 889,389 B
browser parsing size (minified with terser): 320,510 B
download size (minified and gzipped): 92,079 B
815.92KB 44.92KB 5.50% -4.83%
new popper with arrow and preventOverflow Computed sizes of "material-ui.production.min.js" with "umd" format

bundler parsing size: 887,291 B
browser parsing size (minified with terser): 319,649 B
download size (minified and gzipped): 91,807 B
814.04KB 43.02KB 5.29% -5.04%

@oliviertassinari
Copy link
Member

oliviertassinari commented Jul 12, 2020

What issues do you see with the relative position logic apart from #21661?

I'm not aware of any other GitHub issues than #21661 open by users.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jul 15, 2020
@joshwooding joshwooding force-pushed the popper-v2 branch 3 times, most recently from 27d202b to e2c6d9c Compare July 23, 2020 22:12
@eps1lon eps1lon removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jul 24, 2020
Copy link
Member

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

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

There are a couple of tests that could possibly be simplified:

packages/material-ui/src/Popper/Popper.test.js Outdated Show resolved Hide resolved
@joshwooding joshwooding requested a review from eps1lon July 24, 2020 23:06
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jul 29, 2020
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 21, 2020
@eps1lon
Copy link
Member

eps1lon commented Oct 22, 2020

Bundle size-wise, it seems that after rebasing on HEAD, the change is neutral

Capture d’écran 2020-10-18 à 11 18 35

Makes a lot more sense now after landing #23181:

@material-ui/core: parsed: -0.80% heart_eyes, gzip: -0.70% heart_eyes
@material-ui/lab: parsed: -1.29% heart_eyes, gzip: -0.64% heart_eyes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change new feature New feature or request package: material-ui Specific to @mui/material
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Popper changed home
5 participants