Skip to content

Commit 1657ab3

Browse files
danilsomsikovDevtools-frontend LUCI CQ
authored andcommitted
Fixed the Event Listener Leak in styles panel
Every time the Styles panel rebuilt a CSS section, `StylePropertyTreeElement` would attach a new `LOCAL_VALUE_UPDATED` listener to the `SDK.CSSProperty`. Because these listeners were never removed, they accumulated. A single style update would eventually trigger thousands of `updateTitle()` calls, causing a CPU spike. Explicitly saving the bound listener to a private property (`#onPropertyLocalValueUpdated`) in `StylePropertyTreeElement` and leverage the `TreeElement` framework's native `onunbind()` lifecycle method to properly remove this listener when the element is detached. Bug: 487901682 Change-Id: I7bb7c3e338109497df072333294d10386324892d Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7658087 Auto-Submit: Danil Somsikov <dsv@chromium.org> Reviewed-by: Philip Pfaffe <pfaffe@chromium.org> Commit-Queue: Danil Somsikov <dsv@chromium.org>
1 parent c842e97 commit 1657ab3

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

front_end/panels/elements/StylePropertyTreeElement.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,9 +2066,12 @@ export class StylePropertyTreeElement extends UI.TreeOutline.TreeElement {
20662066
this.listItemElement.textContent = '';
20672067
}
20682068

2069-
this.property.addEventListener(SDK.CSSProperty.Events.LOCAL_VALUE_UPDATED, () => {
2070-
this.updateTitle();
2071-
});
2069+
this.property.addEventListener(SDK.CSSProperty.Events.LOCAL_VALUE_UPDATED, this.updateTitle, this);
2070+
}
2071+
2072+
override onunbind(): void {
2073+
this.property.removeEventListener(SDK.CSSProperty.Events.LOCAL_VALUE_UPDATED, this.updateTitle, this);
2074+
super.onunbind();
20722075
}
20732076

20742077
async gridNames(): Promise<Set<string>> {

0 commit comments

Comments
 (0)