mirror of
https://github.com/stablyai/orca.git
synced 2026-09-28 00:02:41 +00:00
fix: clean up PDF scale event listener (#2875)
This commit is contained in:
@@ -86,11 +86,12 @@ export default function PdfViewer({ content, filePath }: PdfViewerProps): JSX.El
|
||||
|
||||
linkService.setViewer(viewer)
|
||||
|
||||
eventBus.on('scalechanging', (evt: { scale: number }) => {
|
||||
const handleScaleChanging = (evt: { scale: number }): void => {
|
||||
if (!cancelled) {
|
||||
setScale(evt.scale)
|
||||
}
|
||||
})
|
||||
}
|
||||
eventBus.on('scalechanging', handleScaleChanging)
|
||||
|
||||
const loadingTask = pdfjsLib.getDocument({ data: bytes })
|
||||
|
||||
@@ -128,6 +129,9 @@ export default function PdfViewer({ content, filePath }: PdfViewerProps): JSX.El
|
||||
// renders, clears the find controller, and dispatches pagesdestroy.
|
||||
// The runtime accepts null but the types only declare PDFDocumentProxy.
|
||||
viewer.setDocument(null as unknown as pdfjsLib.PDFDocumentProxy)
|
||||
// Why: pdf.js EventBus retains callbacks by event name; unregister the
|
||||
// scale listener so repeated PDF opens do not retain stale component state.
|
||||
eventBus.off('scalechanging', handleScaleChanging)
|
||||
eventBusRef.current = null
|
||||
findControllerRef.current = null
|
||||
pdfViewerRef.current = null
|
||||
|
||||
Reference in New Issue
Block a user