atomiks / tippyjs

Tooltip, popover, dropdown, and menu library
https://atomiks.github.io/tippyjs/
MIT License
11.77k stars 517 forks source link

Upgrade to Popper 2 #678

Closed atomiks closed 4 years ago

atomiks commented 4 years ago

@FezVrasta and I have been working hard on releasing the next Popper version (v2) since November (the rewrite initially started by him in 2018 though but laid dormant for ages due to difficulties). The rewrite of Popper will be explained more in-depth in an article once the final release is out, but it fixes tons of bugs and API flaws that have come to light over the past 3 years (Popper v1 was released in early 2017 and has been in use since Tippy v0!)

It's a breaking major, so Tippy will need to increment its own major (v6). I'd like to make some other changes to Tippy as well to better integrate with libraries like react-spring - effectively stripping the built-in CSS animations out and element creation and making them optional, but of course still easy to use and add in.

powah commented 4 years ago

Just interested why Tippy would need to increment its major? Does it mean that its API will change and have breaking changes?

atomiks commented 4 years ago

Tippy exposes Popper APIs in popperOptions and instance.popperInstance, which have changed, so they'll break when we upgrade.

atomiks commented 4 years ago

Here's the article: https://dev.to/fezvrasta/smarter-tooltips-and-popovers-with-popper-2-44bh

atomiks commented 4 years ago

Update

Most of the work is now complete. I'm hoping to release the final by the end of February, but I'll release an alpha within the next couple days.

Positioning

Popper 2 works much better than v1, so in general you'll find far less positioning issues! There are lots of bug reports for broken positioning due to Popper 1, and I'm pretty sure Popper 2 has fixed almost all of them 🀞

Size

Popper 1 was a pretty large dependency, but it's now 1.7 kB smaller for its full version. I've also been able to delete nearly 1 kB worth of legacy hacks that existed due to v1 bugs/problems.

Minzip sizes, JS + tippy.css file (brotli compression is likely 10-20% smaller):

Version Full size (F) Tree-shaken size (TS) Self (F) Self (TS)
v5 15.7 kB 12.8 kB 8.2 kB 5.5 kB
v6 12.7 kB 10.3 kB 6.8 kB 4.4 kB

There's also the matter of using Popper Lite instead of the full version, which is tiny, but I'm not sure how to incorporate it yet. I'll continue to try to minimize the bundle size nonetheless.

Headless Tippy

You'll be able to render your own tippy element in the next version (the default import will still be the vanilla element creation):

tippy(targets, {
  content: 'hello',
  render({props}) {
    const popper = document.createElement('div');
    popper.textContent = props.content;

    return { 
      popper,
      update(prevProps, nextProps) {
        // DOM diffing (e.g. changing content)
        popper.textContent = nextProps.content;
      }
    };
  }
});

This is mainly useful for React and CSS in JS for advanced scenarios to avoid globals. For Tippy React it will likely be a template prop that you pass static JSX to instead of a render function prop.

Spring animations

You can now integrate these properly with the added instance.unmount() method and being able to set animation: false.

Breaking changes

Import paths may change, I'm not sure of the new structure though. These changes aren't final either

Changes due to Popper 2

Self changes

atomiks commented 4 years ago

I published the first alpha tippy.js@next β€” feedback is appreciated. The breaking changes I listed above should be enough to allow you to experiment with it, not many of the core features have changed.

Also a couple experimental features I didn't mention have been added (may change):

gregkonush commented 4 years ago

@atomiks so if I want to use this alpha version with tippy.js-react what should I do?

atomiks commented 4 years ago

@djkalmyk I'll probably release 6.0.0 this weekend anyway πŸ˜ƒ

Some docs improvements I worked on: