Transcription block saves silently lost when navigating away in production #204
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
TranscriptionEditView.svelteusesnavigator.sendBeacon()influshViaBeacon()(line 231-238) to flush pending transcription block edits onbeforeunload. The beacon sends a PUT request to/api/documents/${documentId}/transcription-blocks/${blockId}.This works in dev mode but silently fails in production.
Impact
Users lose unsaved transcription text when navigating away or closing the tab. No error is shown -- the data is silently dropped.
Root Cause
The app has two different
/apirouting paths depending on the environment:Dev mode (works): Vite's dev server proxy (
vite.config.ts:16-33) intercepts all/apirequests -- includingsendBeacon-- and forwards them to Spring Boot, injecting theAuthorizationheader from theauth_tokencookie.Production (broken): SvelteKit serves the app. Client-side
fetch()calls to/api/...are intercepted by SvelteKit'shandleFetchhook (hooks.server.ts:63-101), which reads theauth_tokencookie and adds theAuthorizationheader before proxying to the backend. However,navigator.sendBeacon()is a raw browser API -- it does not go through SvelteKit'shandleFetchhook. It sends the request directly to the SvelteKit server as a regular HTTP request. Since there is no+server.tsroute matching/api/documents/[id]/transcription-blocks/[blockId], SvelteKit returns a 404.The existing API route files confirm the gap -- only these proxy routes exist:
frontend/src/routes/api/documents/[id]/file/+server.tsfrontend/src/routes/api/persons/+server.tsfrontend/src/routes/api/tags/+server.tsThere is no
+server.tsfor transcription-blocks.Relevant Files
frontend/src/lib/components/TranscriptionEditView.svelte:231-238--flushViaBeacon()frontend/src/hooks.server.ts:63-101--handleFetch(only applies to SvelteKit-managed fetch)frontend/vite.config.ts:16-33-- Vite dev proxy (masks the bug in dev)frontend/src/routes/documents/[id]/+page.svelte:79-85-- regularsaveBlock()via fetch (works correctly)Reproduction Steps
npm run build && npm run preview)Proposed Fix
Add a SvelteKit API proxy route at
frontend/src/routes/api/documents/[id]/transcription-blocks/[blockId]/+server.tsthat forwards PUT requests to the backend with theAuthorizationheader, matching the pattern used by the existing proxy routes.Alternatively, consider whether all
/apipaths need a catch-all proxy route (frontend/src/routes/api/[...path]/+server.ts) to avoid this class of bug recurring for other client-side fetch or beacon calls.