Skip to content

Conversation

bugii
Copy link
Contributor

@bugii bugii commented Jun 2, 2025

I am getting the same error on Safari iOS as well as macOS when trying to upload a file to grove:

Error: ReadableStream is not supported

According to MDN, Safari actually really does not support ReadableStreams as body inside fetch requests.

Thus, I figured the support check inside this package is not correct and I was correct: The detectStreamSupport method returns true on Safari but then the actual request fails. I found a nice article from google where they have another method of testing for support: https://developer.chrome.com/docs/capabilities/web-apis/fetch-streaming-requests#feature_detection

I think that method is quite nice as its not async, too.

Tested on:
Firefox: both versions return false
Chrome: both versions return true
Safari: new version returns false, old version true


// If fails to handle fetch(Request), it's likely not a native implementation of
// Fetch API, so it's not supported.
await fetch(request.clone());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @bugii , thank you for contributing with this great alternative.

There's 2 usages we are trying to assess here, one is browsers and one is Node.js with patched or non-native Fetch API implementations.

This line specifically designed to fail with patched fetch that do not support fetch(Request) and instead just assumes fetch(uri, options). We have seen this in few circumstances one of which was the ElizaOS monorepo.

Copy link
Contributor Author

@bugii bugii Jun 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @cesarenaldi, thank you for the review! Was late at night and I overlooked that code somehow :D
I added the fetch call again.

src/utils.ts Outdated
function detectStreamSupport() {
let duplexAccessed = false;

const hasContentType = new Request('data:text/plain;charset=utf-8,42', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compared to the example in the google page you linked, here we are using a data URI, which includes a mime type. Wondering if this could make a difference, specifically with the hasContentType check.

Copy link
Contributor Author

@bugii bugii Jun 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly I cannot use an empty string as in the example (gives an error in node - which makes sense I guess since relative paths in servers are not really a thing). I think this one is safer, even though I would be very much surprised if the request url had an impact on the content type of the outgoing request before actually fetching it.

@bugii bugii force-pushed the fix/readable-stream-support-check-safari branch from 98ee09a to 8f17913 Compare June 4, 2025 05:13
);
const body = await res.text();

return duplexAccessed && !hasContentType && body === '\x00';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent with the original check was to verify that the testStream was consumed by checking its text representation. A buffer with 0 byte in it renders the \x00 char.

Since the 'response' of a Data URI request is the data URI payload itself, would this be a string with '42' in this case and not match the \x00?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take this PR for a spin and see if we can adjust it.

@cesarenaldi cesarenaldi merged commit 89d50ad into lens-protocol:main Jun 16, 2025
1 of 2 checks passed
@cesarenaldi
Copy link
Member

@bugii this is now available in @lens-chain/storage-client@1.0.5. Thank you for the PR.

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