refactor(autosave): rename flushViaBeacon → flushOnUnload; add void to fire-and-forget fetch

The sendBeacon name was misleading after switching to keepalive fetch.
Also adds a test to confirm flush is a no-op when pendingTexts is empty.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-04-22 16:46:58 +02:00
committed by marcel
parent c9dd3f8e78
commit ff0bb89297
3 changed files with 21 additions and 9 deletions

View File

@@ -94,10 +94,10 @@ export function createBlockAutoSave({ saveFn, documentId }: Options) {
saveStates.delete(blockId);
}
function flushViaBeacon(): void {
function flushOnUnload(): void {
for (const [blockId, text] of pendingTexts) {
clearDebounce(blockId);
fetch(`/api/documents/${documentId}/transcription-blocks/${blockId}`, {
void fetch(`/api/documents/${documentId}/transcription-blocks/${blockId}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text }),
@@ -124,7 +124,7 @@ export function createBlockAutoSave({ saveFn, documentId }: Options) {
handleBlur,
handleRetry,
clearBlock,
flushViaBeacon,
flushOnUnload,
destroy
};
}