From 8d375357780a3bcf5e73222e5e801b0659ca2c17 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 11 Dec 2023 17:33:01 +0100 Subject: [PATCH] Fix the overlay container being stuck in dialogs The `MutationObserver` is an async process that does not reliably fire when a property is mutated repeatedly within a short time. See https://www.woltlab.com/community/thread/303449-url-einem-bild-zuweisen-erst-nach-speichern-m%C3%B6glich/ See https://www.woltlab.com/community/thread/303397-men%C3%BC-zur-bildpositionierung-%C3%B6ffnet-sich-nicht-nach-dem-einf%C3%BCgen/ --- ts/WoltLabSuite/Core/Ui/Dialog.ts | 20 +++++++----------- .../files/js/WoltLabSuite/Core/Ui/Dialog.js | 21 ++++++++----------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/ts/WoltLabSuite/Core/Ui/Dialog.ts b/ts/WoltLabSuite/Core/Ui/Dialog.ts index c65f04ac59..760f72e6eb 100644 --- a/ts/WoltLabSuite/Core/Ui/Dialog.ts +++ b/ts/WoltLabSuite/Core/Ui/Dialog.ts @@ -62,25 +62,21 @@ const UiDialog = { { passive: false }, ); - const observer = new MutationObserver((mutations) => { + let containsPageOverlay = false; + const observer = new MutationObserver(() => { const currentValue = _container.getAttribute("aria-hidden"); - for (const mutation of mutations) { - if (mutation.oldValue === currentValue) { - continue; - } - - if (currentValue === "false") { - adoptPageOverlayContainer(_container); - } else { - releasePageOverlayContainer(_container); - } + if (currentValue === "true") { + releasePageOverlayContainer(_container); + containsPageOverlay = false; + } else if (!containsPageOverlay) { + adoptPageOverlayContainer(_container); + containsPageOverlay = true; } }); observer.observe(_container, { attributes: true, attributeFilter: ["aria-hidden"], - attributeOldValue: true, }); document.getElementById("content")!.appendChild(_container); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js index 3125c9817f..bd0ec196d4 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js @@ -44,24 +44,21 @@ define(["require", "exports", "tslib", "../Core", "../Dom/Change/Listener", "./S event.preventDefault(); } }, { passive: false }); - const observer = new MutationObserver((mutations) => { + let containsPageOverlay = false; + const observer = new MutationObserver(() => { const currentValue = _container.getAttribute("aria-hidden"); - for (const mutation of mutations) { - if (mutation.oldValue === currentValue) { - continue; - } - if (currentValue === "false") { - (0, PageOverlay_1.adoptPageOverlayContainer)(_container); - } - else { - (0, PageOverlay_1.releasePageOverlayContainer)(_container); - } + if (currentValue === "true") { + (0, PageOverlay_1.releasePageOverlayContainer)(_container); + containsPageOverlay = false; + } + else if (!containsPageOverlay) { + (0, PageOverlay_1.adoptPageOverlayContainer)(_container); + containsPageOverlay = true; } }); observer.observe(_container, { attributes: true, attributeFilter: ["aria-hidden"], - attributeOldValue: true, }); document.getElementById("content").appendChild(_container); _keyupListener = (event) => { -- 2.20.1