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

Commit

Permalink
don't discard destination insertion points of the shadow host itself …
Browse files Browse the repository at this point in the history
…when we rerender it. fixes Polymer/polymer#512
  • Loading branch information
John Messerly committed Aug 29, 2014
1 parent 79837e5 commit 70e7d91
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/ShadowRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@

// http://w3c.github.io/webcomponents/spec/shadow/#distribution-algorithms
distribution: function(root) {
this.resetAll(root);
this.resetAllSubtrees(root);
this.distributionResolution(root);
},

Expand All @@ -308,6 +308,10 @@
else
resetDestinationInsertionPoints(node);

this.resetAllSubtrees(node);
},

resetAllSubtrees: function(node) {
for (var child = node.firstChild; child; child = child.nextSibling) {
this.resetAll(child);
}
Expand Down
32 changes: 31 additions & 1 deletion test/js/reprojection.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,34 @@ suite('Shadow DOM reprojection', function() {
var content3 = sr3.appendChild(document.createElement('content'));
assert.equal(getVisualInnerHtml(div), '<a><b><d></d></b></a>');
});
});

test('Polymer Issue 512', function () {
// div
// - shadow-root
// -- content
// - a
// -- shadow-root
// --- content
// -- b

var div = document.createElement('div');
var sr = div.createShadowRoot();
var content = sr.appendChild(document.createElement('content'));
var a = div.appendChild(document.createElement('a'));
var b = a.appendChild(document.createElement('b'));
b.offsetWidth;

var srA = a.createShadowRoot();
var contentA = srA.appendChild(document.createElement('content'));
// Ensure we don't improperly reset the insertion point for the shadow host
// node "a" when we re-render it. The fact that "a" was inserted somewhere
// else is not a concern when we are only re-rendering its shadow root.
b.offsetWidth;

assertArrayEqual(content.getDistributedNodes(), [a]);
assertArrayEqual(contentA.getDistributedNodes(), [b]);

assertArrayEqual(a.getDestinationInsertionPoints(), [content]);
assertArrayEqual(b.getDestinationInsertionPoints(), [contentA]);
});
});

0 comments on commit 70e7d91

Please sign in to comment.