Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

structuredClone fails for {Readable,Writable}Stream in Safari #24642

Open
jed opened this issue Oct 5, 2024 · 4 comments
Open

structuredClone fails for {Readable,Writable}Stream in Safari #24642

jed opened this issue Oct 5, 2024 · 4 comments
Labels
data:api 🐇 Compat data for Web APIs. https://developer.mozilla.org/docs/Web/API

Comments

@jed
Copy link

jed commented Oct 5, 2024

What type of issue is this?

Browser bug (a bug with a feature that may impact site compatibility)

What information was incorrect, unhelpful, or incomplete?

The Browser Compatibility shows Safari and Safari iOS fully support structuredClone, but the API fails for ReadableStream or WritableStream.

What browsers does this problem apply to, if applicable?

Safari

What did you expect to see?

A clone of the ReadableStream.

Did you test this? If so, how?

Run the following in the console to test:

let rs = new ReadableStream();
structuredClone(rs, {transfer: [rs]})

Chrome et al will log something like this:

▶︎ ReadableStream {locked: false}

Safari will log this:

▶︎ DataCloneError: The object can not be cloned.

Can you link to any release notes, bugs, pull requests, or MDN pages related to this?

No response

Do you have anything more you want to share?

Transferring streams is also broken for postMessage: https://bugs.webkit.org/show_bug.cgi?id=215485

MDN URL

https://developer.mozilla.org/en-US/docs/Web/API/Window/structuredClone

MDN metadata

MDN page report details
  • Query: api.structuredClone
  • Report started: 2024-10-05T13:15:00.407Z
@queengooborg queengooborg added the data:api 🐇 Compat data for Web APIs. https://developer.mozilla.org/docs/Web/API label Oct 6, 2024
@Josh-Cena
Copy link
Member

Josh-Cena commented Oct 6, 2024

This is not how BCD encodes this information. BCD documents the transferability of each API under its API table, because structuredClone basically delegates the transfer algorithm to each API implementation, so full support of structuredClone does not imply full support of transferring every web API. Check https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream#browser_compatibility, and you will see that transferable is false.

@jed
Copy link
Author

jed commented Oct 7, 2024

Perhaps rather than a full green checkmark, this merits some sort of caveat, like a "See implementation notes" asterisk? Do you see how this could be misleading otherwise?

@Josh-Cena
Copy link
Member

I can imagine a note like "full support of structuredClone does not imply full support of all transferable types", but I don't think it's confusing as-is. structuredClone()'s algorithm is extremely simple and self-contained, and it basically just tries to search "transfer" as a method on each object. The bulk of the transfer behavior is defined by each web API.

@jed
Copy link
Author

jed commented Oct 7, 2024

Totally, I think a note like that would be a great help for folks unfamiliar with these exceptions, which are otherwise quite far from the MDN page of the failing function... postMessage failing due to structuredClone failing due a transferrable object failing to have a transfer method...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data:api 🐇 Compat data for Web APIs. https://developer.mozilla.org/docs/Web/API
Projects
None yet
Development

No branches or pull requests

3 participants