fix(fileloader): use untrack to prevent infinite reload loop
loadFile() reads fileUrl synchronously before its first await. When called from a \$effect, Svelte tracks that read and re-runs the effect every time fileUrl changes — i.e. after every successful load — causing an infinite cycle of file fetches and PdfViewer remounts. Fix: wrap the fileUrl read in untrack() so callers never accidentally subscribe to fileUrl changes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit was merged in pull request #243.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { untrack } from 'svelte';
|
||||
|
||||
export function createFileLoader() {
|
||||
let fileUrl = $state('');
|
||||
let isLoading = $state(false);
|
||||
@@ -6,7 +8,11 @@ export function createFileLoader() {
|
||||
async function loadFile(url: string): Promise<void> {
|
||||
isLoading = true;
|
||||
fileError = '';
|
||||
if (fileUrl) URL.revokeObjectURL(fileUrl);
|
||||
// untrack prevents callers ($effect) from accidentally subscribing to fileUrl.
|
||||
// Without it, the calling effect would re-run every time fileUrl changes (i.e.
|
||||
// on every successful load), creating an infinite load loop.
|
||||
const prev = untrack(() => fileUrl);
|
||||
if (prev) URL.revokeObjectURL(prev);
|
||||
fileUrl = '';
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user