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

Deprecation Warning for DOMSubtreeModified #4

Open
500Foods opened this issue Oct 14, 2023 · 2 comments
Open

Deprecation Warning for DOMSubtreeModified #4

500Foods opened this issue Oct 14, 2023 · 2 comments

Comments

@500Foods
Copy link

peity-vanilla.min.js:6 [Deprecation] Listener added for a synchronous 'DOMSubtreeModified' DOM Mutation Event. This event type is deprecated (https://w3c.github.io/uievents/#legacy-event-types) and work is underway to remove it from this browser. Usage of this event listener will cause performance issues today, and represents a risk of future incompatibility. Consider using MutationObserver instead.

@mathieugalle
Copy link

Hi,

This morning, peity broke on a user's desktop because Chrome removed DOMSubtreeModified support.

Here is a quick fix in peity-vanilla.js : you replace the mount and unmount functions by :

        mount() {
            if (!svgSupported) return;
            this.observer = new MutationObserver(this.draw.bind(this));
            const config = { attributes: true, childList: true, subtree: true };
            this.observer.observe(this.element, config);
            this.draw();
            this.mounted = true;
        }

        unmount() {
            if (this.observer) {
                this.observer.disconnect();
            }

            this.svg.remove();
            this.mounted = false;
        }

It looks like support for MutationObserver is 98%

I'm not sure yet of all the consequences of this change, but it works on my Chrome, Firefox and Edge, give it a try if you have the same problem.

@mathieugalle
Copy link

pull request here #5

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

No branches or pull requests

2 participants