feat(pdf): add a pdfmake-based PDF toolkit - #317
Open
gcutrini wants to merge 1 commit into
Open
Conversation
Add a React-agnostic PDF toolkit under src/utils/pdf so PDF generation does
not depend on @react-pdf/renderer, which breaks on React 19. pdfmake has no
reconciler, so the same code runs on React 16/17 and 19.
- createDocument({ pdfMake, font, template, data }) runs a pure
(data, { font }) => docDefinition template and returns
download/open/print/getBlob/getBase64 (all promise-based, per pdfmake 0.3).
- resolveFont fetches a URL font and base64-embeds it (pdfmake cannot load
fonts by URL in the browser), falling back to Helvetica.
- imageDataUrl base64s an image for the same reason.
- downloadBlob saves through a light-DOM anchor so a widget inside a shadow
root keeps the download filename.
- field and badge are shared node builders: a label/value pair and an SVG
badge with a CSS-like radius.
pdfmake is declared as an optional peer dependency: the toolkit only receives
a pdfMake instance and never imports pdfmake, so consumers that do not use
the toolkit need not install it.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ref: https://app.clickup.com/t/86bbf0d90
Adds
src/utils/pdf— a React-agnostic PDF toolkit on pdfmake (createDocument,resolveFont,imageDataUrl,downloadBlob,field,badge).pdfmakeis an optional peer; the toolkit never imports it, the consumer injects one instance.Why: react-pdf renders through react-reconciler. React 19 commits the reconciler container asynchronously, but react-pdf reads
container.document.propssynchronously right afterupdateContainer— so under React 19 it reads null and throws (Cannot read properties of null (reading 'props'), upstream diegomura/react-pdf#3223); under React 17/18 the commit was synchronous and never raced. Our stack spans React 17/18 (legacy widgets) and React 19 (the Next event site), so PDF generation broke on React 19. pdfmake has no reconciler, so it sidesteps this entirely.