Fix event listener and observer leaks in cookie banner

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-04-17 11:22:31 +04:00
parent 11a63b5dec
commit bc766ae5c9
3 changed files with 11 additions and 7 deletions

View File

@@ -18,7 +18,7 @@ import { ProboElement } from "./base";
export class ProboCategory extends ProboElement {
get categoryName(): string {
return this.getAttribute("name") ?? "";
return this.getAttribute("name") ?? "Other";
}
get required(): boolean {

View File

@@ -53,6 +53,13 @@ export class ProboCookieBannerRoot extends ProboElement implements ProboRootElem
this.initClient();
}
disconnectedCallback(): void {
if (this._client) {
this._client.destroy();
this._client = null;
}
}
setState(state: ProboState): void {
const prev = this._state;
this._state = state;

View File

@@ -26,6 +26,9 @@ export class ProboPreferencePanel extends ProboElement {
private onStateChange = (e: Event): void => {
const { state } = (e as CustomEvent).detail;
this.hidden = state !== "panel";
if (state === "panel") {
(this.root as ProboCookieBannerRoot).resetDraft();
}
};
connectedCallback(): void {
@@ -34,12 +37,6 @@ export class ProboPreferencePanel extends ProboElement {
if (this.root) {
this.root.addEventListener("probo-state", this.onStateChange);
this.root.addEventListener("probo-state", (e: Event) => {
const { state } = (e as CustomEvent).detail;
if (state === "panel") {
(this.root as ProboCookieBannerRoot).resetDraft();
}
});
}
this.scheduleValidation(() => this.validate());