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

IE still needs full webcomponents.js (non lite) in this edge case #2114

Closed
nippur72 opened this issue Jul 18, 2015 · 6 comments
Closed

IE still needs full webcomponents.js (non lite) in this edge case #2114

nippur72 opened this issue Jul 18, 2015 · 6 comments
Assignees
Labels

Comments

@nippur72
Copy link
Contributor

A custom element created by code (manually creating <dom-module> and injecting template) results in an empty element in IE 11.

But if I switch from webcomponents-lite.js to webcomponents.js it starts to work normally like in Chrome or Firefox.

Any idea why this happens? Is it a webcomponents bug?

I wouldn't like include the full WebComponents just for this reason.

The dom-module creation code is:

function createDomModule(proto,templateString)
{
      var domModule = document.createElement('dom-module');
      domModule.id = proto.is;
      var elemTemplate = document.createElement('template');
      domModule.appendChild(elemTemplate);
      elemTemplate.innerHTML = templateString;
      domModule.createdCallback();
}

As said before, the above code works normally in Chrome and FF, but not IE.

@kevinpschaaf
Copy link
Member

The standalone Template polyfill used in wcjs-lite does not currently support innerHTML. It should be fairly straightforward to add, and I've opened an issue on that tracker: webcomponents/webcomponentsjs#355

In the meantime, I've added code to your createDomModule method that effectively does what the Template polyfill would need to do: performs innerHTML in a separate document (to ensure the elements don't upgrade), and then moves them into the template's content: http://jsbin.com/luvuda/edit?html,output. Hopefully that unsticks you for now.

We also noticed you needed to call createdCallback on dom-module after creating it imperatively to get it to register. We'll add a register API to allow registration for the imperative case as well, since calling createdCallback is a bit hacky.

@nippur72
Copy link
Contributor Author

Ok, big thanks for the workaround code, it works nicely.

@kevinpschaaf
Copy link
Member

Closing, as webcomponents/webcomponentsjs#355 has been resolved (added <template>.innerHTML support to polyfill).

@nippur72
Copy link
Contributor Author

thanks, it works perfectly!

@nippur72
Copy link
Contributor Author

nippur72 commented Aug 9, 2015

@kevinpschaaf just to let you know that the createDomModule() you suggested to use does not work in IE11 if the element has a <template is="dom repeat"> (it raises a weird exception in Polymer).

Don't know if it's a Polymer bug or webcomponents bug.

I tried both versions, the "good" for latest webcomponentsjs and the "meantime" for the old 0.7.2, but none of them work in IE11.

BUT: I switched to a simpler createDomModule() like this:

   function createDomModule(proto) {
      var domModule = document.createElement('dom-module');      
      domModule.id = proto.is;
      var html = "";
      if (proto.style !== undefined)    html += `<style>${proto.style}</style>`;
      if (proto.template !== undefined) html += `<template>${proto.template}</template>`;      
      domModule.innerHTML = html;
      (domModule as any).createdCallback();
   }   

and it works perfectly in all browsers and all webcomponents versions (0.7.2 and 0.7.10), so I'm using it for my project (PolymerTS).

Just wanted to let you know, thank you for your kind help.

@kevinpschaaf
Copy link
Member

Thanks for the follow-up! This pointed out a problem with the innerHTML implementation landed in webcomponents/webcomponentsjs#355, which didn't handle nested templates injected through innerHTML. I posted an issue (webcomponents/webcomponentsjs#374) and fix (webcomponents/webcomponentsjs#376).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants