webcomponentsjs icon indicating copy to clipboard operation
webcomponentsjs copied to clipboard

[ie11] When using webcomponents-loader.js, the Template polyfill is not applied yet when WebComponentsReady is fired

Open ciampo opened this issue 8 years ago • 3 comments

Hello,

I'm importing those scripts at the bottom of the HTML page

<script src="js/demo.js"></script>
<script>if (!window.customElements) { document.write('<!--'); }</script>
<script src="js/third-party/custom-elements-es5-adapter.js"></script>
<!--! do not remove -->
<script src="js/third-party/webcomponents-loader.js"></script>

In demo.js, I wait for the WebComponentsReady event, and then I need to get a <template> from the page in order to stamp it.

var onWCReady = function() {
  var demoTemplate = document.querySelector('#demoTemplate');
  document.body.appendChild(template.content.cloneNode(true));
};

if (window.WebComponents && window.WebComponents.ready === true) {
  onWCReady();
} else {
  window.addEventListener('WebComponentsReady', onWCReady);
}

But in IE11 I get this error: Unable to get property 'cloneNode' of undefined or null reference, and in fact, demoTemplate is still a HTMLUnknownElement.

Also, please note that this doesn't happen if I switch webcomponents-loader with webcomponents-lite.

ciampo avatar Feb 07 '18 09:02 ciampo

workaround: bower install webcomponents/template --save and load before the loader:

<script src="bower_components/template/template.js"></script>
<script src="bower_components/webcomponentsjs/webcomponents-loader.js"></script>

mkropf avatar Apr 06 '18 11:04 mkropf

Hey @mkropf ,

thanks for your answer.

However, adding explicitly the <Template> polyfill defeats the purpose of using webcomponents-loader, and is similar to the fix that I'm applying so far (using webcomponents-lite)

ciampo avatar Apr 06 '18 14:04 ciampo

This should be fixed now: https://github.com/webcomponents/webcomponentsjs/blob/447cf811674e6c05375082d72f839b0e2056b7fa/webcomponents-loader.js#L68-L75 If it is not, please open a new issue with a JSBin that shows the problem.

TimvdLippe avatar Jun 17 '18 14:06 TimvdLippe