Skip to content

fix(web): convert ReadableStream to Blob for all browser environments#431

Open
JohnsonChin1009 wants to merge 1 commit into
ardriveapp:alphafrom
JohnsonChin1009:fix/issue-396-readable-stream-disturbed-web-retry
Open

fix(web): convert ReadableStream to Blob for all browser environments#431
JohnsonChin1009 wants to merge 1 commit into
ardriveapp:alphafrom
JohnsonChin1009:fix/issue-396-readable-stream-disturbed-web-retry

Conversation

@JohnsonChin1009

Copy link
Copy Markdown

Context

uploadFile() fails in browser environments (Chrome + Next.js/Turbopack) with:

Failed to upload file after 6 attempts
Failed to execute 'fetch' on 'Window': The provided ReadableStream is disturbed

As reported here in #396.

Root cause

createReadableStreamWithEvents in events.ts calls originalStream.getReader() inside the start() callback, which runs immediately when the wrapper stream is constructed. Chrome's fetch is stricter than Firefox/Safari — it considers the stream already "disturbed" when { body: ReadableStream, duplex: 'half' } is passed to fetch.

New Fix

toFetchBody in http.ts already converted ReadableStream → Blob for Firefox/Safari via isFirefoxOrSafari(). This PR extends that same conversion to all browser environments by replacing the guard with isBrowser, and removes the now-unused isFirefoxOrSafari function.

Testing

Chrome fails with "ReadableStream is disturbed" when the event-tracking
wrapper locks the stream via getReader() before fetch consumes it.
Firefox/Safari already converted streams to Blob — this extends the same
fix to all browsers, resolving the issue in Chrome/Turbopack environments.

Closes ardriveapp#396
@JohnsonChin1009 JohnsonChin1009 requested a review from a team as a code owner June 8, 2026 04:51
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c4ba1934-2aeb-4760-95b4-07e491f78004

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@fedellen

Copy link
Copy Markdown
Contributor

hey @JohnsonChin1009 thanks for this!

we're having some trouble reproducing the issue in a chrome environment using the html example on the repo. the readable stream code path can be used for files over the memory constrains of the browser to post the whole stream to /tx without getting OOM during chunkingMode: disabled

accepting the PR as is will break that functionality. we believe the best way to unblock you here is that there should be a new parameter added to the factory like browserStreamMode: 'blob' | 'stream' | 'auto' -- where auto is the current unbreaking functionality and blob and stream set use the path the client wants

you're welcome to take a shot at that, should be just updating the turbo factory and drilling that parameter down to this layer

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.

2 participants