Skip to content

stream: fix Writable.toWeb() desiredSize for non-object-mode#62986

Open
mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:fix-writable-toweb-desiredsize
Open

stream: fix Writable.toWeb() desiredSize for non-object-mode#62986
mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:fix-writable-toweb-desiredsize

Conversation

@mcollina
Copy link
Copy Markdown
Member

Writable.toWeb() used a plain { highWaterMark } as the queuing strategy for non-object-mode streams, which meant no size function was provided. The WritableStream defaulted to counting each chunk as size 1, so desiredSize was incorrect (e.g. a 3-byte Uint8Array was counted as size 1 instead of 3).

Add a size() function to the strategy that mirrors how the Node.js stream computes chunk length: byteLength for typed arrays, length for strings/buffers, falling back to 1.

Fixes: #56269

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. web streams labels Apr 27, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.32%. Comparing base (74ccf38) to head (088b5e2).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62986      +/-   ##
==========================================
- Coverage   90.32%   90.32%   -0.01%     
==========================================
  Files         730      730              
  Lines      234209   234157      -52     
  Branches    43934    43906      -28     
==========================================
- Hits       211558   211508      -50     
- Misses      14372    14378       +6     
+ Partials     8279     8271       -8     
Files with missing lines Coverage Δ
lib/internal/webstreams/adapters.js 86.62% <100.00%> (+0.06%) ⬆️

... and 35 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Renegade334
Copy link
Copy Markdown
Member

Add a size() function to the strategy that mirrors how the Node.js stream computes chunk length: byteLength for typed arrays, length for strings/buffers, falling back to 1.

Technically, I think the Node.js side deals exclusively in .length, not that it should make a difference to the outcome.

Writable.toWeb() used a plain { highWaterMark } as the queuing
strategy for non-object-mode streams, which meant no size function
was provided. The WritableStream defaulted to counting each chunk
as size 1, so desiredSize was incorrect (e.g., a 3-byte Uint8Array
was counted as size 1 instead of 3).

Add a size() function to the strategy that mirrors how the Node.js
stream computes chunk length: byteLength for typed arrays, length
for strings/buffers, falling back to 1.

Fixes: nodejs#56269
Signed-off-by: Matteo Collina <hello@matteocollina.com>
@mcollina mcollina force-pushed the fix-writable-toweb-desiredsize branch from 33b3fe0 to 088b5e2 Compare May 24, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. web streams

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The desiredSize of Writable.toWeb() is incorrect

3 participants