Skip to content

fix(structured-clone): preserve Blob.type across structuredClone#319

Open
watilde wants to merge 1 commit into
bytecodealliance:mainfrom
watilde:fix/structured-clone-blob-type
Open

fix(structured-clone): preserve Blob.type across structuredClone#319
watilde wants to merge 1 commit into
bytecodealliance:mainfrom
watilde:fix/structured-clone-blob-type

Conversation

@watilde

@watilde watilde commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

structuredClone(blob) serialized only the byte data and reconstructed the Blob with an empty type, so structuredClone(new Blob(['x'], {type: 'text/plain'})).type returned "" instead of "text/plain". A Blob's type is part of its serialized state per the File API.

Append the type as a length-prefixed UTF-8 string after the byte data on write, and read it back on read. Add an integration test covering a typed Blob, an empty type, and content/type round-tripping.

structuredClone(blob) serialized only the byte data and reconstructed
the Blob with an empty type, so structuredClone(new Blob(['x'],
{type: 'text/plain'})).type returned "" instead of "text/plain". A
Blob's type is part of its serialized state per the File API.

Append the type as a length-prefixed UTF-8 string after the byte data
on write, and read it back on read. Add an integration test covering a
typed Blob, an empty type, and content/type round-tripping.

Signed-off-by: Daijiro Wachi <daijiro.wachi@gmail.com>

@andreiltd andreiltd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! Could you update WPT expectations? I think the easiest way to do that is to run:

just wpt-setup
just wpt-update

This will update new passes. Also I believe the tests added here largely duplicates WPT coverage so we can drop them.

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