Fix BrowserView cleanup on component unmount

- Separate BrowserView cleanup into dedicated useEffect with empty dependency array
- Ensures cleanup runs when WebViewer component is unmounted, not just on URL changes
- Add detailed logging for debugging BrowserView destruction
- Fixes issue where BrowserView persists after closing WebViewer container
- Proper cleanup prevents orphaned BrowserView instances floating on screen
This commit is contained in:
spencrmartin
2025-11-10 17:02:08 -05:00
parent eb29a5a88f
commit a714e4e436
+12 -4
View File
@@ -152,15 +152,23 @@ export function WebViewer({
}
}, 100);
// Cleanup on unmount
return () => {
clearTimeout(timer);
if (browserViewCreated && browserViewId.current) {
window.electron.destroyBrowserView(browserViewId.current).catch(console.error);
}
};
}, [url]);
// Cleanup BrowserView on component unmount
useEffect(() => {
return () => {
console.log('WebViewer component unmounting, cleaning up BrowserView:', browserViewId.current);
if (browserViewId.current) {
window.electron.destroyBrowserView(browserViewId.current).catch((err) => {
console.error('Error destroying BrowserView on unmount:', err);
});
}
};
}, []);
// Update BrowserView bounds when container resizes
useEffect(() => {
if (!browserViewCreated || !containerRef.current) return;