From fda98dce84a5865dfda0bcc60069d80f061689e5 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 18 May 2022 18:38:36 +0200 Subject: [PATCH] Work-around when closing a closing dialog See https://www.woltlab.com/community/thread/295669-uidialog-cannot-read-properties-of-undefined-reading-closable/ --- ts/WoltLabSuite/Core/Ui/Dialog.ts | 7 ++++++- wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ts/WoltLabSuite/Core/Ui/Dialog.ts b/ts/WoltLabSuite/Core/Ui/Dialog.ts index 384a723fc3..4ee1a088e6 100644 --- a/ts/WoltLabSuite/Core/Ui/Dialog.ts +++ b/ts/WoltLabSuite/Core/Ui/Dialog.ts @@ -738,7 +738,12 @@ const UiDialog = { _close(event: MouseEvent): boolean { event.preventDefault(); - const data = _dialogs.get(_activeDialog!) as DialogData; + const data = _dialogs.get(_activeDialog!); + if (data === undefined) { + // Closing the dialog while it is already being closed + // could cause the dialog data to be already discarded. + return true; + } // The current dialog might be unclosable, but another open, but closable, // dialog could have spawned this event listener. diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js index 8474b12fd3..33c240dbcd 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js @@ -609,6 +609,11 @@ define(["require", "exports", "tslib", "../Core", "../Dom/Change/Listener", "./S _close(event) { event.preventDefault(); const data = _dialogs.get(_activeDialog); + if (data === undefined) { + // Closing the dialog while it is already being closed + // could cause the dialog data to be already discarded. + return true; + } // The current dialog might be unclosable, but another open, but closable, // dialog could have spawned this event listener. if (!data.closable) { -- 2.20.1