Skip to content

Commit

Permalink
fix(icon): verify the icon loads in the lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
thetaPC committed Sep 11, 2023
1 parent 1b7e8aa commit 371c58f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/components/icon/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class Icon {
private io?: IntersectionObserver;
private iconName: string | null = null;
private inheritedAttributes: { [k: string]: any } = {};
private didLoadIcon = false;

@Element() el!: HTMLElement;

Expand Down Expand Up @@ -94,6 +95,12 @@ export class Icon {
});
}

componentDidLoad() {
if (!this.didLoadIcon) {
this.loadIcon();
}
}

disconnectedCallback() {
if (this.io) {
this.io.disconnect();
Expand Down Expand Up @@ -138,6 +145,7 @@ export class Icon {
// async if it hasn't been loaded
getSvgContent(url, this.sanitize).then(() => (this.svgContent = ioniconContent.get(url)));
}
this.didLoadIcon = true;
}
}

Expand Down

0 comments on commit 371c58f

Please sign in to comment.