feat: drop the stream dependency from browser builds - #1766
Merged
Conversation
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
blikblum
approved these changes
Aug 16, 2026
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 :) |
Member
|
Of course |
Collaborator
Author
|
Thanks! I don't think I have rights to do so? Or never did in the past |
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.
Closes #1765, option 1.
streamwas the last Node builtin left in the browser bundle. It now goes through a#streamcondition, like#fsand#zlib.Node still gets
stream.Readable, so nothing changes there.The browser gets
lib/stream/browser.js, about 100 lines. It doeson,once,off,emit,push,pipeand async iteration, and nothing else.pipewaits for the destination'sdrain. Chunks pushed before you attach a listener are replayed on a microtask, soon('data')pluson('end')still works.LineWrapperhad a copy of the same event emitter, so both now uselib/event_emitter.js.read(),setEncoding(),destroy()and thereadable/error/closeevents 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())andfor awaiteach produce a valid PDF. New tests intests/unit/stream.spec.js.