Skip to content

Commit

Permalink
Avoid calling detached before an element is readied. When an elemen…
Browse files Browse the repository at this point in the history
…t is readied, if attachment is pending only call `attached` if the element is actually attached.

Note, this means that an element that is attached + detached before `ready` will not fire any attach/detach callback; however, this is a very corner case and previously in this case these callbacks were called out of order.
  • Loading branch information
Steven Orvell committed May 22, 2017
1 parent b967c5e commit 4e0abe4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
9 changes: 1 addition & 8 deletions src/mini/ready.html
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,6 @@
this._attachedPending = false;
this.attachedCallback();
}
// only call detached if the element is actually detached
if (this._detachedPending && !Polymer.dom(document.body).deepContains(this)) {
this._attachedPending = false;
this.detachedCallback();
}
},

// for system overriding
Expand Down Expand Up @@ -196,12 +191,10 @@
if (this._readied) {
baseDetachedCallback.call(this);
} else {
this._detachedPending = true;
this._attachedPending = false;
}
}



});

})();
Expand Down
8 changes: 4 additions & 4 deletions test/unit/element-disable-upgrade.html
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,16 @@
el.removeAttribute('disable-upgrade');
assert.ok(el._wasAttached);
});
test('detached does not fire when element is not yet enabled', function() {
test('attached/detached do not fire when element is not yet enabled', function() {
el.parentNode.removeChild(el);
Polymer.dom.flush();
assert.notOk(el._wasAttached);
assert.notOk(el._wasDetached);
el.removeAttribute('disable-upgrade');
assert.ok(el._wasAttached);
assert.ok(el._wasDetached);
assert.notOk(el._wasAttached);
assert.notOk(el._wasDetached);
});
test('detached does not fire when element is detached/attached when not yet enabled', function() {
test('attached/detached do not fire when element is detached/attached when not yet enabled', function() {
var parent = el.parentNode;
parent.removeChild(el);
Polymer.dom.flush();
Expand Down

0 comments on commit 4e0abe4

Please sign in to comment.