Skip to content

Commit 44a9fa0

Browse files
committed
fix(ComponentChildMixin): this.nearestOfType() is not reliable in willDestroyElement hook
Fixes emberjs-addons#99
2 parents 00bfde3 + 47ec98a commit 44a9fa0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

addon/mixins/component-child.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@ export default Ember.Mixin.create({
1414
let parent = this.nearestOfType(ComponentParentMixin);
1515
if (parent) {
1616
parent.registerChild(this);
17+
this.set('_parent', parent);
1718
}
1819
}),
1920

21+
// stores the parent in didInsertElement hook as a work-a-round for
22+
// https://github.com/emberjs/ember.js/issues/12080
23+
_parent: null,
24+
2025
_willDestroyElement: Ember.on('willDestroyElement', function() {
21-
let parent = this.nearestOfType(ComponentParentMixin);
26+
let parent = this.nearestOfType(ComponentParentMixin) || this.get('_parent');
2227
if (parent) {
2328
parent.removeChild(this);
2429
}

0 commit comments

Comments
 (0)