diegomura / diegomura/react-pdf
Interference between multiple pdf renders when using usePDF
- Dominant language
- TypeScript
- Stars
- 16.8k
- Forks
- 1.3k
- Avg merge
- 5h 6m
- Merged PRs (30d)
- 52
Description
**Describe the bug**
When using usePDF, and triggering another render on other place of the app, it makes usePDF rerender and regenerate the PDF again.
My guess is that the problem is here:
https://github.com/diegomura/react-pdf/blob/a37d927f54d7f367416788979e4b5a8248532952/packages/renderer/src/index.js#L19-L25
The on change listeners always are called, even for renders of other documents, that triggers the queueDocumentRender. Causing an unnecessary pdf rerender.
https://github.com/diegomura/react-pdf/blob/a37d927f54d7f367416788979e4b5a8248532952/packages/renderer/src/dom/usePDF.js#L22-L28
Maybe the onChange listeners should be scoped by its pdf instance to avoid this.
**To Reproduce**
Steps to reproduce the behavior including code snippet (if applies):
1. Create a component that displays a pdf with BlobProvider or usePDF
3. Create a button and use the onClick to generate a pdf directly with the `pdf` API
4. See how the component regenerates the PDF
**Expected behavior**
The generation of another unrelated document should not make the usePDF to rerender.
**Desktop (please complete the following information):**
- OS: Windows and MacOS
- Browser: Chrome
- React-pdf version @react-pdf/renderer@3.1.12
Contributor guide
Assessment
This issue has not been assessed yet.