From 232c434254536d3b5331d7c3c94d7c0069379f6b Mon Sep 17 00:00:00 2001 From: Paul Derscheid Date: Thu, 12 Feb 2026 09:52:37 +0100 Subject: [PATCH] Bug 40896: (follow-up) Fix bfcache double-toggle on form button elements - Track pending reset timeouts in a WeakMap keyed by element - Clear any pending timeout in the pageshow handler before re-enabling - Prevents the resumed setTimeout from re-disabling the button after bfcache restoration Signed-off-by: Brendan Lawlor --- koha-tmpl/intranet-tmpl/prog/js/throttledButton.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/throttledButton.js b/koha-tmpl/intranet-tmpl/prog/js/throttledButton.js index fe6b411b72..9ad563f647 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/throttledButton.js +++ b/koha-tmpl/intranet-tmpl/prog/js/throttledButton.js @@ -1,5 +1,6 @@ (() => { const DEFAULT_TIMEOUT = 3000; + const pendingTimeouts = new WeakMap(); const toggleButton = element => { const isDisabled = element.hasAttribute("disabled"); @@ -53,7 +54,11 @@ requestAnimationFrame(() => { toggleButton(submitter); - setTimeout(() => toggleButton(submitter), timeout); + const timeoutId = setTimeout( + () => toggleButton(submitter), + timeout + ); + pendingTimeouts.set(submitter, timeoutId); }); } }); @@ -64,6 +69,11 @@ document .querySelectorAll("[data-throttled-button][disabled]") .forEach(button => { + const timeoutId = pendingTimeouts.get(button); + if (timeoutId) { + clearTimeout(timeoutId); + pendingTimeouts.delete(button); + } toggleButton(button); }); } -- 2.39.5