mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-02 19:17:03 +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;
|
const container = ref.current;
|
||||||
if (!container) return;
|
if (!container) return;
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
|
const loadingTask = pdfjs.getDocument({ data: data.slice() });
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const doc = await pdfjs.getDocument({ data: data.slice() }).promise;
|
const doc = await loadingTask.promise;
|
||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
const width = container.clientWidth;
|
const width = container.clientWidth;
|
||||||
const dpr = window.devicePixelRatio || 1;
|
const dpr = window.devicePixelRatio || 1;
|
||||||
@@ -47,6 +48,7 @@ export function PdfPreview({ data }: { data: Uint8Array }) {
|
|||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
|
loadingTask.destroy();
|
||||||
};
|
};
|
||||||
}, [data]);
|
}, [data]);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user