From 0bd234ddf62e824d114c56d111a188ba82018a7e Mon Sep 17 00:00:00 2001 From: Arjun <6592213+arkml@users.noreply.github.com> Date: Mon, 4 May 2026 17:28:04 +0530 Subject: [PATCH] fix browser reload issue --- apps/x/apps/main/src/browser/view.ts | 35 ++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/apps/x/apps/main/src/browser/view.ts b/apps/x/apps/main/src/browser/view.ts index d319c5fb..b540809d 100644 --- a/apps/x/apps/main/src/browser/view.ts +++ b/apps/x/apps/main/src/browser/view.ts @@ -109,10 +109,31 @@ export class BrowserViewManager extends EventEmitter { private visible = false; private bounds: BrowserBounds = { x: 0, y: 0, width: 0, height: 0 }; private snapshotCache = new Map(); + private cleanupWindowListeners: (() => void) | null = null; attach(window: BrowserWindow): void { + this.cleanupWindowListeners?.(); this.window = window; - window.on('closed', () => { + + const resetForHostWindowNavigation = () => { + // Renderer refreshes do not run React unmount cleanup reliably, so the + // native browser view must be detached from the main process side. + this.visible = false; + this.bounds = { x: 0, y: 0, width: 0, height: 0 }; + this.syncAttachedView(); + }; + + const handleDidStartLoading = () => { + resetForHostWindowNavigation(); + }; + + const handleRenderProcessGone = () => { + resetForHostWindowNavigation(); + }; + + const handleClosed = () => { + this.cleanupWindowListeners?.(); + this.cleanupWindowListeners = null; this.window = null; this.browserSession = null; this.tabs.clear(); @@ -121,7 +142,17 @@ export class BrowserViewManager extends EventEmitter { this.attachedTabId = null; this.visible = false; this.snapshotCache.clear(); - }); + }; + + window.webContents.on('did-start-loading', handleDidStartLoading); + window.webContents.on('render-process-gone', handleRenderProcessGone); + window.on('closed', handleClosed); + + this.cleanupWindowListeners = () => { + window.webContents.removeListener('did-start-loading', handleDidStartLoading); + window.webContents.removeListener('render-process-gone', handleRenderProcessGone); + window.removeListener('closed', handleClosed); + }; } private getSession(): Session {