diff --git a/lib/elements/dom-if.js b/lib/elements/dom-if.js index 8c09d91293..5b801856af 100644 --- a/lib/elements/dom-if.js +++ b/lib/elements/dom-if.js @@ -40,7 +40,7 @@ import { showHideChildren } from '../utils/templatize.js'; * @summary Custom element that conditionally stamps and hides or removes * template content based on a boolean flag. */ -export class DomIf extends PolymerElement { +class DomIfBase extends PolymerElement { // Not needed to find template; can be removed once the analyzer // can find the tag name from customElements.define call @@ -87,10 +87,7 @@ export class DomIf extends PolymerElement { constructor() { super(); this.__renderDebouncer = null; - this.__syncProps = null; - this.__instance = null; this._lastIf = false; - this.__ctor = null; this.__hideTemplateChildren__ = false; } @@ -145,6 +142,56 @@ export class DomIf extends PolymerElement { } } + __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