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:
@@ -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
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user