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

Commit

Permalink
Don't schedule a second callback if one is already waiting on `did-at…
Browse files Browse the repository at this point in the history
…tach`

Although the error mentions `dom-ready`, there is actually a timing problem
with that event and the webContents is always set before `did-attach`
updated fix for #2037

auditors: @bbondy, @diracdeltas
  • Loading branch information
bridiver committed Jun 2, 2016
1 parent b1fd055 commit b27cc9d
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions js/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,15 @@ class Frame extends ImmutableComponent {
}

if (webviewAdded) {
let runOnDomReady = (e) => {
this.webview.removeEventListener(e.type, runOnDomReady)
cb && cb()
if (cb) {
this.runOnDomReady = cb
let eventCallback = (e) => {
this.webview.removeEventListener(e.type, eventCallback)
this.runOnDomReady()
delete this.runOnDomReady
}
this.webview.addEventListener('did-attach', eventCallback)
}
this.webview.addEventListener('did-attach', runOnDomReady)
this.addEventListeners()
this.webviewContainer.appendChild(this.webview)
} else {
Expand Down Expand Up @@ -225,11 +229,13 @@ class Frame extends ImmutableComponent {
if (this.shouldCreateWebview() || this.props.frame.get('src') !== prevProps.frame.get('src')) {
this.updateWebview(cb)
} else {
try {
if (this.runOnDomReady) {
// there is already a callback waiting for did-attach
// so replace it with this callback because it might be a
// mount callback which is a subset of the update callback
this.runOnDomReady = cb
} else {
cb()
} catch (e) {
// webview DOM may not be ready yet
this.webview.addEventListener('dom-ready', cb)
}
}
}
Expand Down

1 comment on commit b27cc9d

@diracdeltas
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

Please sign in to comment.