diff --git a/lib/mixins/property-effects.js b/lib/mixins/property-effects.js index 7e3300d918..5da858450f 100644 --- a/lib/mixins/property-effects.js +++ b/lib/mixins/property-effects.js @@ -899,6 +899,8 @@ function setupBindings(inst, templateInfo) { addNotifyListener(node, inst, binding); } } + // This ensures all bound elements have a host set, regardless + // of whether they upgrade synchronous to creation node.__dataHost = inst; } } @@ -1376,7 +1378,7 @@ export const PropertyEffects = dedupingMixin(superClass => { */ _initializeProperties() { super._initializeProperties(); - hostStack.registerHost(this); + this._registerHost(); this.__dataClientsReady = false; this.__dataPendingClients = null; this.__dataToNotify = null; @@ -1389,6 +1391,16 @@ export const PropertyEffects = dedupingMixin(superClass => { this.__dataClientsInitialized = false; } + _registerHost() { + if (hostStack.length) { + let host = hostStack[hostStack.length-1]; + host._enqueueClient(this); + // This ensures even non-bound elements have a host set, as + // long as they upgrade synchronously + this.__dataHost = host; + } + } + /** * Overrides `PropertyAccessors` implementation to provide a * more efficient implementation of initializing properties from @@ -2769,9 +2781,9 @@ export const PropertyEffects = dedupingMixin(superClass => { templateInfo = templateInfo || /** @type {!TemplateInfo} */(this._bindTemplate(template, true)); // Ensures that created dom is `_enqueueClient`'d to this element so // that it can be flushed on next call to `_flushProperties` - hostStack.beginHosting(this); + hostStack.push(this); let dom = super._stampTemplate(template, templateInfo); - hostStack.endHosting(this); + hostStack.pop(); // Add template-instance-specific data to instanced templateInfo templateInfo.nodeList = dom.nodeList; // Capture child nodes to allow unstamping of non-prototypical templates @@ -3164,7 +3176,7 @@ export const PropertyEffects = dedupingMixin(superClass => { }); /** - * Helper api for enqueuing client dom created by a host element. + * Stack for enqueuing client dom created by a host element. * * By default elements are flushed via `_flushProperties` when * `connectedCallback` is called. Elements attach their client dom to @@ -3186,39 +3198,4 @@ export const PropertyEffects = dedupingMixin(superClass => { * * @private */ -class HostStack { - constructor() { - this.stack = []; - } - - /** - * @param {*} inst Instance to add to hostStack - * @return {void} - */ - registerHost(inst) { - if (this.stack.length) { - let host = this.stack[this.stack.length-1]; - host._enqueueClient(inst); - } - } - - /** - * @param {*} inst Instance to begin hosting - * @return {void} - */ - beginHosting(inst) { - this.stack.push(inst); - } - - /** - * @param {*} inst Instance to end hosting - * @return {void} - */ - endHosting(inst) { - let stackLen = this.stack.length; - if (stackLen && this.stack[stackLen-1] == inst) { - this.stack.pop(); - } - } -} -const hostStack = new HostStack(); +const hostStack = [];