diff --git a/web/src/elements/controllers/ModalOrchestrationController.ts b/web/src/elements/controllers/ModalOrchestrationController.ts index 3119ee95cb..2892caaebf 100644 --- a/web/src/elements/controllers/ModalOrchestrationController.ts +++ b/web/src/elements/controllers/ModalOrchestrationController.ts @@ -94,22 +94,25 @@ export class ModalOrchestrationController implements ReactiveController { } removeTopmostModal() { - let checking = true; - while (checking) { - const modal = this.knownModals.pop(); + const knownModals = [...this.knownModals]; + // Pop off modals until you find the first live one, schedule it to be closed, and make that + // cleaned list the current state. Since this is our *only* state object, this has the + // effect of creating a new "knownModals" collection with some semantics. + // eslint-disable-next-line no-constant-condition + while (true) { + const modal = knownModals.pop(); if (!modal) { break; } if (!modalIsLive(modal)) { continue; } - if (modal.closeModal() !== false) { this.scheduleCleanup(modal); } - checking = false; break; } + this.knownModals = knownModals; } @bound