fix: typecheck

This commit is contained in:
Amruth Pillai
2026-06-01 10:31:25 +02:00
parent 0df7f21130
commit a8c70d784c
10 changed files with 100 additions and 118 deletions
@@ -46,7 +46,6 @@ export function PdfCanvasDocument({ children, file, onLoadSuccess }: PdfCanvasDo
useEffect(() => {
let isCancelled = false;
let loadingTask: PDFDocumentLoadingTask | undefined;
let loadedDocument: PDFDocumentProxy | undefined;
const loadDocument = async () => {
setDocument(null);
@@ -59,9 +58,8 @@ export function PdfCanvasDocument({ children, file, onLoadSuccess }: PdfCanvasDo
const pdfDocument = await loadingTask.promise;
if (isCancelled) {
void pdfDocument.destroy();
void loadingTask.destroy();
} else {
loadedDocument = pdfDocument;
setDocument(pdfDocument);
onLoadSuccessRef.current(pdfDocument);
}
@@ -76,12 +74,7 @@ export function PdfCanvasDocument({ children, file, onLoadSuccess }: PdfCanvasDo
return () => {
isCancelled = true;
if (loadedDocument) {
void loadedDocument.destroy();
} else if (loadingTask) {
void loadingTask.destroy();
}
void loadingTask?.destroy();
};
}, [file]);
@@ -60,10 +60,6 @@ export const createPdfFirstPageImageUrl = async (file: Blob) => {
page.cleanup();
}
} finally {
if (pdfDocument) {
void pdfDocument.destroy();
} else {
void loadingTask.destroy();
}
void loadingTask.destroy();
}
};
@@ -10,7 +10,6 @@ const pdfjsMock = vi.hoisted(() => {
};
const pdfDocument = {
destroy: vi.fn(),
getPage: vi.fn(async () => page),
numPages: 1,
};
@@ -49,7 +48,6 @@ describe("PDF.js browser entrypoints", () => {
pdfjsMock.legacyModule.GlobalWorkerOptions.workerSrc = undefined;
pdfjsMock.legacyModule.getDocument.mockClear();
pdfjsMock.loadingTask.destroy.mockClear();
pdfjsMock.pdfDocument.destroy.mockClear();
pdfjsMock.pdfDocument.getPage.mockClear();
pdfjsMock.page.cleanup.mockClear();
pdfjsMock.page.getViewport.mockClear();
@@ -100,6 +98,6 @@ describe("PDF.js browser entrypoints", () => {
expect(pdfjsMock.page.render).toHaveBeenCalledWith(
expect.objectContaining({ annotationMode: 0, background: "white" }),
);
expect(pdfjsMock.pdfDocument.destroy).toHaveBeenCalledTimes(1);
expect(pdfjsMock.loadingTask.destroy).toHaveBeenCalledTimes(1);
});
});
@@ -6,7 +6,6 @@ import { sampleResumeData } from "@reactive-resume/schema/resume/sample";
const pdfViewerMock = vi.hoisted(() => {
const pdfDocument = {
destroy: vi.fn(),
numPages: 1,
};
@@ -93,7 +92,6 @@ beforeEach(() => {
pdfViewerMock.createResumePdfBlob.mockClear();
pdfViewerMock.getDocument.mockClear();
pdfViewerMock.loadingTask.destroy.mockClear();
pdfViewerMock.pdfDocument.destroy.mockClear();
});
describe("PdfViewer", () => {
@@ -113,7 +111,6 @@ describe("PdfViewer", () => {
expect(abortSignal?.aborted).toBe(true);
expect(viewer.setDocument).toHaveBeenCalledWith(null);
expect(pdfViewerMock.pdfDocument.destroy).toHaveBeenCalledTimes(1);
expect(pdfViewerMock.loadingTask.destroy).toHaveBeenCalledTimes(1);
});
});
@@ -168,7 +168,7 @@ export function PdfViewer({ className, data }: PdfViewerProps) {
const nextDocument = await loadingTask.promise;
if (isCancelled) {
void nextDocument.destroy();
void loadingTask.destroy();
} else {
pdfDocument = nextDocument;
const pdfViewerOptions = {
@@ -208,7 +208,6 @@ export function PdfViewer({ className, data }: PdfViewerProps) {
window.cancelAnimationFrame(animationFrameId);
resizeObserver?.disconnect();
if (pdfViewer) clearPdfViewerDocument(pdfViewer);
void pdfDocument?.destroy();
void loadingTask?.destroy();
viewer.replaceChildren();
};