Skip to content

Commit

Permalink
Fix dom-if detachment
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Apr 15, 2017
1 parent a282565 commit 2722532
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
8 changes: 6 additions & 2 deletions src/lib/template/dom-if.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@
},

detached: function() {
if (!this.parentNode ||
(this.parentNode.nodeType == Node.DOCUMENT_FRAGMENT_NODE &&
var parentNode = this.parentNode;
if (parentNode && parentNode.localName == this.is) {
parentNode = Polymer.dom(parentNode).parentNode;
}
if (!parentNode ||
(parentNode.nodeType == Node.DOCUMENT_FRAGMENT_NODE &&
(!Polymer.Settings.hasShadow ||
!(this.parentNode instanceof ShadowRoot)))) {
this._teardownInstance();
Expand Down
17 changes: 12 additions & 5 deletions test/unit/dom-if.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,22 @@
assert.equal(stamped[0].parentNode, document.body);
});

test('remove & re-add works correctly', function() {
test('remove & re-add works correctly', function(done) {
var wrapper = hybridDomIfWrapper;
var domIf = hybridDomIf;
Polymer.dom(document.body).removeChild(wrapper);
Polymer.dom(document.body).appendChild(wrapper);
CustomElements.takeRecords();
hybridDomIf.render();
domIf.render();
var stamped = Array.from(document.querySelectorAll('[hybrid-stamped]'));
assert.equal(stamped.length, 1);
assert.equal(stamped[0].parentNode, document.body);
assert.equal(stamped.length, 0);
Polymer.dom(removalContainer).appendChild(wrapper);
CustomElements.takeRecords();
setTimeout(function() {
stamped = Array.from(document.querySelectorAll('[hybrid-stamped]'));
assert.equal(stamped.length, 1);
assert.equal(stamped[0].parentNode, removalContainer);
done();
});
});

test('children removed correctly', function() {
Expand Down
23 changes: 20 additions & 3 deletions test/unit/dom-repeat.html
Original file line number Diff line number Diff line change
Expand Up @@ -3898,21 +3898,38 @@ <h4>x-repeat-chunked</h4>
test('parent is parent of <dom-repeat>', function() {
var stamped = Array.from(document.querySelectorAll('[hybrid-stamped]'));
assert.equal(stamped.length, 3);
stamped.forEach(function(el) {
stamped.forEach(function(el, i) {
assert.equal(el.parentNode, document.body);
assert.equal(el.textContent, hybridDomRepeat.items[i].prop);
});
});

test('remove & re-add works correctly', function() {
var wrapper = hybridDomRepeatWrapper;
Polymer.dom(document.body).removeChild(wrapper);
Polymer.dom(document.body).appendChild(wrapper);
CustomElements.takeRecords();
hybridDomRepeat.render();
var stamped = Array.from(document.querySelectorAll('[hybrid-stamped]'));
assert.equal(stamped.length, 0);
Polymer.dom(document.body).appendChild(wrapper);
CustomElements.takeRecords();
hybridDomRepeat.render();
stamped = Array.from(document.querySelectorAll('[hybrid-stamped]'));
assert.equal(stamped.length, 3);
stamped.forEach(function(el) {
stamped.forEach(function(el, i) {
assert.equal(el.parentNode, document.body);
assert.equal(el.textContent, hybridDomRepeat.items[i].prop);
});
});

test('insertion works correctly', function() {
hybridDomRepeat.splice('items', 1, 0, {prop: 'new'});
hybridDomRepeat.render();
var stamped = Array.from(document.querySelectorAll('[hybrid-stamped]'));
assert.equal(stamped.length, 4);
stamped.forEach(function(el, i) {
assert.equal(el.parentNode, document.body);
assert.equal(el.textContent, hybridDomRepeat.items[i].prop);
});
});

Expand Down

0 comments on commit 2722532

Please sign in to comment.