From ce2163da2f716839a00c0a8eb09f8831d3ead8fd Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Fri, 27 Sep 2024 14:46:22 -0400 Subject: [PATCH] fix: remove resize listener when BrowserWindow closed (#44000) Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr --- lib/browser/api/browser-view.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/browser/api/browser-view.ts b/lib/browser/api/browser-view.ts index ed6670d4574d..dc6b3818e783 100644 --- a/lib/browser/api/browser-view.ts +++ b/lib/browser/api/browser-view.ts @@ -68,10 +68,7 @@ export default class BrowserView { // a webContents can be closed by the user while the BrowserView // remains alive and attached to a BrowserWindow. set ownerWindow (w: BrowserWindow | null) { - if (this.#ownerWindow && this.#resizeListener) { - this.#ownerWindow.off('resize', this.#resizeListener); - this.#resizeListener = null; - } + this.#removeResizeListener(); if (this.webContents && !this.webContents.isDestroyed()) { this.webContents._setOwnerWindow(w); @@ -82,6 +79,7 @@ export default class BrowserView { this.#lastWindowSize = w.getBounds(); w.on('resize', this.#resizeListener = this.#autoResize.bind(this)); w.on('closed', () => { + this.#removeResizeListener(); this.#ownerWindow = null; this.#destroyListener = null; }); @@ -94,6 +92,13 @@ export default class BrowserView { this.#ownerWindow?.contentView.removeChildView(this.webContentsView); } + #removeResizeListener () { + if (this.#ownerWindow && this.#resizeListener) { + this.#ownerWindow.off('resize', this.#resizeListener); + this.#resizeListener = null; + } + } + #autoHorizontalProportion: {width: number, left: number} | null = null; #autoVerticalProportion: {height: number, top: number} | null = null; #autoResize () {