Skip to content

Implement support for serializing Headers, Request, and Response.#135

Open
kentonv wants to merge 1 commit intomainfrom
kenton/request-response
Open

Implement support for serializing Headers, Request, and Response.#135
kentonv wants to merge 1 commit intomainfrom
kenton/request-response

Conversation

@kentonv
Copy link
Member

@kentonv kentonv commented Feb 13, 2026

There are some ugly hacks to work around Firefox not supporting request.body. Ugh.

(I started out asking Claude to do this but it actually failed in a bunch of ways and I ended up rewriting most of it.)

There are some ugly hacks to work around Firefox not supporting `request.body`. Ugh.

(I started out asking Claude to do this but it actually failed in a bunch of ways and I ended up rewriting most of it.)
@kentonv kentonv requested a review from dmmulroy February 13, 2026 19:17
@changeset-bot
Copy link

changeset-bot bot commented Feb 13, 2026

⚠️ No Changeset found

Latest commit: 16abb40

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 13, 2026

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/capnweb@135

commit: 16abb40

// `as Uint8Array` is needed here to work around some sort of weird bug in the TS
// types where `new Uint8Array` somehow doesn't return a `Uint8Array`. Instead it
// somehow returns `Uint8Array<ArrayBuffer>` -- but `Uint8Array` is not a generic
// type! WTF?
Copy link
Contributor

@dimitropoulos dimitropoulos Feb 13, 2026

Choose a reason for hiding this comment

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

fwiw, re: this

I think it's because there's a variable and a type with the same name (unfortunate thing that's happened a few times, some worse than others (apocalypse coming if the Record global proposal ever lands and overlaps with the utility type name)).

There's the declare var called Uint8Array which has the constructor type defined here. There's a few overloads for the newable type definition, but they all return a type of the same name Uint8Array defined here which is generic (you can also get to it from globalThis.Uint8Array<...>).

similar to working with class types (which, this time by design have the same name as their types) when you use Uint8Array as a type (with an as casting, for example here) then it's disambiguated.

at least, that's how I understand it.


What error do you see when you remove the cast? I pulled down this branch and removed it and didn't see an error right away.

Copy link
Member Author

Choose a reason for hiding this comment

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

npx tsc --noEmit says:

src/serialize.ts:222:36 - error TS2769: No overload matches this call.
  Overload 1 of 2, '(chunk?: Uint8Array | undefined): void', gave the following error.
    Type 'Uint8Array<ArrayBuffer>' has no properties in common with type 'Uint8Array'.
  Overload 2 of 2, '(chunk?: Uint8Array | undefined): void', gave the following error.
    Type 'Uint8Array<ArrayBuffer>' has no properties in common with type 'Uint8Array'.

222                 controller.enqueue(new Uint8Array(await bodyPromise));
                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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