From f759ca4573faa915230fe5f87d761a5074b3451e Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Fri, 14 Jun 2024 19:19:55 +0200
Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Force-display=20the=20preview=20?=
=?UTF-8?q?button=20after=20render()?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Some tests indicate, that the `ppcp-hidden` and `ppcp-enabled` events are not always triggered on some sites. As the preview button is refreshed during those events, it would stay hidden on those sites.
Adding a delayed DOM show() call solves the issue in a slightly less-elegant way.
---
.../resources/js/modules/Renderer/PreviewButton.js | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/modules/ppcp-button/resources/js/modules/Renderer/PreviewButton.js b/modules/ppcp-button/resources/js/modules/Renderer/PreviewButton.js
index 80184a322..f2b7f0b4c 100644
--- a/modules/ppcp-button/resources/js/modules/Renderer/PreviewButton.js
+++ b/modules/ppcp-button/resources/js/modules/Renderer/PreviewButton.js
@@ -129,6 +129,17 @@ class PreviewButton {
}
this.createButton(previewButtonConfig);
+
+ /*
+ * Unfortunately, a hacky way that is required to guarantee that this preview button is
+ * actually visible after calling the `render()` method. On some sites, we've noticed that
+ * certain JS events (like `ppcp-hidden`) do not fire in the expected order. This causes
+ * problems with preview buttons not being displayed instantly.
+ *
+ * Using a timeout here will make the button visible again at the end of the current
+ * event queue.
+ */
+ setTimeout(() => this.domWrapper.show());
}
remove() {