webcomponents / polyfills

Web Components Polyfills
BSD 3-Clause "New" or "Revised" License
1.13k stars 165 forks source link

Patch the registry class only when polyfilling #524

Closed rictic closed 1 year ago

rictic commented 1 year ago

Currently we always write/overwrite window.CustomElementsRegistry when the polyfill loads, even if we don't patch anything else, including window.customElements

If the browser has a native implementation of custom elements, this means that customElements isn't an instance of CustomElementsRegistry, so patching CustomElementsRegistry.prototype, as redefine_custom_elements does, does not effect how customElements behaves. This leads to fun and mysterious bugs!

Better to only write to CustomElementsRegistry when we're doing other patching, and otherwise leave it alone.

Fixes #340.

bicknellr commented 1 year ago

LGTM with a changelog entry, thanks!