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

Error handling - PDFJS worker termination while loading and unmounting component. #1062

Closed
4 tasks done
nicolasiscoding opened this issue Oct 8, 2022 · 21 comments · Fixed by #1877
Closed
4 tasks done
Labels
bug Something isn't working fresh help wanted Extra attention is needed

Comments

@nicolasiscoding
Copy link

Before you start - checklist

  • I followed instructions in documentation written for my React-PDF version
  • I have checked if this bug is not already reported
  • I have checked if an issue is not listed in Known issues
  • If I have a problem with PDF rendering, I checked if my PDF renders properly in PDF.js demo

Description

Sorry for the bump but is there any known solutions to this? This is referenced in this closed issue but 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.

#651

image

image

image

image

Steps to reproduce

  1. Throttle Network speed in browser
  2. Load a PDF
  3. Navigate to another page prior to the PDF completing forcing the component to unmount
  4. Get error in console

Expected behavior

Graceful error handling or the ability to do a try catch, or an abort controller equivalent.

Actual behavior

React is not happy

Additional information

I happen to be using Gatsby, but this should persist even in vanilla React environments

Environment

  • Browser (if applicable): Chrome Version 106.0.5249.103
  • React-PDF version: 5.7.2
  • React version: 16.14.0
  • Webpack version (if applicable): 5.74.0
@nicolasiscoding nicolasiscoding added the bug Something isn't working label Oct 8, 2022
@nicolasiscoding
Copy link
Author

And this appears to extend this: mozilla/pdf.js#11595

@catmans1
Copy link

catmans1 commented Nov 8, 2022

It might related to this issue: #729 (comment)

@github-actions
Copy link
Contributor

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 14 days.

@github-actions github-actions bot added the stale label Feb 13, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2023

This issue was closed because it has been stalled for 14 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 6, 2023
@nicolasiscoding
Copy link
Author

Bump?

@wojtekmaj wojtekmaj reopened this May 2, 2023
@wojtekmaj wojtekmaj added help wanted Extra attention is needed fresh and removed stale labels May 2, 2023
@nicolasiscoding
Copy link
Author

@wojtekmaj it seems that even if you use the onLoadError prop, pdf.js itself is still firing a error that propagates up. I can make a PR that suppresses these warnings using techniques discussed in the Mozilla thread. Is this something you think could get merged in (assuming good quality)?

@wojtekmaj
Copy link
Owner

Sounds fair! Especially since I was to believe that we are already suppressing these errors :D

Just please be aware that on main, currently, we have a completely new version so this fix would land in 7.x.

@nicolasiscoding
Copy link
Author

@wojtekmaj that's a good point. Let me verify the version when I'm back in front of this and report findings.

@IvanGerasin
Copy link

Got in the same issue. It appeared in unit tests (jest+RTL) after migrating from nodeJS v14 to nodeJS v16.
react-pdf: 5.7.2

@VigneshSonaiya
Copy link

HI @wojtekmaj , Still getting the same issue on version 7.3.3
image

@OrlandoHurtadoBMC

This comment was marked as spam.

@jiangxiaoqiang

This comment has been minimized.

@monscamus

This comment has been minimized.

@jiangxiaoqiang
Copy link

try to use the same version in whole project, I am using the different version pdf pdfjs seems trigger the issue(fisrt install pdfjs then install react-pdf but the react-pdf use old version of pdfjs).

@codewizard-dt
Copy link

This is still a real issue :( There is no way that I have found to NOT log this error. Very annoying.

@mauudev
Copy link

mauudev commented Dec 12, 2023

Hi, just passing by and dropping a potential solution. We need to import the worker by this way (specified in docs):

import { pdfjs } from 'react-pdf';

pdfjs.GlobalWorkerOptions.workerSrc = new URL(
  'pdfjs-dist/build/pdf.worker.min.js',
  import.meta.url,
).toString();

Worked for me, hope it helps.

@riancintiyo
Copy link

@mauudev Thanks for dropping the code. It's indeed worked for me too. 🍻

@AlfredMadere
Copy link

AlfredMadere commented Jun 21, 2024

@mauudev I don't think this is really a fix, i have confirmed that when you set the workerSrc using either method you get the error. I'm still getting this exact issue on v9.

Both of the following result in an AbortException when the component unmounts while loading. I can reliably reproduce this issue by throttling in dev tools.

The following two methods of loading the workerSrc both result in errors
1.

pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.mjs`
pdfjs.GlobalWorkerOptions.workerSrc = `/static/js/pdf.worker-${pdfjs.version}.mjs`

The resulting error:
Screenshot 2024-06-21 at 12 20 54 PM

@CyberAndrii
Copy link
Contributor

In case someone is looking for a workaround, mozilla/pdf.js#11595 (comment)

@nicolasiscoding
Copy link
Author

@CyberAndrii in the context of react, should this be added to a useEffect unmount?

@CyberAndrii
Copy link
Contributor

It needs to be added here

loadingTask.destroy();

But because it's not fixed in this package yet, we use patch-package to apply the fix.

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

Successfully merging a pull request may close this issue.