Skip to content
Advertisement

Why does customElements.upgrade appear to not upgrade this custom element?

I have a situation similar to the example below: from a template element, I clone a node tree containing custom elements. One custom element is passed data during initialization, represented here by the line infobox.setData(getData()). The function I use to pass the data (setData) is added by my custom class, so I make sure the custom element is upgraded before calling it, by passing the node tree to customElements.upgrade. (I have also tried passing infobox itself.)

Unfortunately, when I try running my code or the example below I receive the error infobox.setData is not a function. I have confirmed infobox instanceof InfoBox is false and the element has no custom properties or methods prior to being connected to the document, so it seems customElements.upgrade is not upgrading the elements in the tree. What might be preventing it from doing so?

JavaScript
JavaScript
JavaScript

Advertisement

Answer

I narrowed it down to <template> / cloneNode

Submit it here: https://github.com/WICG/webcomponents/issues
(Your credits if it is a bug, in other words I don’t have a clue 🙂

JavaScript

Update: submitted by OP as issue: https://github.com/WICG/webcomponents/issues/946#issuecomment-1200377464

Advertisement