Files
ServerKit/frontend/src/utils/singleFlight.js
T
Juan Denis b156e2dce1 Keep the 2FA setup modal open until cancelled
Overlay click and Escape closed the setup modal and dropped the user
onto the Change password form. Add a Modal closeOnDismiss prop (default
unchanged) and use it for the setup modal; Cancel and the header X still
close it.

Guard Enable with a ref-based single-flight lock in both the settings
tab and the setup wizard so a double-click cannot fire two requests, and
show a hint after a failed confirm that the code may belong to an older
QR. Add the string to every locale.
2026-11-26 02:38:47 -05:00

16 lines
463 B
JavaScript

// Drops a call while a previous one is still running. Backed by a plain
// object (hold it in a useRef) so a double-click is refused synchronously,
// before React has flushed any `disabled` state.
export function createSingleFlight() {
let busy = false;
return async function run(fn) {
if (busy) return undefined;
busy = true;
try {
return await fn();
} finally {
busy = false;
}
};
}