Skip to content

Commit 4e0abe4

Browse files
author
Steven Orvell
committed
Avoid calling detached before an element is readied. When an element 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.
1 parent b967c5e commit 4e0abe4

2 files changed

Lines changed: 5 additions & 12 deletions

File tree

src/mini/ready.html

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,6 @@
153153
this._attachedPending = false;
154154
this.attachedCallback();
155155
}
156-
// only call detached if the element is actually detached
157-
if (this._detachedPending && !Polymer.dom(document.body).deepContains(this)) {
158-
this._attachedPending = false;
159-
this.detachedCallback();
160-
}
161156
},
162157

163158
// for system overriding
@@ -196,12 +191,10 @@
196191
if (this._readied) {
197192
baseDetachedCallback.call(this);
198193
} else {
199-
this._detachedPending = true;
194+
this._attachedPending = false;
200195
}
201196
}
202197

203-
204-
205198
});
206199

207200
})();

test/unit/element-disable-upgrade.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,16 @@
181181
el.removeAttribute('disable-upgrade');
182182
assert.ok(el._wasAttached);
183183
});
184-
test('detached does not fire when element is not yet enabled', function() {
184+
test('attached/detached do not fire when element is not yet enabled', function() {
185185
el.parentNode.removeChild(el);
186186
Polymer.dom.flush();
187187
assert.notOk(el._wasAttached);
188188
assert.notOk(el._wasDetached);
189189
el.removeAttribute('disable-upgrade');
190-
assert.ok(el._wasAttached);
191-
assert.ok(el._wasDetached);
190+
assert.notOk(el._wasAttached);
191+
assert.notOk(el._wasDetached);
192192
});
193-
test('detached does not fire when element is detached/attached when not yet enabled', function() {
193+
test('attached/detached do not fire when element is detached/attached when not yet enabled', function() {
194194
var parent = el.parentNode;
195195
parent.removeChild(el);
196196
Polymer.dom.flush();

0 commit comments

Comments
 (0)