Skip to content

Conversation

@LeaVerou
Copy link
Contributor

@LeaVerou LeaVerou commented Nov 4, 2021

New Pull Request

Currently, ApexCharts uses a script that hasn't been updated since 2014 to detect element resizes, which adds two functions to the global scope, breaking module encapsulation (see #2743) and even causes errors when Apex Charts are used in Shadow DOM (see #1332).
We now have ResizeObserver to react to element resizes which is faster and more robust, and is supported pretty much everywhere.
In this PR I added a new utility module that exports two helper functions (addResizeListener() and removeResizeListener()) that follow the same API as the existing library used. I also added guidance for people who need to support IE11, pointing to the most popular polyfill.

Fixes #1332
Fixes #2743

As a heads up, I could not get the tests in this repo to work prior to making this change. Just running npm install and then npm build and npm test in a fresh clone resulted in the entire testsuite failing. I see they seem to be passing in CI, so not sure what's up with that. If something additional is needed to get the testsuite working, it may be good to mention it in CONTRIBUTING.md. Therefore, it was hard to test for any regressions, but code seems to work when tested manually by browsing samples and e.g. changing the CSS for <body> so that the chart resizes.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes (see note)

Copy link
Contributor

@junedchhipa junedchhipa left a comment

Choose a reason for hiding this comment

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

Looks good 👍🏻
Thanks a lot for the contribution.

@junedchhipa junedchhipa merged commit db4b136 into apexcharts:master Nov 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ESM leaks to the global scope Not able to use ApexCharts.js as web-component

2 participants