Skip to content

Commit 344ca2d

Browse files
committed
fix: remove document event listener leaks in view components
Add disconnectedCallback to CalltreeView, AnalysisView, DMLView, and SOQLView to remove find event listeners registered on document. Extract CalltreeView's inline calltree-go-to-row handler to a named field so it can be properly removed. Restore the isTableVisible guard in DMLView to prevent searching against hidden tables when switching views.
1 parent 8c325c0 commit 344ca2d

4 files changed

Lines changed: 38 additions & 4 deletions

File tree

log-viewer/src/features/analysis/components/AnalysisView.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ export class AnalysisView extends LitElement {
126126
document.addEventListener('lv-find-close', this._findEvt);
127127
}
128128

129+
disconnectedCallback(): void {
130+
super.disconnectedCallback();
131+
document.removeEventListener('lv-find', this._findEvt);
132+
document.removeEventListener('lv-find-match', this._findEvt);
133+
document.removeEventListener('lv-find-close', this._findEvt);
134+
}
135+
129136
updated(changedProperties: PropertyValues): void {
130137
if (
131138
this.timelineRoot &&

log-viewer/src/features/call-tree/components/CalltreeView.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,27 @@ export class CalltreeView extends LitElement {
8080
return (this.tableContainer = this.renderRoot?.querySelector('#call-tree-table') ?? null);
8181
}
8282

83+
private _goToRowEvt = ((e: CustomEvent) => {
84+
this._goToRow(e.detail.timestamp);
85+
}) as EventListener;
86+
8387
constructor() {
8488
super();
8589

86-
document.addEventListener('calltree-go-to-row', ((e: CustomEvent) => {
87-
this._goToRow(e.detail.timestamp);
88-
}) as EventListener);
89-
90+
document.addEventListener('calltree-go-to-row', this._goToRowEvt);
9091
document.addEventListener('lv-find', this._findEvt);
9192
document.addEventListener('lv-find-match', this._findEvt);
9293
document.addEventListener('lv-find-close', this._findEvt);
9394
}
9495

96+
disconnectedCallback(): void {
97+
super.disconnectedCallback();
98+
document.removeEventListener('calltree-go-to-row', this._goToRowEvt);
99+
document.removeEventListener('lv-find', this._findEvt);
100+
document.removeEventListener('lv-find-match', this._findEvt);
101+
document.removeEventListener('lv-find-close', this._findEvt);
102+
}
103+
95104
updated(changedProperties: PropertyValues): void {
96105
if (
97106
this.timelineRoot &&

log-viewer/src/features/database/components/DMLView.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ export class DMLView extends LitElement {
7272
document.addEventListener('lv-find-match', this._findEvt);
7373
}
7474

75+
disconnectedCallback(): void {
76+
super.disconnectedCallback();
77+
document.removeEventListener('lv-find', this._findEvt);
78+
document.removeEventListener('lv-find-close', this._findEvt);
79+
document.removeEventListener('lv-find-match', this._findEvt);
80+
}
81+
7582
updated(changedProperties: PropertyValues): void {
7683
if (
7784
this.timelineRoot &&
@@ -226,6 +233,10 @@ export class DMLView extends LitElement {
226233
}
227234

228235
const newFindArgs = JSON.parse(JSON.stringify(e.detail));
236+
if (!isTableVisible) {
237+
newFindArgs.text = '';
238+
}
239+
229240
const newSearch =
230241
newFindArgs.text !== this.findArgs.text ||
231242
newFindArgs.options.matchCase !== this.findArgs.options?.matchCase;

log-viewer/src/features/database/components/SOQLView.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ export class SOQLView extends LitElement {
8383
document.addEventListener('lv-find-match', this._findEvt);
8484
}
8585

86+
disconnectedCallback(): void {
87+
super.disconnectedCallback();
88+
document.removeEventListener('lv-find', this._findEvt);
89+
document.removeEventListener('lv-find-close', this._findEvt);
90+
document.removeEventListener('lv-find-match', this._findEvt);
91+
}
92+
8693
updated(changedProperties: PropertyValues): void {
8794
if (
8895
this.timelineRoot &&

0 commit comments

Comments
 (0)