diff --git a/.changeset/perfect-rockets-approve.md b/.changeset/perfect-rockets-approve.md new file mode 100644 index 0000000000..86f50db398 --- /dev/null +++ b/.changeset/perfect-rockets-approve.md @@ -0,0 +1,5 @@ +--- +"@patternfly/elements": patch +--- + +``: prevent memory leak by removing event listeners event on popover close diff --git a/elements/pf-popover/pf-popover.ts b/elements/pf-popover/pf-popover.ts index f47048c550..d1f3ad5ba8 100644 --- a/elements/pf-popover/pf-popover.ts +++ b/elements/pf-popover/pf-popover.ts @@ -321,7 +321,6 @@ export class PfPopover extends LitElement { connectedCallback() { super.connectedCallback(); this.addEventListener('keydown', this.onKeydown); - PfPopover.instances.add(this); } render() { @@ -454,6 +453,7 @@ export class PfPopover extends LitElement { }); this._popover?.show(); this.dispatchEvent(new PopoverShownEvent()); + PfPopover.instances.add(this); } /** @@ -464,6 +464,7 @@ export class PfPopover extends LitElement { await this.#float.hide(); this._popover?.close(); this.dispatchEvent(new PopoverHiddenEvent()); + PfPopover.instances.delete(this); } }