From 82c57c6e57040c1836154771d7e638d6d30fa6b3 Mon Sep 17 00:00:00 2001 From: Steven Luscher Date: Tue, 16 Apr 2024 14:13:42 -0700 Subject: [PATCH] Use native `WebSocket` in server runtimes that support it (#2500) * Use native `WebSocket` in server runtimes that support it * Create witty-camels-remember.md --- .changeset/witty-camels-remember.md | 5 +++++ packages/ws-impl/src/index.node.ts | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .changeset/witty-camels-remember.md diff --git a/.changeset/witty-camels-remember.md b/.changeset/witty-camels-remember.md new file mode 100644 index 000000000000..6fb330c94fa2 --- /dev/null +++ b/.changeset/witty-camels-remember.md @@ -0,0 +1,5 @@ +--- +"@solana/ws-impl": patch +--- + +Use native `WebSocket` for compatibility with server runtimes that support it, like Deno diff --git a/packages/ws-impl/src/index.node.ts b/packages/ws-impl/src/index.node.ts index cb4d0c100e3a..92c4403f3228 100644 --- a/packages/ws-impl/src/index.node.ts +++ b/packages/ws-impl/src/index.node.ts @@ -1,4 +1,6 @@ // When building the browser bundle, this import gets replaced by `globalThis.WebSocket`. import WebSocketImpl from 'ws'; -export default WebSocketImpl; +export default globalThis.WebSocket + ? globalThis.WebSocket // Use native `WebSocket` in runtimes that support it (eg. Deno) + : WebSocketImpl;