fix(web): convert ReadableStream to Blob for all browser environments#431
Conversation
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
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
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 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 you're welcome to take a shot at that, should be just updating the turbo factory and drilling that parameter down to this layer |
Context
uploadFile()fails in browser environments (Chrome + Next.js/Turbopack) with:As reported here in #396.
Root cause
createReadableStreamWithEventsinevents.tscallsoriginalStream.getReader()inside thestart()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
toFetchBodyinhttp.tsalready convertedReadableStream → Blobfor Firefox/Safari viaisFirefoxOrSafari(). This PR extends that same conversion to all browser environments by replacing the guard withisBrowser, and removes the now-unusedisFirefoxOrSafarifunction.Testing
TurboHTTPService.postcovering the Node.js fetch body path