Use MutationObserver to detect when canvas is attached#5955
Use MutationObserver to detect when canvas is attached#5955simonbrunel wants to merge 2 commits intochartjs:masterfrom
Conversation
Using CSS animations to detect when the canvas is attached causes issues when dealing with CSP. Instead, we can use the MutationObserver API to efficiently detect when a node is added or removed, which is now widely adopted (https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver). MutationObserver is not supported on IE10, however we use this feature only to detect when a node is attached to the DOM. Checking if MutationObserver is defined allows us to keep support for old browsers when the node is already attached, which is the case in most situations.
|
I will try this on a few browsers and report back. In terms of 2.8 vs 3.0, our homepage says "IE9+" so we would need to update that. I think its safer to do as a major version upgrade unless we keep some backwards compatibility |
|
With |
|
I can't find a decent solution to handle Even if the keyframe/animation method is not a "modern" solution, it works in all use cases currently reported (except in shadow DOM, but I think it's the same issue with I'm open to any suggestion to make it works efficiently but it seems that it will be really complicated and risky to use |
|
@etimberg Chart.js doesn't work with IE9. The homepage says "IE9+" only because it's running an old version of the code. The latest code in https://github.com/chartjs/www.chartjs.org says IE11 as does https://www.chartjs.org/docs/latest/developers/. Any idea how we can get the latest code deployed to the homepage? |
|
I'm closing this PR since it doesn't fully work and could break existing responsive projects. We can re-open later if we figure out an optimal working way to detect |
Using CSS animations to detect when the canvas is attached causes issues when dealing with CSP. Instead, we can use the
MutationObserverAPI to efficiently detect when a node is added or removed, which is now widely adopted (https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver).MutationObserveris not supported on IE10, however we use this feature only to detect when a node is attached to the DOM. Checking ifMutationObserveris defined allows us to keep support for old browsers when the node is already attached, which is the case in most situations.Any help testing this PR on different browsers (desktop / mobile) is more than welcome! We need to verify that responsiveness still work as expected when the canvas is attached after the chart is created. I think Vue.js or React projects could be concerned.
This PR partially drops support for IE10: should we release at v2.8 or v3 since it could be a breaking change for some projects?
Closes #5952
Fixes #5208