Просмотр исходного кода

Clear PDF file container element before rendering (#16028)

GitOrigin-RevId: acec635bc1bbd47bf76f6a15151fefc0831fa541
Alf Eaton 2 лет назад
Родитель
Сommit
2f45c8b90a

+ 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++) {