Open zwily opened 2 months ago
This is a hard one to fix in "isomorphic apps". I don't think there's a clean solution here, we can't rename our WebSocket to something else. You'd face this problem even with other runtimes as well. We'll have to think this one through...
Which Cloudflare product(s) does this pertain to?
Workers Runtime
What version(s) of the tool(s) are you using?
3.51.0 [Wrangler]
What version of Node are you using?
No response
What operating system and version are you using?
Mac Sonoma
Describe the Bug
Observed behavior
I am in a Remix app on Cloudflare Pages, and adding a websocket endpoint. Things work fine, except for typescript typing. When I create a socket pair (in a loader, which runs in the worker), I get 2 WebSocket objects that are typed according to DOM WebSockets, not the Cloudflare flavor:
I believe this is happening because since this is a Remix app, the tsconfig.json specifies "DOM" in the
lib
list, and thatWebSocket
definition is overriding the one specified by workers-types.Expected behavior
I'm not sure what the right thing to do here is. Maybe since Cloudflare WebSockets aren't 100% compatible with a DOM WebSocket, they should use a different name, like CloudflareWebSocket?
Steps to reproduce
app/routes/websocket.ts
:See that the
server.accept()
line has an error saying accept isn't found on WebSocket, because it thinksserver
is a DOMWebSocket
, not theWebSocket
defined in @cloudflare/workers-types.Relevant issue, before workers-types had WebSocket typing at all: https://github.com/cloudflare/workers-types/issues/84
Please provide a link to a minimal reproduction
No response
Please provide any relevant error logs
No response