Skip to content

Commit 1261924

Browse files
authored
Merge pull request #7 from jackiotyu/patch-1
fix: Slot nodes are not cleaned up after component destruction.
2 parents 6bb4ea5 + 9642992 commit 1261924

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/Teleport.vue

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ export default {
3232
disabled(value) {
3333
if (value) {
3434
this.disable();
35-
this.teardownObserver();
35+
// Ensure all event done.
36+
this.$nextTick(() => {
37+
this.teardownObserver();
38+
});
3639
} else {
3740
this.bootObserver();
3841
this.move();
@@ -51,6 +54,9 @@ export default {
5154
this.maybeMove();
5255
},
5356
beforeDestroy() {
57+
// Fix nodes reference
58+
this.nodes = this.getComponentChildrenNode();
59+
5460
// Move back
5561
this.disable();
5662
@@ -145,7 +151,9 @@ export default {
145151
this.childObserver = new MutationObserver(mutations => {
146152
const childChangeRecord = mutations.find(i => i.target === this.$el);
147153
if (childChangeRecord) {
148-
this.nodes = Array.from(this.$el.childNodes);
154+
// Remove old nodes before update position.
155+
this.nodes.forEach((node) => node.parentNode && node.parentNode.removeChild(node));
156+
this.nodes = this.getComponentChildrenNode();
149157
this.maybeMove();
150158
}
151159
});
@@ -167,6 +175,11 @@ export default {
167175
this.childObserver = null;
168176
}
169177
},
178+
getComponentChildrenNode() {
179+
return this.$vnode.componentOptions.children
180+
.map((i) => i.elm)
181+
.filter((i) => i);
182+
},
170183
},
171184
};
172185
</script>

0 commit comments

Comments
 (0)