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:
@@ -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);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { enhance } from '$app/forms';
|
||||
import { onMount, untrack } from 'svelte';
|
||||
import { onMount, onDestroy, untrack } from 'svelte';
|
||||
import { m } from '$lib/paraglide/messages.js';
|
||||
import DocumentViewer from '$lib/components/DocumentViewer.svelte';
|
||||
import WhoWhenSection from '$lib/components/document/WhoWhenSection.svelte';
|
||||
@@ -34,6 +34,7 @@ $effect(() => {
|
||||
async function loadFile(id: string) {
|
||||
isLoading = true;
|
||||
fileError = '';
|
||||
if (fileUrl) URL.revokeObjectURL(fileUrl);
|
||||
fileUrl = '';
|
||||
try {
|
||||
const response = await fetch(`/api/documents/${id}/file`);
|
||||
@@ -47,6 +48,10 @@ async function loadFile(id: string) {
|
||||
}
|
||||
}
|
||||
|
||||
onDestroy(() => {
|
||||
if (fileUrl) URL.revokeObjectURL(fileUrl);
|
||||
});
|
||||
|
||||
// Form state
|
||||
let tags = $state(untrack(() => doc.tags?.map((t: { name: string }) => t.name) ?? []));
|
||||
let senderId = $state(untrack(() => doc.sender?.id ?? ''));
|
||||
|
||||
Reference in New Issue
Block a user