fix: retain stale main frame for longer (#12225)

This commit is contained in:
Alex Rudenko 2024-04-08 11:24:54 +02:00 committed by GitHub
parent 2821970485
commit aa5b1824a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -21,6 +21,7 @@ export class FrameTree<FrameType extends Frame> {
// frameID -> childFrameIDs // frameID -> childFrameIDs
#childIds = new Map<string, Set<string>>(); #childIds = new Map<string, Set<string>>();
#mainFrame?: FrameType; #mainFrame?: FrameType;
#isMainFrameStale = false;
#waitRequests = new Map<string, Set<Deferred<FrameType>>>(); #waitRequests = new Map<string, Set<Deferred<FrameType>>>();
getMainFrame(): FrameType | undefined { getMainFrame(): FrameType | undefined {
@ -59,8 +60,9 @@ export class FrameTree<FrameType extends Frame> {
this.#childIds.set(frame._parentId, new Set()); this.#childIds.set(frame._parentId, new Set());
} }
this.#childIds.get(frame._parentId)!.add(frame._id); this.#childIds.get(frame._parentId)!.add(frame._id);
} else if (!this.#mainFrame) { } else if (!this.#mainFrame || this.#isMainFrameStale) {
this.#mainFrame = frame; this.#mainFrame = frame;
this.#isMainFrameStale = false;
} }
this.#waitRequests.get(frame._id)?.forEach(request => { this.#waitRequests.get(frame._id)?.forEach(request => {
return request.resolve(frame); return request.resolve(frame);
@ -73,7 +75,7 @@ export class FrameTree<FrameType extends Frame> {
if (frame._parentId) { if (frame._parentId) {
this.#childIds.get(frame._parentId)?.delete(frame._id); this.#childIds.get(frame._parentId)?.delete(frame._id);
} else { } else {
this.#mainFrame = undefined; this.#isMainFrameStale = true;
} }
} }