fix: crash due to race between attach and destruction of webview (#24344)

This commit is contained in:
Robo 2021-08-02 08:35:57 -07:00 committed by GitHub
parent 0cabff0a21
commit 2b897c8ad8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 41 deletions

View file

@ -115,9 +115,11 @@ export class WebViewImpl {
}
createGuest () {
this.hooks.guestViewInternal.createGuest(this.buildParams()).then(guestInstanceId => {
this.attachGuestInstance(guestInstanceId);
});
this.internalInstanceId = getNextId();
this.hooks.guestViewInternal.createGuest(this.internalElement, this.internalInstanceId, this.buildParams())
.then(guestInstanceId => {
this.attachGuestInstance(guestInstanceId);
});
}
dispatchEvent (eventName: string, props: Record<string, any> = {}) {
@ -192,20 +194,19 @@ export class WebViewImpl {
}
attachGuestInstance (guestInstanceId: number) {
if (!this.elementAttached) {
// The element could be detached before we got response from browser.
if (guestInstanceId === -1) {
// Do nothing
return;
}
this.internalInstanceId = getNextId();
if (!this.elementAttached) {
// The element could be detached before we got response from browser.
// Destroy the backing webContents to avoid any zombie nodes in the frame tree.
this.hooks.guestViewInternal.detachGuest(guestInstanceId);
return;
}
this.guestInstanceId = guestInstanceId;
this.hooks.guestViewInternal.attachGuest(
this.internalElement,
this.internalInstanceId,
this.guestInstanceId,
this.buildParams()
);
// TODO(zcbenz): Should we deprecate the "resize" event? Wait, it is not
// even documented.
this.resizeObserver = new ResizeObserver(this.onElementResize.bind(this));