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:
parent
53cc39ae2d
commit
c39021d1bc
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue