Skip to content

feat: drop the stream dependency from browser builds - #1766

Merged
blikblum merged 1 commit into
masterfrom
diegomura/pdfkit-1765-solution-1
Aug 16, 2026
Merged

feat: drop the stream dependency from browser builds#1766
blikblum merged 1 commit into
masterfrom
diegomura/pdfkit-1765-solution-1

Conversation

@diegomura

@diegomura diegomura commented Aug 16, 2026

Copy link
Copy Markdown
Collaborator

Closes #1765, option 1.

stream was the last Node builtin left in the browser bundle. It now goes through a #stream condition, like #fs and #zlib.

Node still gets stream.Readable, so nothing changes there.

The browser gets lib/stream/browser.js, about 100 lines. It does on, once, off, emit, push, pipe and async iteration, and nothing else. pipe waits for the destination's drain. Chunks pushed before you attach a listener are replayed on a microtask, so on('data') plus on('end') still works.

LineWrapper had a copy of the same event emitter, so both now use lib/event_emitter.js.

read(), setEncoding(), destroy() and the readable/error/close events are Node only. The guide says so.

blob-stream is still a Writable, so the browser recipe in the docs pulls a shim back in. That's #1345, I can do it separately.

Tests, lint and prettier pass. The browser bundle imports no Node builtin. I built it and checked that on('data'), pipe(fs.createWriteStream()) and for await each produce a valid PDF. New tests in tests/unit/stream.spec.js.

Resolve `stream` through a `#stream` condition, the same way `#fs` and
`#zlib` already work. Node keeps `stream.Readable` with its full surface;
browsers get a minimal readable implementing what a PDF document actually
needs: `on`/`once`/`off`/`emit`, `push`, `pipe` honouring the destination's
`drain`, and async iteration.

`LineWrapper` had its own event emitter inline, so it moves to the shared
one rather than a second copy.

The browser bundle no longer imports any Node builtin.

Closes #1765
@diegomura diegomura self-assigned this Aug 16, 2026
@diegomura diegomura changed the title Drop the stream dependency from browser builds feat: drop the stream dependency from browser builds Aug 16, 2026
@blikblum
blikblum merged commit ee1841b into master Aug 16, 2026
3 checks passed
@blikblum
blikblum deleted the diegomura/pdfkit-1765-solution-1 branch August 16, 2026 19:10
@diegomura

Copy link
Copy Markdown
Collaborator Author

Thanks @blikblum ! Any chance we can do a release with all the latest changes? Id like to see if I can remove my fork on react-pdf side already :)

@blikblum

Copy link
Copy Markdown
Member

Of course

@diegomura

Copy link
Copy Markdown
Collaborator Author

Thanks! I don't think I have rights to do so? Or never did in the past

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.

Node's stream is the last builtin left in the browser build

2 participants