Skip to content

Commit 2487d8a

Browse files
fix(ledger): cancel stale deferred preference writes
1 parent 5bb75f3 commit 2487d8a

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

engraphis/dashboard_assets/ledger.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,20 +2524,31 @@
25242524

25252525

25262526
let graphPreferencesSaveScheduled = false;
2527+
let graphPreferencesSaveCancel = null;
25272528
function scheduleGraphPreferencesSave() {
25282529
if (graphPreferencesSaveScheduled) return;
25292530
graphPreferencesSaveScheduled = true;
25302531
const flush = () => {
2532+
if (!graphPreferencesSaveScheduled) return;
25312533
graphPreferencesSaveScheduled = false;
2534+
graphPreferencesSaveCancel = null;
25322535
saveGraphPreferences();
25332536
};
2534-
if (typeof requestAnimationFrame === 'function') requestAnimationFrame(flush);
2535-
else setTimeout(flush, 0);
2537+
if (typeof requestAnimationFrame === 'function') {
2538+
const frame = requestAnimationFrame(flush);
2539+
graphPreferencesSaveCancel = () => cancelAnimationFrame(frame);
2540+
} else {
2541+
const timer = setTimeout(flush, 0);
2542+
graphPreferencesSaveCancel = () => clearTimeout(timer);
2543+
}
25362544
}
25372545

25382546
function flushGraphPreferencesSave() {
25392547
if (!graphPreferencesSaveScheduled) return;
25402548
graphPreferencesSaveScheduled = false;
2549+
const cancel = graphPreferencesSaveCancel;
2550+
graphPreferencesSaveCancel = null;
2551+
if (cancel) cancel();
25412552
saveGraphPreferences();
25422553
}
25432554

0 commit comments

Comments
 (0)