fix(fileloader): revoke blob URLs before re-assignment and on destroy

Calling loadFile a second time previously leaked the previous object URL.
Add URL.revokeObjectURL(fileUrl) before creating a new one and in
onDestroy so all URLs are freed. Revoke behavior will be covered by the
useFileLoader hook tests in the next commit.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-04-15 13:13:21 +02:00
parent 8be876492c
commit dbf7f0bc16
2 changed files with 12 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
<script lang="ts">
import { onMount } from 'svelte';
import { onMount, onDestroy } from 'svelte';
import { m } from '$lib/paraglide/messages.js';
import DocumentTopBar from '$lib/components/DocumentTopBar.svelte';
import DocumentViewer from '$lib/components/DocumentViewer.svelte';
@@ -31,6 +31,7 @@ $effect(() => {
async function loadFile(id: string) {
isLoading = true;
fileError = '';
if (fileUrl) URL.revokeObjectURL(fileUrl);
fileUrl = '';
try {
@@ -51,6 +52,10 @@ async function loadFile(id: string) {
}
}
onDestroy(() => {
if (fileUrl) URL.revokeObjectURL(fileUrl);
});
// ── Mode state ───────────────────────────────────────────────────────────────
let transcribeMode = $state(false);