Skip to content

Commit

Permalink
Ensure clients are flushed when runtime stamping via _stampTemplate.
Browse files Browse the repository at this point in the history
Maintains flush semantics with Templatizer stamping (relevant to fastDomIf, which is a switch between Templatizer-based stamping and runtime _stampTemplate-based stamping). Works around an issue with `noPatch` where nested undistributed dom-if's won't stamp.  The changes to the tests are to remove testing that the full host tree is correct since the host doing the runtime stamping will no longer be the DOM getRootNode().host at ready time (this is exactly the case with Templatizer, whose semantics we intend to match).
  • Loading branch information
kevinpschaaf committed Aug 22, 2019
1 parent e534c3c commit 7e7febc
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 54 deletions.
1 change: 1 addition & 0 deletions lib/mixins/property-effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -2845,6 +2845,7 @@ export const PropertyEffects = dedupingMixin(superClass => {
// are run at this point during the initial element boot-up.
if (this.__dataClientsReady) {
this._runEffectsForTemplate(templateInfo, this.__data, null, false);
this._flushClients();
}
return dom;
}
Expand Down
118 changes: 64 additions & 54 deletions test/unit/property-effects-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
}
ready() {
super.ready();
this.readied = true;
window.lifecycleOrder.log(this, 'ready');
}
}
Expand Down Expand Up @@ -154,6 +155,9 @@
this.shadowRoot.appendChild(dom);
return dom;
}
stampNoAppend() {
return this._stampTemplate(this.$.templateFromShadowDom);
}
}
customElements.define('x-runtime', XRuntime);
</script>
Expand Down Expand Up @@ -304,6 +308,7 @@
},
idFor(el) {
let host = el.getRootNode().host;
host = host && host.localName !== 'x-runtime' ? host : null;
let id = el.getAttribute('log') || el.id;
return (host ? this.idFor(host) + '|' : '') + el.localName + (id ? '#' + id : '');
}
Expand Down Expand Up @@ -356,9 +361,9 @@
assert.equal(stamped[0], el.$.first);
// Lifecycle order correct
assert.deepEqual(window.lifecycleOrder.ready, [
'x-runtime|x-element#proto|x-element-child#noBinding',
'x-runtime|x-element#proto|x-element-child#hasBinding',
'x-runtime|x-element#proto',
'x-element#proto|x-element-child#noBinding',
'x-element#proto|x-element-child#hasBinding',
'x-element#proto',
'x-runtime'
]);
});
Expand All @@ -372,13 +377,13 @@
assert.equal(stamped[0], el.$.first);
assert.equal(stamped[1], dom.$.first);
assert.deepEqual(window.lifecycleOrder.ready, [
'x-runtime|x-element#proto|x-element-child#noBinding',
'x-runtime|x-element#proto|x-element-child#hasBinding',
'x-runtime|x-element#proto',
'x-element#proto|x-element-child#noBinding',
'x-element#proto|x-element-child#hasBinding',
'x-element#proto',
'x-runtime',
'x-runtime|x-element#shadow|x-element-child#noBinding',
'x-runtime|x-element#shadow|x-element-child#hasBinding',
'x-runtime|x-element#shadow'
'x-element#shadow|x-element-child#noBinding',
'x-element#shadow|x-element-child#hasBinding',
'x-element#shadow'
]);
});

Expand Down Expand Up @@ -419,19 +424,19 @@
assert.equal(stamped[1], dom2.$.first);
assert.equal(stamped[2], dom3.$.first);
assert.deepEqual(window.lifecycleOrder.ready, [
'x-runtime|x-element#proto|x-element-child#noBinding',
'x-runtime|x-element#proto|x-element-child#hasBinding',
'x-runtime|x-element#proto',
'x-element#proto|x-element-child#noBinding',
'x-element#proto|x-element-child#hasBinding',
'x-element#proto',
'x-runtime',
'x-runtime|x-element#shadow|x-element-child#noBinding',
'x-runtime|x-element#shadow|x-element-child#hasBinding',
'x-runtime|x-element#shadow',
'x-runtime|x-element#shadow|x-element-child#noBinding',
'x-runtime|x-element#shadow|x-element-child#hasBinding',
'x-runtime|x-element#shadow',
'x-runtime|x-element#shadow|x-element-child#noBinding',
'x-runtime|x-element#shadow|x-element-child#hasBinding',
'x-runtime|x-element#shadow'
'x-element#shadow|x-element-child#noBinding',
'x-element#shadow|x-element-child#hasBinding',
'x-element#shadow',
'x-element#shadow|x-element-child#noBinding',
'x-element#shadow|x-element-child#hasBinding',
'x-element#shadow',
'x-element#shadow|x-element-child#noBinding',
'x-element#shadow|x-element-child#hasBinding',
'x-element#shadow'
]);
// Unstamp
el._removeBoundDom(dom2);
Expand All @@ -456,9 +461,9 @@
assert.equal(stamped[0], el.$.first);
assert.equal(stamped[1], dom.$.first);
assert.deepEqual(window.lifecycleOrder.ready, [
'x-runtime|x-element#proto|x-element-child#noBinding',
'x-runtime|x-element#proto|x-element-child#hasBinding',
'x-runtime|x-element#proto',
'x-element#proto|x-element-child#noBinding',
'x-element#proto|x-element-child#hasBinding',
'x-element#proto',
'x-runtime',
'x-element#shadow|x-element-child#noBinding',
'x-element#shadow|x-element-child#hasBinding',
Expand Down Expand Up @@ -503,19 +508,19 @@
assert.equal(stamped[1], dom2.$.first);
assert.equal(stamped[2], dom3.$.first);
assert.deepEqual(window.lifecycleOrder.ready, [
'x-runtime|x-element#proto|x-element-child#noBinding',
'x-runtime|x-element#proto|x-element-child#hasBinding',
'x-runtime|x-element#proto',
'x-element#proto|x-element-child#noBinding',
'x-element#proto|x-element-child#hasBinding',
'x-element#proto',
'x-runtime',
'x-element#shadow|x-element-child#noBinding',
'x-element#shadow|x-element-child#hasBinding',
'x-element#shadow',
'x-runtime|x-element#shadow|x-element-child#noBinding',
'x-runtime|x-element#shadow|x-element-child#hasBinding',
'x-runtime|x-element#shadow',
'x-runtime|x-element#shadow|x-element-child#noBinding',
'x-runtime|x-element#shadow|x-element-child#hasBinding',
'x-runtime|x-element#shadow'
'x-element#shadow|x-element-child#noBinding',
'x-element#shadow|x-element-child#hasBinding',
'x-element#shadow',
'x-element#shadow|x-element-child#noBinding',
'x-element#shadow|x-element-child#hasBinding',
'x-element#shadow'
]);
// Unstamp
el._removeBoundDom(dom2);
Expand All @@ -540,13 +545,13 @@
assert.equal(stamped[0], el.$.first);
assert.equal(stamped[1], dom.$.first);
assert.deepEqual(window.lifecycleOrder.ready, [
'x-runtime|x-element#proto|x-element-child#noBinding',
'x-runtime|x-element#proto|x-element-child#hasBinding',
'x-runtime|x-element#proto',
'x-element#proto|x-element-child#noBinding',
'x-element#proto|x-element-child#hasBinding',
'x-element#proto',
'x-runtime',
'x-runtime|x-element#light|x-element-child#noBinding',
'x-runtime|x-element#light|x-element-child#hasBinding',
'x-runtime|x-element#light'
'x-element#light|x-element-child#noBinding',
'x-element#light|x-element-child#hasBinding',
'x-element#light'
]);
});

Expand Down Expand Up @@ -584,19 +589,19 @@
assert.equal(stamped[1], dom2.$.first);
assert.equal(stamped[2], dom3.$.first);
assert.deepEqual(window.lifecycleOrder.ready, [
'x-runtime|x-element#proto|x-element-child#noBinding',
'x-runtime|x-element#proto|x-element-child#hasBinding',
'x-runtime|x-element#proto',
'x-element#proto|x-element-child#noBinding',
'x-element#proto|x-element-child#hasBinding',
'x-element#proto',
'x-runtime',
'x-runtime|x-element#light|x-element-child#noBinding',
'x-runtime|x-element#light|x-element-child#hasBinding',
'x-runtime|x-element#light',
'x-runtime|x-element#light|x-element-child#noBinding',
'x-runtime|x-element#light|x-element-child#hasBinding',
'x-runtime|x-element#light',
'x-runtime|x-element#light|x-element-child#noBinding',
'x-runtime|x-element#light|x-element-child#hasBinding',
'x-runtime|x-element#light'
'x-element#light|x-element-child#noBinding',
'x-element#light|x-element-child#hasBinding',
'x-element#light',
'x-element#light|x-element-child#noBinding',
'x-element#light|x-element-child#hasBinding',
'x-element#light',
'x-element#light|x-element-child#noBinding',
'x-element#light|x-element-child#hasBinding',
'x-element#light'
]);
// Unstamp
el._removeBoundDom(dom2);
Expand Down Expand Up @@ -688,13 +693,18 @@
assert.equal(stamped[0], el.$.first);
// Lifecycle order correct
assert.deepEqual(window.lifecycleOrder.ready, [
'x-runtime|x-element#proto|x-element-child#noBinding',
'x-runtime|x-element#proto|x-element-child#hasBinding',
'x-runtime|x-element#proto',
'x-element#proto|x-element-child#noBinding',
'x-element#proto|x-element-child#hasBinding',
'x-element#proto',
'x-runtime'
]);
});

test('runtime stamped templates ready before append', () => {
const dom = el.stampNoAppend();
assert.isTrue(dom.querySelector('x-element').readied);
});

});

suite('template parsing hooks', () => {
Expand Down

0 comments on commit 7e7febc

Please sign in to comment.