mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-02 11:07:04 +00:00
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
This commit is contained in:
1 parent
4e5ea6d855
commit
aa75b3ebda
1 file changed
+3
-1
@@ -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]);
|
||||
|
||||
|
||||
Reference in new issue
Block a user