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