fix(fe): debounce mask auto-run 500ms after slider/sheet changes

Rapid sensitivity drags triggered a flood of async mask runs; an in-flight
run could settle after the owner pressed Approve and clobber the state, so
the Approve click read a snapshot with overlay:null and early-returned.
Debounce 500ms after the user stops adjusting so the mask settles before any
interaction and the click reads a stable state.
This commit is contained in:
2026-09-25 09:19:52 -07:00
parent 703655a763
commit 0bc86ecc6d
+9 -4
View File
@@ -71,12 +71,17 @@
let fileInput: HTMLInputElement;
// Auto-run the mask so the overlay (and preview) populate without the owner
// pressing Approve first. `controlKey` changes only on sheet/sensitivity
// edits (never on the overlay itself), so this fires on entry and on each
// control change - but not when approveMask settles the overlay (no loop).
// pressing Approve first. Debounced 500ms after the user stops adjusting the
// sheet/sensitivity, so rapid slider drags don't trigger a flood of async
// mask runs (and an in-flight run can't clobber the state around an Approve
// click). Keyed on control values, not the overlay, so settling never loops.
let maskRunTimer = 0;
$: controlKey = kind === 'mask' && cap.control ? `${cap.control.sheet}:${cap.control.sensitivity}` : null;
$: if (controlKey && cap.source && cap.source.widthPx > 0) {
void session.approveMask();
clearTimeout(maskRunTimer);
maskRunTimer = setTimeout(() => {
void session.approveMask();
}, 500);
}
function pickFiles(e: Event) {