diff --git a/lib/elements/dom-if.js b/lib/elements/dom-if.js index 48fdc988c6..eb049c5592 100644 --- a/lib/elements/dom-if.js +++ b/lib/elements/dom-if.js @@ -142,28 +142,55 @@ class DomIfBase extends PolymerElement { } } + /** + * Ensures a template has been assigned to `this.__template`. If it has not + * yet been, it querySelectors for it in its children and if it does not yet + * exist (e.g. in parser-generated case), opens a mutation observer and + * waits for it to appear (returns false if it has not yet been found, + * otherwise true). In the `removeNestedTemplates` case, the "template" will + * be the `dom-if` element itself. + * + * @return {boolean} True when a template has been found, false otherwise + */ __ensureTemplate() { - // When `removeNestedTemplates` is true, the "template" is the element - // itself, which has been given a `_templateInfo` property - let template = this._templateInfo ? this : - /** @type {HTMLTemplateElement} */(wrap(this).querySelector('template')); - if (!template) { - // Wait until childList changes and template should be there by then - let observer = new MutationObserver(() => { - if (wrap(this).querySelector('template')) { - observer.disconnect(); - this.__render(); - } else { - throw new Error('dom-if requires a