fix: crash due to race between attach and destruction of webview (#24344)
This commit is contained in:
parent
0cabff0a21
commit
2b897c8ad8
4 changed files with 36 additions and 41 deletions
|
@ -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));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue