How are re-renders treated in react-pdf? Using and updating contexts seems to work, but only once.
#3221
Unanswered
michael-wegener-metro
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hello everyone,
I might have a rather uncommon issue, but maybe someone has faced something similar, or maybe someone understands the rendering pipeline a bit better than I do and can tell me what's going on here.
Using contexts with changing values while generating PDFs might not sound like the best idea, but I wanted to see how
react-pdfhandles it anyway. It worked surprisingly good, but as I later discovered, it only works once, which is something I can't quite figure out why.I created a small-ish example to explain what I'm trying to do:
Now, when I run this example with
ts-node generateDemoPdfs.tsx, the logs look exactly like I would expect them to look:The logs for both documents look exactly the same. It first renders the note list with an empty array, then two notes are added, and since the context changes, the note list is rendered for a second time with the notes that were added.
If the Footnotes were missing from both documents, I actually wouldn't be surprised, but the first document actually looks completely fine and only in the second document the footnotes are missing. I can render even more documents and the first one will always work fine and everything that comes after that is missing all the re-renders.
So basically the first
renderToBuffer(document)considers both render cycles and only only then writes the document, while the secondrenderToBuffer(document)only considers the first render cycle, so any re-renders that might be happening are disregarded.Did anyone every run into an issue with re-renders while generating PDFs? I guess re-renders are not a very common thing, so most people probably don't run into this issue, but maybe I'm lucky and somebody can help me with this.
All reactions