From 450d2b4e65c88eb7f78eb14838c08505f6936ac8 Mon Sep 17 00:00:00 2001 From: petemill Date: Wed, 11 Apr 2018 00:12:54 -0700 Subject: [PATCH] fix tabs destroyed if switched away during first webview attach Fix #13798 since "display: none" and then "display: ''" of a webview will cause the guest to (asynchronously) detach and attach again, and by that time we had attached another guest, which causes the original tab to be destroyed since we are attaching a guest to a webview which already has a guest. Luckily, it doesn't look like this workaround is needed in order to paint the first attachGuest of a webview anymore. --- app/renderer/pooledWebviewDisplay.js | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/app/renderer/pooledWebviewDisplay.js b/app/renderer/pooledWebviewDisplay.js index d0bedf2aed1..4511448677f 100644 --- a/app/renderer/pooledWebviewDisplay.js +++ b/app/renderer/pooledWebviewDisplay.js @@ -8,16 +8,6 @@ const debounce = require('../../js/lib/debounce') let i = 0 -function ensurePaintWebviewFirstAttach (webview, cb = () => {}) { - window.requestAnimationFrame(() => { - webview.style.display = 'none' - window.requestAnimationFrame(() => { - webview.style.display = '' - window.requestAnimationFrame(cb) - }) - }) -} - function ensurePaintWebviewSubsequentAttach (webview, cb = () => {}) { webview.style.top = '1px' window.requestAnimationFrame(() => { @@ -165,7 +155,6 @@ module.exports = class WebviewDisplay { this.attachingToTabId = tabId const t0 = window.performance.now() - let timeoutHandleBumpView = null const fnEnd = () => { if (this.shouldLogEvents) { console.groupEnd() @@ -179,7 +168,7 @@ module.exports = class WebviewDisplay { // size has changed or forced to. if (!toAttachWebview.isSubsequentAttach) { toAttachWebview.isSubsequentAttach = true - ensurePaintWebviewFirstAttach(toAttachWebview, showAttachedView) + showAttachedView() } else { ensurePaintWebviewSubsequentAttach(toAttachWebview, showAttachedView) } @@ -290,7 +279,6 @@ module.exports = class WebviewDisplay { case 'will-destroy': case 'destroyed': // don't need to bump view - clearTimeout(timeoutHandleBumpView) remote.unregisterEvents(tabId, tabEventHandler) onDestroyedInsteadOfAttached() break @@ -302,7 +290,6 @@ module.exports = class WebviewDisplay { // we're done displaying if (!handled) { // don't need to bump view - clearTimeout(timeoutHandleBumpView) onToAttachDidAttach() handled = true } @@ -331,8 +318,6 @@ module.exports = class WebviewDisplay { // setImmediate is a bit of a hacky way to ensure that registerEvents handler is registered setImmediate(() => toAttachWebview.attachGuest(guestInstanceId, webContents)) this.debugLog(`swapWebviewOnAttach: Waiting.... ${window.performance.now() - t0}ms`) - // another workaround for not getting did-attach on webview, set a timeout and then hide / show view - timeoutHandleBumpView = window.setTimeout(ensurePaintWebviewFirstAttach.bind(null, toAttachWebview), 2000) }) }