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 <blawlor@clamsnet.org>
Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Paul Derscheid 2026-02-12 09:52:37 +01:00 committed by Lucas Gass
parent 53cc39ae2d
commit c39021d1bc
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
1 changed files with 11 additions and 1 deletions

View File

@ -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);
});
}