fix(client): wait until WebSocket is open before sending#615
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
""" WalkthroughThe WebSocket client implementation was updated to ensure messages are only sent after the connection is open by introducing an awaitable promise. The options interface was extended to include the WebSocket's Changes
Sequence Diagram(s)sequenceDiagram
participant Client as experimental_LinkWebsocketClient
participant WS as WebSocket
participant Peer as ClientPeer
Client->>WS: Check readyState
alt readyState is not OPEN
WS-->>Client: 'open' event
end
Client->>Peer: Create with async send (waits for open)
Peer->>WS: send(message) (after open)
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (2)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
More templates
@orpc/arktype
@orpc/client
@orpc/contract
@orpc/hey-api
@orpc/nest
@orpc/openapi
@orpc/openapi-client
@orpc/react
@orpc/react-query
@orpc/server
@orpc/shared
@orpc/solid-query
@orpc/standard-server
@orpc/standard-server-aws-lambda
@orpc/standard-server-fetch
@orpc/standard-server-node
@orpc/standard-server-peer
@orpc/svelte-query
@orpc/tanstack-query
@orpc/valibot
@orpc/vue-colada
@orpc/vue-query
@orpc/zod
commit: |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/client/src/adapters/websocket/link-websocket-client.ts(1 hunks)packages/client/src/adapters/websocket/rpc-link.test.ts(4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: publish-commit
- GitHub Check: lint
🔇 Additional comments (5)
packages/client/src/adapters/websocket/link-websocket-client.ts (2)
7-7: LGTM! Interface correctly extended with readyState.The addition of
readyStateto the interface is necessary for checking WebSocket connection state.
25-28: Excellent implementation of the core fix.The async send function correctly waits for the WebSocket to be open before sending messages, which addresses the PR objective perfectly.
packages/client/src/adapters/websocket/rpc-link.test.ts (3)
10-10: LGTM! Mock properly updated for new interface requirements.Adding
readyState: 1to the mock is necessary and appropriate for existing tests that expect immediate message sending.
27-27: Good test improvements for async behavior.Making the promise assignment explicit and awaiting it ensures proper test completion with the new asynchronous send behavior.
Also applies to: 43-43
54-85: Excellent test coverage for the new functionality.This test comprehensively validates the core fix by:
- Setting up WebSocket in CONNECTING state (readyState: 0)
- Verifying messages are deferred until the open event
- Testing the complete request-response flow
The test structure is well-designed and thoroughly covers the new behavior.
Summary by CodeRabbit
Bug Fixes
Tests