Skip to content
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

DEV-269 Use isomorphic-ws instead of ws #443

Merged
merged 3 commits into from
Mar 4, 2024

Conversation

dmytroyarmak
Copy link
Contributor

Use isomorphic-ws instead of ws to fix problem with webpack v5 complaining about native module usage by ws (it's intender to be run only on Node.js)

@dmytroyarmak dmytroyarmak force-pushed the DEV-269-migrate-to-isomorphic-ws branch from 671b65f to 4c856ca Compare March 1, 2024 18:28
Comment on lines -555 to -575

describe("when executing in a browser environment", () => {
before(() => {
(global as any).window = {
WebSocket: {...ws, fake: true},
};
});

after(() => {
(global as any).window = undefined;
});

it("should use the native browser WebSocket implementation", () => {
createClientStub.resetHistory();

client.graphQL.createSubscriptionClient();

expect(createClientStub.callCount).to.equal(1);
expect(createClientStub.getCall(0).args[0].webSocketImpl.fake).to.equal(true);
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 why we are removing test? we can still verify if isomorphic-ws using native WebSocket with this

Copy link
Contributor Author

@dmytroyarmak dmytroyarmak Mar 4, 2024

Choose a reason for hiding this comment

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

This test case was specifically for typeof window === "undefined" condition that was in our code base, but now it's removed and it's now internal logic of isomorphic-ws. They actually handle it in more graceful way by having browser entry point in package.json (webpack uses it during bundling) that loads very tiny JS wrapper to normalize native websocket and for node.js it loads completely different file with ws implementation.

Anyway, I've extendede previous test case to verify that we pass WebSocket from isomorphic-ws to createClient: d5600cc

Comment on lines -28 to +29
"ws": "^8.4.2"
"ws": "^8.16.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

❔ Why did you downgrade ws library?
Also could it be totally replaced by isomorphic-ws library?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ws is actually upgraded from 4 to 16 😉 It's just unusual to read when version number has 2 digits

isomorphic-ws internally uses ws for NodeJS and they require to have ws package installed as "peer dependency".

Copy link
Contributor

@Campalo Campalo Mar 4, 2024

Choose a reason for hiding this comment

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

ws is actually upgraded from 4 to 16 😉 It's just unusual to read when version number has 2 digits

🙈

@dmytroyarmak dmytroyarmak merged commit a9f717b into master Mar 4, 2024
3 checks passed
@dmytroyarmak dmytroyarmak deleted the DEV-269-migrate-to-isomorphic-ws branch March 4, 2024 09:18
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.

4 participants