atomiks / tippyjs

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

Uncaught TypeError: Cannot read properties of undefined (reading 'applyStyles') #1040

Closed ahsynv closed 2 years ago

ahsynv commented 2 years ago

Bug description

tippy.min.js:formatted:884 Uncaught TypeError: Cannot read properties of undefined (reading 'applyStyles') at tippy.min.js:formatted:884:33 at tippy.min.js:formatted:2:214 at tippy.min.js:formatted:3:2

Reproduction

It is happening when we include tippy.min.js & popper js file dynamically after page loading.

shah commented 2 years ago

We see a similar error when loading dynamically after page load:

image

This is on up to date Edge Chromium on Windows 11 loading from //unpkg.com/@popperjs/core@2 and //unpkg.com/tippy.js@6.

atomiks commented 2 years ago

You have a async race condition problem: @popperjs/core must always be loaded before tippy.js

shah commented 2 years ago

Good advice @atomiks - I'm using script.js's bundle mechanism like this, do you see anything I might be able to improve?

$script(["//unpkg.com/@popperjs/core@2", "//unpkg.com/tippy.js@6"], 'tippy-bundle', () => {
    // Tippy.js should be ready to use after this but window.tippy is not available because of 
    // Uncaught TypeError: Cannot read properties of undefined (reading 'applyStyles')
});

Thanks!

atomiks commented 2 years ago

Based on the docs you're loading both scripts asyncronously while @popperjs/core must be a dependency:

$script('//unpkg.com/@popperjs/core@2', () => {
  $script('//unpkg.com/tippy.js@6', () => {
    // tippy.js is ready with no async race conditions
  });
});
shah commented 2 years ago

Got it @atomiks - thanks! It's working now.