Skip to content

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

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
mcollina:fix-writable-toweb-desiredsize
Jun 21, 2026
Merged

stream: fix Writable.toWeb() desiredSize for non-object-mode#62986
nodejs-github-bot merged 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-botnodejs-github-bot added needs-ci PRs that need a full CI run. web streams labels Apr 27, 2026
@codecov

codecovBot commented Apr 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.32%. Comparing base (74ccf38) to head (088b5e2).
⚠️ Report is 291 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 linesCoverage Δ
lib/internal/webstreams/adapters.js86.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
mcollinaforce-pushed the fix-writable-toweb-desiredsize branch from 33b3fe0 to 088b5e2CompareMay 24, 2026 12:45
@mcollinamcollina added the request-ci Add this label to start a Jenkins CI on a PR. label May 28, 2026
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 28, 2026
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@trivikrtrivikr added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jun 21, 2026
@trivikrtrivikr added the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 21, 2026
@nodejs-github-botnodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 21, 2026
@nodejs-github-bot
nodejs-github-bot merged commit ca406b2 into nodejs:mainJun 21, 2026
87 of 88 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in ca406b2

aduh95 pushed a commit that referenced this pull request Jun 22, 2026
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
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: #62986
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
aduh95 pushed a commit that referenced this pull request Jun 25, 2026
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
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: #62986
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
aduh95 pushed a commit that referenced this pull request Jul 21, 2026
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
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: #62986
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
aduh95 pushed a commit that referenced this pull request Jul 22, 2026
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
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: #62986
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
aduh95 pushed a commit that referenced this pull request Jul 30, 2026
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
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: #62986
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.needs-ciPRs 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

4 participants

@mcollina@Renegade334@nodejs-github-bot@trivikr