소스 검색

Clear PDF file container element before rendering (#16028)

GitOrigin-RevId: acec635bc1bbd47bf76f6a15151fefc0831fa541
Alf Eaton 2 년 전
부모
커밋
2f45c8b90a
1개의 변경된 파일과 8개의 추가작업 그리고 0개의 파일을 삭제
  1. 8 0
      services/web/frontend/js/features/file-view/components/file-view-pdf.tsx

+ 8 - 0
services/web/frontend/js/features/file-view/components/file-view-pdf.tsx

@@ -35,6 +35,14 @@ const FileViewPdf: FC<{
 
         const pdf = await PDFJS.getDocument(preview.url).promise
 
+        // bail out if loading the PDF took too long
+        if (!mountedRef.current) {
+          onError()
+          return
+        }
+
+        element.textContent = '' // ensure the element is empty
+
         const scale = window.devicePixelRatio || 1
 
         for (let i = 1; i <= pdf.numPages; i++) {