ansu5555 / pdf-viewer-reactjs

A simple PDF viewer for React js
https://ansu5555.github.io/pdf-viewer-reactjs/
MIT License
139 stars 64 forks source link

Error: Cannot use the same canvas during multiple render() version@2.2.3 #111

Open jawed7siddiqui opened 1 year ago

jawed7siddiqui commented 1 year ago

pdf-viewer-reactjs.js:192 Error occured while rendering ! version@2.2.3 Error: Cannot use the same canvas during multiple render() operations. Use different canvas or ensure previous operations were cancelled or completed. at InternalRenderTask.initializeGraphics (pdf.js:3480:1) Screenshot from 2023-01-08 21-56-29 Screenshot from 2023-01-08 22-57-24

nikhilnaik5 commented 1 year ago

I am facing the same issue for the example URL. Even the local pdf is giving the error. It renders for a millisecond and the the error pops up

jalombro commented 1 year ago

Any updates to this? I'm also experiencing the same problem

XxQuickSilverZz commented 1 year ago

use


{contractPdf && (
            <div className="column has-text-centered" id="base64">
              <PDFViewer
                document={doc}
                scale={1.5}
              />
            </div>
          )}

add a condition to avoid re-render

SubramonianInian commented 11 months ago

The issue can also arise if the strict mode is enabled as the component will render twice.

vinayak-trivedi commented 6 months ago

@jawed7siddiqui @jalombro @nikhilnaik5, not sure if you have figured a solution for this, but for me adding key solves the issue, adding example code as well here

<PDFViewer
    key={pdfFile}
    document={{
      url: pdfFile,
    }}
 />

Notes: this issue will still be there in dev mode because it renders twice