Skip to content

Commit

Permalink
fix(chip): disconnect mutation observer when component is disconnecte…
Browse files Browse the repository at this point in the history
…d from the DOM (#7418)

**Related Issue:** #7417 

## Summary

✨🧹✨
  • Loading branch information
jcfranco authored Aug 2, 2023
1 parent 217324f commit 412e5fb
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions packages/calcite-components/src/components/chip/chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class Chip
connectInteractive(this);
connectLocalized(this);
connectMessages(this);
this.setupTextContentObserver();
this.mutationObserver?.observe(this.el, { childList: true, subtree: true });
}

componentDidLoad(): void {
Expand All @@ -220,6 +220,7 @@ export class Chip
disconnectInteractive(this);
disconnectLocalized(this);
disconnectMessages(this);
this.mutationObserver?.disconnect();
}

async componentWillLoad(): Promise<void> {
Expand Down Expand Up @@ -302,10 +303,6 @@ export class Chip
this.hasText = this.el.textContent.trim().length > 0;
}

private setupTextContentObserver() {
this.mutationObserver?.observe(this.el, { childList: true, subtree: true });
}

private handleSlotImageChange = (event: Event): void => {
this.hasImage = slotChangeHasAssignedElement(event);
};
Expand Down

0 comments on commit 412e5fb

Please sign in to comment.