-
Notifications
You must be signed in to change notification settings - Fork 10
Enable usage of react-pdf inside a web worker #3
Conversation
Looks great, thanks for the patch! |
This is now published in |
Now that the content of our shim extension was merged in exogee-technology/vite-plugin-shim-react-pdf#3 we can safely remove our own shimming.
Now that the content of our shim extension was merged in exogee-technology/vite-plugin-shim-react-pdf#3 we can safely remove our own shimming.
Hello, I used your method to render my pdf in a web worker. |
@aclec I have also had problems similar to what you describe, with Firefox not supporting dynamic imports of web worker scripts correctly, while in Chromium it worked fine. For now, I solved them by using vite-plugin-worker and using the Additionally, I added Unfortunately, I am also using Comlink to simplify the boilerplate code for communication between main thread and worker, but that should be optional. This current setup works for me both during development and in a productive build, in Firefox, Chrome, Chromium, Edge and even Firefox mobile. Let me know if you need more explanations or if something is unclear. |
Thanks a lot for this shim! As I already mentioned in diegomura/react-pdf#1317, it has helped me to run react-pdf using vite, and even inside a Vue application.
In the meantime, we have started using web workers for rendering the PDFs for performance reasons. The approach from diegomura/react-pdf#464 has served as a basis there. However, I have had to add another shim, since in a web worker environment,
window
is not defined, but instead the global scope is calledself
.This PR adds the fix I found to this library, in the safest way I could find. It should only have any effect if the code is currently running inside a web worker. We are able to transparently switch our implementation between running on the main thread and running in the worker, and both variants work fine with this small addition.