Skip to content

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

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

stream: fix Writable.toWeb() desiredSize for non-object-mode#62986
mcollina wants to merge 1 commit intonodejs: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

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
@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 89.66%. Comparing base (c3dd52a) to head (33b3fe0).
⚠️ Report is 103 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62986      +/-   ##
==========================================
+ Coverage   89.61%   89.66%   +0.04%     
==========================================
  Files         706      707       +1     
  Lines      219136   219506     +370     
  Branches    41981    42077      +96     
==========================================
+ Hits       196376   196815     +439     
+ Misses      14671    14604      -67     
+ Partials     8089     8087       -2     
Files with missing lines Coverage Δ
lib/internal/webstreams/adapters.js 86.66% <100.00%> (+0.05%) ⬆️

... and 74 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.

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