From aa75b3ebda6597d38af8f48e595b69be71c415c3 Mon Sep 17 00:00:00 2001 From: PJ Date: Mon, 22 Jun 2026 13:29:30 -0400 Subject: [PATCH] fix(preview): destroy pdf.js document on recompile The preview created a new PDF document on every recompile but never destroyed the old one, leaking the document and its worker transport. Keep the loading task and destroy it on effect cleanup. Claude-Session: https://claude.ai/code/session_01RzTWrLiy4zGuw2hZSQGamk --- src/components/PdfPreview.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/PdfPreview.tsx b/src/components/PdfPreview.tsx index 52a1b35..e98f1ad 100644 --- a/src/components/PdfPreview.tsx +++ b/src/components/PdfPreview.tsx @@ -12,10 +12,11 @@ export function PdfPreview({ data }: { data: Uint8Array }) { const container = ref.current; if (!container) return; let cancelled = false; + const loadingTask = pdfjs.getDocument({ data: data.slice() }); (async () => { try { - const doc = await pdfjs.getDocument({ data: data.slice() }).promise; + const doc = await loadingTask.promise; if (cancelled) return; const width = container.clientWidth; const dpr = window.devicePixelRatio || 1; @@ -47,6 +48,7 @@ export function PdfPreview({ data }: { data: Uint8Array }) { return () => { cancelled = true; + loadingTask.destroy(); }; }, [data]);