Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.

Commit 5eb2f21

Browse files
author
Scott J. Miles
committed
tweak order of operations so that document._url is available at element upgrade time when using imports dynamically
1 parent 78cb8b6 commit 5eb2f21

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/HTMLImports.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,22 @@ function makeDocument(resource, url) {
155155
var doc = resource;
156156
if (!(doc instanceof Document)) {
157157
doc = document.implementation.createHTMLDocument(IMPORT_LINK_TYPE);
158-
// install html
159-
doc.body.innerHTML = resource;
160158
}
161159
// cache the new document's source url
162160
doc._URL = url;
163161
// establish a relative path via <base>
164162
var base = doc.createElement('base');
165163
base.setAttribute('href', document.baseURI || document.URL);
166164
doc.head.appendChild(base);
165+
// install HTML last as it may trigger CustomElement upgrades
166+
// TODO(sjmiles): problem wrt to template boostrapping below,
167+
// template bootstrapping must (?) come before element upgrade
168+
// but we cannot bootstrap templates until they are in a document
169+
// which is too late
170+
if (!(resource instanceof Document)) {
171+
// install html
172+
doc.body.innerHTML = resource;
173+
}
167174
// TODO(sorvell): ideally this code is not aware of Template polyfill,
168175
// but for now the polyfill needs help to bootstrap these templates
169176
if (window.HTMLTemplateElement && HTMLTemplateElement.bootstrap) {

0 commit comments

Comments
 (0)