Closed epithet closed 3 years ago
Exception is thrown here: https://github.com/webcomponents/polyfills/blob/041aff1a2408a5854c880e45dfad150556e51bcb/packages/scoped-custom-element-registry/src/scoped-custom-element-registry.js#L345
Reason: native insertAdjacentHTML returns undefined, but WeakMaps only support objects as keys:
insertAdjacentHTML
undefined
WeakMap
Can be reproduced with the following example, which should spell out "success" (I can get the example to work by commenting out the line installScopedCreationMethod(Element, 'insertAdjacentHTML');):
installScopedCreationMethod(Element, 'insertAdjacentHTML');
<span>u</span><span id="host"></span> <script> class MyWidgetGlobal extends HTMLElement { constructor() { super() this.attachShadow({ mode: 'open' }) this.shadowRoot.innerHTML = '<span>s</span>' } } class MyWidgetScoped extends HTMLElement { constructor() { super() this.attachShadow({ mode: 'open' }) this.shadowRoot.innerHTML = '<span>c</span>' } } window.customElements.define('my-widget', MyWidgetGlobal) try { const span = document.querySelector('span') span.insertAdjacentHTML('beforebegin', '<my-widget></my-widget>') // next line won't execute span.insertAdjacentText('afterend', 'c') } catch (ex) { console.log(ex) } const scope = new CustomElementRegistry() scope.define('my-widget', MyWidgetScoped) const host = document.querySelector('#host') const shadowRoot = host.attachShadow({ mode: 'open', customElements: scope }) shadowRoot.innerHTML = '<span>es</span>' try { const span = shadowRoot.querySelector('span') span.insertAdjacentHTML('beforebegin', '<my-widget></my-widget>') // next line won't execute span.insertAdjacentText('afterend', 's') } catch (ex) { console.log(ex) } </script>
@justinfagnani
Exception is thrown here: https://github.com/webcomponents/polyfills/blob/041aff1a2408a5854c880e45dfad150556e51bcb/packages/scoped-custom-element-registry/src/scoped-custom-element-registry.js#L345
Reason: native
insertAdjacentHTML
returnsundefined
, butWeakMap
s only support objects as keys:Can be reproduced with the following example, which should spell out "success" (I can get the example to work by commenting out the line
installScopedCreationMethod(Element, 'insertAdjacentHTML');
):