-
Notifications
You must be signed in to change notification settings - Fork 489
Script imported from template tag does not evaluate #151
Comments
Unfortunately, that does not confirm the test case OK. Sorry for the not very obvious message. I've updated the repo with clearer messages and use of webcomponents 0.5.4 and am still seeing the problem. It should say "Component SCRIPT loaded. Test case OK!" when it works. |
From @ebidel in Polymer/polymer#1197: The import used in the demo contains a Expected: In Chrome, when you click that page it updates the This may have something to do with template being in another document and the polyfill using .innerHTML. |
Looking into it. Looks like importNode is flubbered on FF. |
Some of @atotic's notes:
http://lxr.mozilla.org/mozilla-central/source/dom/base/nsNodeUtils.cpp#344 https://github.com/atotic/web-component-polyfill-test
|
Some history of the issue in firefox: |
The fix is to manually recreate a template node before attaching it to the document. There are a couple potentially appropriate locations for this: In the Polymer source in template stamping code, after calling importNode and before calling attach. |
We do not have to recreate the entire template, just the script elements. After import, I loop though all script nodes, create clone with create element, insert the clone, and remove originals. Sample code is in my test case branch. Aleks
|
@atotic is right, I misworded things. Here's his example workaround: function swapScript(script) {
if (script.nodeName != 'SCRIPT')
throw new Error("swapScript requires script");
var clone = document.createElement('script');
clone.appendChild( document.createTextNode(script.textContent));
script.parentNode.insertBefore(clone, script);
script.parentNode.removeChild(script);
};
var templateClone = document.importNode(importLink.import.content, true);
var scripts = templateClone.querySelectorAll('script');
for (var i=0; i<scripts.length; i++)
swapScript(scripts[i]);
document.body.appendChild(templateClone); |
Thanks for the workaround. I've verified it to work in FF and IE11. Cheers! |
The costs of querySelectorAll on every importNode is too high to pay in the polyfill when it's so easy to work around. I'm going to close this bug with a known workaround unless there's significant clamor to add the feature. It's possible to override document.importNode to globally work around this issue. |
Hello, thanks for the snippet. |
A script imported from a template tag, cloned and appended into the main document does not get evaluated in Firefox and IE11. It works in Safari and Chrome.
Switching the template to a div seems to work better, but gives a type error "wrapper is undefined" in webcomponents.js.
This repo demonstrates the problem.
(use version 0.5.2 of webcomponents.js)
The text was updated successfully, but these errors were encountered: