Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throwing AbortException when unmounting react-pdf components before PDF is finished rendering #651

Closed
taylorbf opened this issue Sep 18, 2020 · 26 comments
Labels
bug Something isn't working

Comments

@taylorbf
Copy link

What are you trying to achieve? Please describe.

I'd like to be able to unmount my PDF viewer component before the PDF is finished rendering, without having an unhandled promise exception.

Describe solutions you've tried

I have tried using the available onRenderError, onLoadError, etc props. I've also tried wrapping the component in an ErrorBoundary, however it does not catch this error.

Additional information

This is an unhandled promise exception from within PDF.js. I wonder if this exception could be handled within your library or if a prop could be exposed to handle this error. I imagine others have come across this error and I wonder how others have solved this.

When unmounting the <Document> and <Page> before it is finished rendering:

Uncaught (in promise) pdf.js:1153 
AbortException: {
  message: "Worker was terminated."
  name: "AbortException"
}

Using this worker: 'react-pdf/dist/esm/entry.webpack.js'

Environment

  • Browser Chrome 85:
  • React-PDF version 5.0.0:
  • React version 16.10.2:
  • Webpack version 4.41.0:
@dmanaster
Copy link

Did you ever figure out how to handle this? I am getting the same error.

@taylorbf
Copy link
Author

I did not fix it. What I did, for a variety of reasons, was show the PDF one page at a time and I do not show the 'close' controls until the page is loaded.

@Darono87
Copy link

Darono87 commented Nov 5, 2020

Have the same issue. Very annoying if you have some quite big pdf-s. Unhandled exception basically crashes the app so it's quite an issue when you want to implement some navigation :)

@wojtekmaj wojtekmaj added bug Something isn't working help wanted Extra attention is needed labels Nov 5, 2020
@kevinmamaqi
Copy link

I receive this error when I am opening several pages in a modal, for example, and I close it before all are loaded. Is there any way to lazyload on scroll?

@voidrender
Copy link

voidrender commented Dec 13, 2020

Has anyone come up with a non-blocking solution or workaround for this?

Edit: looks like this only happens in development mode for me. I don't have a crash on the app in production.

@LinusGeffarth
Copy link

LinusGeffarth commented Jan 5, 2021

Same issue here. No fix yet?
Also not happening in production for me though.

@landorid
Copy link

landorid commented Jan 7, 2021

I have the same issue too.

@AmmarMohamadIsmaeel
Copy link

I did not find a solution for the problem, but luckily the crash is happening in the development mode only and not in the production :)

@zxlin
Copy link

zxlin commented Feb 21, 2021

@TugboatTanner
Copy link

TugboatTanner commented May 5, 2021

Still getting this error React PDF version 5.2.0. It's also happening in production for me.

@sokoloveugene
Copy link

I was able to skip this problem in react-pdf v5.2.0

Try the next steps.

  • copy file from node_modules/pdfjs-dist/build/pdf.worker.js to public/pdf.worker.js
  • import { Document, Page } from 'react-pdf';
  • I did not set any options to "Document" component.

Check chrome dev tools/task manages. It should use worker from the public folder.

Here is a tutorial I found for react-pdf v4.1.0.
https://levelup.gitconnected.com/displaying-pdf-in-react-app-6e9d1fffa1a9

@TugboatTanner
Copy link

I was able to skip this problem in react-pdf v5.2.0

Try the next steps.

  • copy file from node_modules/pdfjs-dist/build/pdf.worker.js to public/pdf.worker.js
  • import { Document, Page } from 'react-pdf';
  • I did not set any options to "Document" component.

Check chrome dev tools/task manages. It should use worker from the public folder.

Here is a tutorial I found for react-pdf v4.1.0.
https://levelup.gitconnected.com/displaying-pdf-in-react-app-6e9d1fffa1a9

I'll try this out. Thank you @sokoloveugene!

@zxlin
Copy link

zxlin commented May 7, 2021

🤔 Not seeing the same results here. On react-pdf 5.2.0, if you navigate away from a PDF mid load on slow internet, it'll still throw the following error. No special options, using vanilla sample code

Screen Shot 2021-05-07 at 2 51 10 PM

@TugboatTanner
Copy link

@zxlin Yeah, it didn't seem to fix my issue either. I did try installing the v5.3.beta.3 version and it seems it's fixed there. At this point I've resigned myself to waiting for 5.3 to be released to fix this

@zxlin
Copy link

zxlin commented May 7, 2021

Oh that's promising to hear about v5.3! thanks for the update!

@wojtekmaj
Copy link
Owner

v5.3.0 is now released. Glad to know it helped!

@wojtekmaj wojtekmaj removed the help wanted Extra attention is needed label May 8, 2021
@renaoliv
Copy link

🤔 Not seeing the same results here. On react-pdf 5.2.0, if you navigate away from a PDF mid load on slow internet, it'll still throw the following error. No special options, using vanilla sample code

Screen Shot 2021-05-07 at 2 51 10 PM

I'm getting the same error, using the 5.3.0 version...
does anyone have the solution?

@goodlana
Copy link

If there is anyone still suffered from this issue, just change the import-alias.
I'm using v5.7.3, and it doesn't seem like they solved this issue...
below code saved my life. hope it helps you 😄

import { Document, Page } from "react-pdf/dist/esm/entry.webpack";

from #729

@angel-langdon
Copy link

@goodlana solution did not work for me. It only worked when launching the app with yarn start. However, when I served the static files of build folder with my FastAPI backend PDF were unable to load

@nicolasiscoding
Copy link

Sorry for the bump but is there any known solutions to this? Seems as if the issue is stale and have a newer build then what is referenced here. It does not appear to be caught in the onLoadError.

image

image

image

image

@codeWriter6
Copy link

See the same error using v5.7.2, any solution how to resolve?

@lagroms
Copy link

lagroms commented Feb 24, 2023

I also have the same problem on 5.7.2

@mammadmammadli
Copy link

Having the same issue on v6.2.2

@frontendphil
Copy link

frontendphil commented Sep 28, 2023

We started seeing this in 7.4.0 when running our tests. It almost seems like something is faster now, which causes this to kick in. It definitively has something to do with our tests giving the Document a shit URL to load. This fails for obvious reasons, but IMO should not bring the whole test suite down.

@chomamateusz
Copy link

Same issue on 7.6.0

@AlfredMadere
Copy link

same issue on v9, why is this closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests