mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-07-13 22:37:14 +10:00
fix: typecheck
This commit is contained in:
@@ -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();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user