-
Notifications
You must be signed in to change notification settings - Fork 153
Open
Description
rel: polkadot-js/api#6079
Node.js v21 introduced a native WebSocket, and with v22 its not behind a flag. This causes issues for node because polkadot-js currently grabs the global websocket over the 'ws' lib if it exists. This can be found below.
common/packages/x-ws/src/node.ts
Line 10 in a328ab4
| export const WebSocket = /*#__PURE__*/ extractGlobal('WebSocket', ws); |
common/packages/x-global/src/index.ts
Lines 50 to 58 in a328ab4
| export function extractGlobal <N extends GlobalNames, T extends GlobalType<N>> (name: N, fallback: unknown): T { | |
| // Not quite sure why this is here - snuck in with TS 4.7.2 with no real idea | |
| // (as of now) as to why this looks like an "any" when we do cast it to a T | |
| // | |
| // eslint-disable-next-line @typescript-eslint/no-unsafe-return | |
| return typeof xglobal[name] === 'undefined' | |
| ? fallback as T | |
| : xglobal[name] as T; | |
| } |
The problem here is that the native WebSocket, and Ws don't have the same ErrorEvent interface which stops the api from succesfully reconnecting. There is a few options here:
-
Fix the reconnection on the api level, and give support for both interfaces.
-
Only expose one WebSocket interface in common in this case
ws.
Metadata
Metadata
Assignees
Labels
No labels