Skip to content

Commit

Permalink
Merge pull request #7 from jackiotyu/patch-1
Browse files Browse the repository at this point in the history
fix: Slot nodes are not cleaned up after component destruction.
  • Loading branch information
Mechazawa authored May 26, 2024
2 parents 6bb4ea5 + 9642992 commit 1261924
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Teleport.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export default {
disabled(value) {
if (value) {
this.disable();
this.teardownObserver();
// Ensure all event done.
this.$nextTick(() => {
this.teardownObserver();
});
} else {
this.bootObserver();
this.move();
Expand All @@ -51,6 +54,9 @@ export default {
this.maybeMove();
},
beforeDestroy() {
// Fix nodes reference
this.nodes = this.getComponentChildrenNode();
// Move back
this.disable();
Expand Down Expand Up @@ -145,7 +151,9 @@ export default {
this.childObserver = new MutationObserver(mutations => {
const childChangeRecord = mutations.find(i => i.target === this.$el);
if (childChangeRecord) {
this.nodes = Array.from(this.$el.childNodes);
// Remove old nodes before update position.
this.nodes.forEach((node) => node.parentNode && node.parentNode.removeChild(node));
this.nodes = this.getComponentChildrenNode();
this.maybeMove();
}
});
Expand All @@ -167,6 +175,11 @@ export default {
this.childObserver = null;
}
},
getComponentChildrenNode() {
return this.$vnode.componentOptions.children
.map((i) => i.elm)
.filter((i) => i);
},
},
};
</script>
Expand Down

0 comments on commit 1261924

Please sign in to comment.