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

Revert "Wrap PDF setDocument in startViewTransition (#33346)" (#33580)

This reverts commit 353ab865de3c7872363a61592d86390dfc34dacc.

GitOrigin-RevId: dd103eb413a51861b31cd77542ca541e10df0c6c
Alf Eaton 5 месяцев назад
Родитель
Сommit
64d706f114

+ 0 - 3
services/web/frontend/js/features/pdf-preview/components/pdf-js-viewer.tsx

@@ -114,9 +114,6 @@ function PdfJsViewer({ url, pdfFile }: PdfJsViewerProps) {
     }
     }
 
 
     const handlePagesinit = () => {
     const handlePagesinit = () => {
-      // Set scale immediately to avoid a one-frame flash at PDF.js's default
-      // 1.333 scale (96/72 DPI) before the React restore effect can correct it.
-      pdfJsWrapper.viewer.currentScaleValue = scaleRef.current
       setInitialised(true)
       setInitialised(true)
       timePDFFetched = performance.now()
       timePDFFetched = performance.now()
       if (document.hidden) {
       if (document.hidden) {

+ 8 - 38
services/web/frontend/js/features/pdf-preview/util/pdf-js-wrapper.ts

@@ -86,36 +86,8 @@ export default class PDFJSWrapper {
         return
         return
       }
       }
 
 
-      // Hold the .pdfViewer element's height steady across the synchronous page-clear
-      // that setDocument() triggers, so the viewer doesn't visually collapse while the
-      // new pages are being initialised. The min-height is released on pagesinit.
-      const viewerEl = this.container.querySelector('.pdfViewer') as HTMLElement
-      const currentHeight = viewerEl.getBoundingClientRect().height
-      if (currentHeight > 0) {
-        viewerEl.style.minHeight = `${currentHeight}px`
-        const clearMinHeight = () => {
-          viewerEl.style.minHeight = ''
-          this.eventBus.off('pagesinit', clearMinHeight)
-        }
-        this.eventBus.on('pagesinit', clearMinHeight)
-      }
-
-      const container = this.container as typeof this.container & {
-        // supported since Chrome 147
-        startViewTransition?: (cb: () => void | Promise<void>) => unknown
-      }
-      if (
-        container.startViewTransition &&
-        typeof container.startViewTransition === 'function'
-      ) {
-        container.startViewTransition(() => {
-          this.viewer.setDocument(doc)
-          this.linkService.setDocument(doc)
-        })
-      } else {
-        this.viewer.setDocument(doc)
-        this.linkService.setDocument(doc)
-      }
+      this.viewer.setDocument(doc)
+      this.linkService.setDocument(doc)
 
 
       return doc
       return doc
     } catch (error: any) {
     } catch (error: any) {
@@ -234,16 +206,14 @@ export default class PDFJSWrapper {
       destArray,
       destArray,
     })
     })
 
 
-    // scrollPageIntoView aligns PDF content to the container top, ignoring the page margin.
-    // For a top-of-document position this leaves scrollTop = marginTop (margin hidden).
-    // Snap back to 0 so the margin is visible, but only when we are in that margin band —
-    // for any real mid-document scrollTop this condition is false and we leave it untouched.
+    // scroll the page left and down by an extra few pixels to account for the pdf.js viewer page border
     const pageIndex = this.viewer.currentPageNumber - 1
     const pageIndex = this.viewer.currentPageNumber - 1
     const pageView = this.viewer.getPageView(pageIndex)
     const pageView = this.viewer.getPageView(pageIndex)
-    const marginTop = parseFloat(getComputedStyle(pageView.div).marginTop)
-    if (this.viewer.container.scrollTop <= marginTop) {
-      this.viewer.container.scrollTop = 0
-    }
+    const offset = parseFloat(getComputedStyle(pageView.div).borderWidth)
+    this.viewer.container.scrollBy({
+      top: -offset,
+      left: -offset,
+    })
   }
   }
 
 
   isVisible() {
   isVisible() {

+ 0 - 14
services/web/frontend/stylesheets/pages/editor/pdf.scss

@@ -217,7 +217,6 @@
 
 
 .pdf-viewer {
 .pdf-viewer {
   isolation: isolate;
   isolation: isolate;
-  view-transition-name: pdf-viewer;
 
 
   iframe {
   iframe {
     width: 100%;
     width: 100%;
@@ -256,7 +255,6 @@
     }
     }
 
 
     .page {
     .page {
-      display: block; // prevent Overleaf's .loading class (display:inline-flex) from affecting PDF.js page state
       box-sizing: content-box;
       box-sizing: content-box;
       margin: var(--spacing-05) auto;
       margin: var(--spacing-05) auto;
       box-shadow:
       box-shadow:
@@ -264,13 +262,6 @@
         0 3px 14px 0 #23282f08,
         0 3px 14px 0 #23282f08,
         0 8px 10px 0 #23282f14;
         0 8px 10px 0 #23282f14;
       border: none;
       border: none;
-
-      // Overleaf has its own loading state UI; suppress the PDF.js page-level loading
-      // spinner so the loadingIcon/loading classes have no layout or visual effect.
-      /* stylelint-disable-next-line selector-class-pattern */
-      &.loadingIcon::after {
-        display: none;
-      }
     }
     }
 
 
     .pdfjs-viewer-inner {
     .pdfjs-viewer-inner {
@@ -325,11 +316,6 @@
   }
   }
 }
 }
 
 
-::view-transition-old(pdf-viewer),
-::view-transition-new(pdf-viewer) {
-  animation-duration: 0.25s;
-}
-
 .pdfjs-viewer-controls {
 .pdfjs-viewer-controls {
   display: flex;
   display: flex;
   align-items: center;
   align-items: center;