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

Throttle PDF.js resize listener (#16402)

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

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

@@ -1,6 +1,6 @@
 import PropTypes from 'prop-types'
 import { memo, useCallback, useEffect, useRef, useState } from 'react'
-import { debounce } from 'lodash'
+import { debounce, throttle } from 'lodash'
 import PdfViewerControls from './pdf-viewer-controls'
 import { useProjectContext } from '../../../shared/context/project-context'
 import usePersistedState from '../../../shared/hooks/use-persisted-state'
@@ -359,9 +359,9 @@ function PdfJsViewer({ url, pdfFile }) {
   // adjust the scale when the container is resized
   useEffect(() => {
     if (pdfJsWrapper && 'ResizeObserver' in window) {
-      const resizeListener = () => {
+      const resizeListener = throttle(() => {
         pdfJsWrapper.updateOnResize()
-      }
+      }, 250)
 
       const resizeObserver = new ResizeObserver(resizeListener)
       resizeObserver.observe(pdfJsWrapper.container)