Skip to content
This repository was archived by the owner on Sep 20, 2019. It is now read-only.

Commit b743f4e

Browse files
author
Steve Orvell
committed
Merge pull request #447 from webcomponents/targeted-template-upgrade
Upgrade templates when performing the CustomElements treewalk
2 parents 7297a08 + ef67dec commit b743f4e

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

src/CustomElements/observe.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,18 +306,12 @@ if (originalCreateShadowRoot) {
306306
};
307307
}
308308

309-
function upgradeAll(doc) {
310-
if (HTMLTemplateElement && HTMLTemplateElement.bootstrap) {
311-
HTMLTemplateElement.bootstrap(doc);
312-
}
313-
addedNode(doc);
314-
}
315309
// exports
316310
scope.watchShadow = watchShadow;
317311
scope.upgradeDocumentTree = upgradeDocumentTree;
318312
scope.upgradeDocument = upgradeDocument;
319313
scope.upgradeSubtree = addedSubtree;
320-
scope.upgradeAll = upgradeAll;
314+
scope.upgradeAll = addedNode;
321315
scope.attached = attached;
322316
scope.takeRecords = takeRecords;
323317

src/CustomElements/upgrade.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ var flags = scope.flags;
3333
*/
3434
// Upgrade a node if it can be upgraded and is not already.
3535
function upgrade(node, isAttached) {
36+
// upgrade template elements before custom elements
37+
if (node.localName === 'template') {
38+
if (window.HTMLTemplateElement && HTMLTemplateElement.decorate) {
39+
HTMLTemplateElement.decorate(node);
40+
}
41+
}
3642
if (!node.__upgraded__ && (node.nodeType === Node.ELEMENT_NODE)) {
3743
var is = node.getAttribute('is');
3844
// find definition first by localName and secondarily by is attribute

src/Template/Template.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ if (typeof HTMLTemplateElement === 'undefined') {
2828
NOTE: there is no support for dynamically adding elements to templates.
2929
*/
3030
HTMLTemplateElement.decorate = function(template) {
31-
if (!template.content) {
32-
template.content = contentDoc.createDocumentFragment();
31+
// if the template is decorated, return fast
32+
if (template.content) {
33+
return;
3334
}
35+
template.content = contentDoc.createDocumentFragment();
3436
var child;
3537
while (child = template.firstChild) {
3638
template.content.appendChild(child);
@@ -63,6 +65,9 @@ if (typeof HTMLTemplateElement === 'undefined') {
6365
canDecorate = false;
6466
}
6567
}
68+
69+
// bootstrap recursively
70+
HTMLTemplateElement.bootstrap(template.content);
6671
};
6772

6873
/**

wct.conf.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"suites": ["tests/runner.html"]
2+
"suites": ["tests/runner.html"],
3+
"clientOptions": {
4+
"environmentImports": []
5+
}
36
}

0 commit comments

Comments
 (0)