Skip to content

chore: Make ws dependency optional for node.js environments #288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 11, 2025

Conversation

jimmycallin
Copy link
Contributor

@jimmycallin jimmycallin commented Mar 11, 2025

  • I have added automatic tests where applicable
  • The PR title is suitable as a release note
  • The PR contains a description of what has been changed
  • The description contains manual test instructions

Changes

As Node >= 21 has a built-in websocket client, it's preferable to not having to rely on the ws dependency through isomorphic-ws for Node, but rather check if WebSocket is available in the global namespace, and only load ws if not.

Once Node 20 becomes EOL (2026-04-30) we can remove ws as well and only rely on undici's WebSocket.

Test

@jimmycallin jimmycallin requested a review from a team as a code owner March 11, 2025 09:30
@@ -27,8 +27,7 @@ class MockXmlHttpRequest extends EventTarget {
}

beforeAll(() => {
server.listen({ onUnhandledRequest: "bypass" });
global.fetch = fetch;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

leftovers from when we removed cross-fetch

@@ -27,8 +27,7 @@ class MockXmlHttpRequest extends EventTarget {
}

beforeAll(() => {
server.listen({ onUnhandledRequest: "bypass" });
global.fetch = fetch;
server.listen({ onUnhandledRequest: "error" });
Copy link
Contributor Author

@jimmycallin jimmycallin Mar 11, 2025

Choose a reason for hiding this comment

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

now when websocket updates are handled natively, we can do "error" again 🥳

@jimmycallin jimmycallin requested a review from gismya March 11, 2025 09:38
Copy link
Contributor

@gismya gismya left a comment

Choose a reason for hiding this comment

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

Looks good

@jimmycallin jimmycallin merged commit 16ccdd6 into main Mar 11, 2025
4 checks passed
@jimmycallin jimmycallin deleted the ws-optional branch March 11, 2025 09:48
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