Skip to content

feat(pdfkit): use fflate instead of zlib in the browser build - #3485

Merged
diegomura merged 1 commit into
masterfrom
diegomura/apply-pdfkit-pr-1760
Aug 12, 2026
Merged

feat(pdfkit): use fflate instead of zlib in the browser build#3485
diegomura merged 1 commit into
masterfrom
diegomura/apply-pdfkit-pr-1760

Conversation

@diegomura

Copy link
Copy Markdown
Owner

Applies foliojs/pdfkit#1760 to our fork. The browser build no longer imports Node's zlib, so consumers don't need a bundler polyfill for it, and browserify-zlib and pako (plus their alias workarounds in the rollup config) are gone from the dependency tree.

Both deflateSync call sites now go through src/zlib.js, which picks fflate's zlibSync or native zlib off the BROWSER constant, so each bundle keeps only one compressor after tree-shaking — verified in the built output. fflate returns a plain Uint8Array, which the bundled Buffer polyfill's concat rejects, so the browser branch wraps it in Buffer.from; PDFDocument._write also takes upstream's instanceof Uint8Array check.

Tests: the existing PNG test now flips BROWSER with vi.stubGlobal instead of mocking the zlib module (which needed a vitest setup file defining BROWSER for the package). Full suite passes, and the browser bundle was checked end to end by rendering text plus an interlaced PNG.

🤖 Generated with Claude Code

Applies upstream pdfkit PR #1760. The browser build no longer imports
Node's zlib, so consumers don't need a bundler polyfill for it, and
browserify-zlib and pako are gone from the dependency tree.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5489b94

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@react-pdf/pdfkit Patch
@react-pdf/font Patch
@react-pdf/renderer Patch
@react-pdf/types Patch
@react-pdf/math Patch
@react-pdf/mermaid Patch
next-14 Patch
next-15 Patch
@react-pdf/vite-example Patch
@react-pdf/layout Patch
@react-pdf/render Patch
@react-pdf/stylesheet Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@diegomura
diegomura merged commit 105bdd2 into master Aug 12, 2026
14 checks passed
@diegomura
diegomura deleted the diegomura/apply-pdfkit-pr-1760 branch August 12, 2026 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant