Throttle PDF.js resize listener (#16402)

GitOrigin-RevId: 5c1498d21197b09865930e1b2deff049022d2d17
This commit is contained in:
Alf Eaton 2024-01-08 12:08:00 +00:00 committed by Copybot
parent fc8892e4fb
commit a50ca25f3a

View file

@ -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)