Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
fix tabs destroyed if switched away during first webview attach
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
petemill committed May 9, 2018
1 parent 14aa7e0 commit 01b1014
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions app/renderer/pooledWebviewDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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()
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
})
}

Expand Down

0 comments on commit 01b1014

Please sign in to comment.