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][base-ui] Replace or refactor to use Floating UI #32587

Closed
rodrigofariow opened this issue May 3, 2022 · 15 comments · Fixed by #37960
Closed

[Popper][base-ui] Replace or refactor to use Floating UI #32587

rodrigofariow opened this issue May 3, 2022 · 15 comments · Fixed by #37960
Assignees
Labels
breaking change component: Popper The React component. See <Popup> for the latest version. new feature New feature or request v6.x
Milestone

Comments

@rodrigofariow
Copy link

With https://floating-ui.com/ aiming to replace Popper.js, I was wondering what are your plans with regards to Popper component. Are you planning to deprecate it, refactor it to use Floating UI or any other changes?
I wanted to know if I can use it without worring too much if it will get changed soon.

Thank you for your time 🙏

@danilo-leal danilo-leal changed the title [Popper]: Are there any plans to replace/refactor this component to Floating UI? [Popper] Are there any plans to replace/refactor this component to Floating UI? May 5, 2022
@danilo-leal danilo-leal added component: Popper The React component. See <Popup> for the latest version. support: question Community support but can be turned into an improvement status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels May 5, 2022
@siriwatknp siriwatknp added new feature New feature or request and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jun 3, 2022
@siriwatknp
Copy link
Member

cc @michaldudak

@michaldudak
Copy link
Member

We don't plan to do anything breaking in the v5 timeframe, so you're safe to use whatever we currently have. We'll likely upgrade to Floating UI at some point, as we generally want to use the latest dependencies. If upgrading from Popper to Floating UI cause breaking changes, we'll do it in the next major.

cc @mnajdova (as the co-owner of this component)

@mnajdova
Copy link
Member

mnajdova commented Jun 3, 2022

The plan sounds good to me 👍

@rodrigofariow
Copy link
Author

Sounds good, thanks for the info!

@mbrookes mbrookes changed the title [Popper] Are there any plans to replace/refactor this component to Floating UI? [Popper] Replace or refactor to use Floating UI Jun 4, 2022
@mbrookes mbrookes removed the support: question Community support but can be turned into an improvement label Jun 4, 2022
@mbrookes mbrookes reopened this Jun 4, 2022
@oliviertassinari
Copy link
Member

oliviertassinari commented Jun 12, 2022

If upgrading from Popper to Floating UI cause breaking changes, we'll do it in the next major.

I have added this issue to #30660 and added the v6.x label, to be sure we consider this in the next major cc @atomiks. We have to consider the pros & cons.

Pros:

Cons:

  • Breaking changes

Benchmark

@jy95
Copy link

jy95 commented Jul 22, 2022

Floating UI has a page for the pros https://floating-ui.com/docs/motivation#comparison-with-popper-style-api
For the migration guide : https://floating-ui.com/docs/migration

So what could be the cons ? The refactoring cost ?

@o-alexandrov
Copy link

o-alexandrov commented Jan 13, 2023

This issue should be labeled as a bug, instead of new feature.

There are many resolved bugs in Floating-UI in the past few months (when Popperjs didn't receive updates).

  • since Floating-UI is a rebranding, we should consider its bugfixes (at least some of them) as fixes to @popperjs/core

@popperjs/core is 252% (2.5x times) heavier than @floating-ui/react-dom when bundling with vite 4/rollup 3 (both latest).
Screenshot 2023-01-13 at 3 12 46 PM

@atomiks
Copy link
Contributor

atomiks commented Jan 14, 2023

@o-alexandrov it's lighter but not that much lighter. It depends what features you import though, as each piece is tree-shakeable (within reason).

https://bundlejs.com is the best source to check. For example, for common usage:

@o-alexandrov
Copy link

o-alexandrov commented Jan 14, 2023

@atomiks most importantly, do you agree on labeling as a bug based on the raised arguments?


You can compare weight on bundlephobia, bundlejs, etc. for a general idea of the weight.

However, to know the precise difference, you should compare it postbundling, achieving feature-parity.

  • it’s as you said, code could be better written on how well side-effects could be inferred and other nuances that allow for better tree-shaking and minification

My weight observation is based on making changes in the Menu component from MUI.

  • ex. copy Menu component, replace popper, bundle, compare weight between two components

@oliviertassinari
Copy link
Member

oliviertassinari commented Mar 2, 2023

We might be able to rely entirely on CSS with https://drafts.csswg.org/css-anchor-position/ to solve the positioning problem. I think within 3 years. It's detailed a bit in https://developer.chrome.com/blog/tether-elements-to-each-other-with-css-anchor-positioning/. I raised the opportunity in #35914 (comment).

What I conclude from this is that using @floating-ui/dom makes more sense than @floating-ui/react-dom so we can minimize future breaking changes, by keeping a close developer-facing API.

One last thought, is there a CSS anchor() ponyfill that we could use? Unless we consider that it's too early.

@atomiks
Copy link
Contributor

atomiks commented Mar 3, 2023

There's a polyfill for CSS anchor positioning using @floating-ui/dom 54k gzipped (but it's not a ponyfill). I guess using @floating-ui/dom directly would be the best choice before being able to use native CSS in the future. Note that if CSS doesn't support all the features it has, the positioning part of Floating UI could start leveraging native CSS where possible while also enhancing/adding additional features on top, acting as a sort of wrapper.

@o-alexandrov
Copy link

o-alexandrov commented Mar 9, 2023

It would be great, if the end users wouldn't have to download floating-ui (as it'd improve Lighthouse LCP everyone has issues with), if their browsers support CSS anchor positioning.

In other words, imho, this feature should be conditionally dynamically imported w/ a polyfill (mentioned above), but not shipped to everyone. It doesn't matter the polyfill is large, two-thirds of users are typically supported within first weeks of the browsers' API release, so on average the data transfer should decrease comparing to shipping floating-ui to everyone, especially in web-based mobile apps and for 100% of Electron (desktop) users due to the bundled latest version of Chromium.
MUI shouldn't wait until the feature is widely supported by browsers, but instead have conditional dynamic imports.
(out of topic, same as Temporal API for date pickers)

@atomiks
Copy link
Contributor

atomiks commented Mar 9, 2023

@o-alexandrov the main problem is that it appears CSS doesn't completely replace all of Floating UI's features, namely uncertainties with same-placement overflow prevention (shifting), arrows, boundaries, virtual elements, available space size, inline elements, cross-document anchoring, shadow DOM, virtual/software keyboards on iOS, pinch-zooming, etc. I guess it depends on what features MUI wants or needs, but some of those are quite fundamental.

I'm not sure if shipping a polyfill (rather than something pure) is something a library should be doing 🤔 . I didn't realize the polyfill was that large which is unfortunate, shipping 50 kB to 1/3 of users, especially browsers other than Chrome/old iOS (it would especially affect mobile users), doesn't seem great. Waiting for wider support seems like a better path to me — the positioning part of Floating UI could get smaller anyway if it detects native CSS can be used for core parts, reducing bundle size.

@o-alexandrov
Copy link

o-alexandrov commented Mar 9, 2023

@atomiks imho, the ideal for MUI would be:

flowchart
  1{Browser supports CSS anchor positioning}
  1 --> |No| 2{Have enough time for a more complex fallback}
  1 --> |Yes| 3[use CSS anchor positioning]
  2 --> |Yes| 4[load floating-ui dynamically, so the fallback is minimal in size]
  2 --> |No| 5[load CSS anchor positioning polyfill dynamically]

Unfortunately, in the source code of floating-ui, end users always load everything they import, there are no dynamic imports (no feature detection based imports).

  • I understand CSS anchor positioning is in early stages

Are you saying there are plans on adding a dynamic import for CSS anchor positioning to floating-ui in the future?

@hbjORbj hbjORbj self-assigned this Mar 23, 2023
@mnajdova mnajdova changed the title [Popper] Replace or refactor to use Floating UI [base][Popper] Replace or refactor to use Floating UI Apr 17, 2023
@michaldudak michaldudak added this to the Base UI: Stable release milestone Jul 7, 2023
@michaldudak michaldudak assigned michaldudak and unassigned hbjORbj Jul 7, 2023
@oliviertassinari
Copy link
Member

oliviertassinari commented Jul 10, 2023

@michaldudak On the topic what to do with the <Popper> component, I think that we should start by updating https://mui.com/base-ui/react-popper/ to give us a better hold of production constraints, we should likely:

  1. Add a demo with a clean transition. For example to match https://www.radix-ui.com/docs/primitives/components/popover. The current demos are not usable in production because of this IMHO.
  2. Add a "without portal" demo. While most cases need a portal (otherwise it's unusable anytime there is an overflow CSS property), I think that it could be nice to make this optional.

Otherwise,

  • a. Consider a component API to automatically wire the anchorEl. The problem with demos like https://mui.com/base-ui/react-popper/#basics is that anytime your component logic grows, hooks make it hard to follow the logic, you need to scroll up and down to understand the logic, not a great DX. MUI X repository has not too bad examples of this problem, e.g. mui-x/docs/data/data-grid/state/RestoreStateApiRef.js.
  • b. the Popper bundling the Portal is a questionable choice. If we remove it (I like the idea to keep things flat like in Radix, making Popover.Portal optional), we would still need an API to change the overflow detection https://floating-ui.com/docs/detectoverflow#altboundary based on portalled vs. not portalled.
  • c. I think that it would be much better to wrap @floating-ui so 1. developers don't have to think about which version they use, and so that once CSS 2. so we can add custom plugins, e.g. collisionPadding, something we need for [Tooltip] Tooltip touch the edge base-ui#413. 3. so we can, later on, more easier handle migration between versions, like this allows us today between popper and floating UI. A quick benchmark: Radix UI wraps @floating-ui/dom, React Aria build it in house, ariakit wraps @floating-ui/dom.
  • d. to optimize the solution to be compatible with a world CSS based. So not sure how much space there is for a hook or even a component in the future.

@michaldudak michaldudak changed the title [base][Popper] Replace or refactor to use Floating UI [Popper][base-ui] Replace or refactor to use Floating UI Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change component: Popper The React component. See <Popup> for the latest version. new feature New feature or request v6.x
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.