react-pdf-js icon indicating copy to clipboard operation
react-pdf-js copied to clipboard

Two news

Open newsiberian opened this issue 3 years ago • 0 comments

Hi, @mikecousins, @ksocha, there are two news: first there are lots of changes for this year in pdf-js and we almost don't need custom pdfjs-dist since original has partly typings support out of the box.

And I found a huge bug for cases when you have number of pdfs at page or user have to move from page to page w/ a lot of pdfs. We don't do a clean up and don't terminate dedicated worker after pdf will be unmounded. Luckily it could be fixed easily:

...
const documentLoadingTask = useRef<any/*pdfjs.PDFDocumentLoadingTask*/ | null>(null);
...

useEffect(() => () => {
    // we must call `PDFDocumentLoadingTask.destroy` method to clean-up after a document, since otherwise some resources
    // may not be removed as intended
    if (documentLoadingTask.current) {
      documentLoadingTask.current.destroy()
    }
  }, [])

...

documentLoadingTask.current = pdfjs.getDocument(config)
documentLoadingTask.current.promise.then(
....

Cheers

newsiberian avatar Dec 08 '20 05:12 newsiberian