Extract Reusable App Adapter Factories for SelfClient Assembly#1862
Extract Reusable App Adapter Factories for SelfClient Assembly#1862
Conversation
📝 WalkthroughWalkthroughIntroduces a new Changes
Estimated Code Review Effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly Related PRs
Suggested Labels
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/mobile-sdk-alpha/src/adapters/browser/network.ts`:
- Line 21: The send implementation on the browser network adapter should guard
against sending when the underlying socket isn't open: update the send function
(the send property that calls socket.send) to first check socket.readyState ===
WebSocket.OPEN and if not throw a clear SDK error (matching the React-Native
adapter’s behavior) instead of calling socket.send directly to avoid the DOM
InvalidStateError; reference the send property, socket and readyState symbols
when locating and changing the code.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 96bbeb2a-e5c2-43ea-b58e-6c86880b510b
📒 Files selected for processing (5)
packages/mobile-sdk-alpha/src/adapters/browser/index.tspackages/mobile-sdk-alpha/src/adapters/browser/network.tspackages/mobile-sdk-alpha/src/browser.tsspecs/projects/sdk/workstreams/sdk-core/SPEC.mdspecs/projects/sdk/workstreams/sdk-core/plans/SC-03-selfclient-adapter-assembly.md
| connect: (url: string): WsConn => { | ||
| const socket = new WebSocket(url); | ||
| return { | ||
| send: (data: string | ArrayBufferView | ArrayBuffer) => socket.send(data), |
There was a problem hiding this comment.
send() should check readyState before dispatching.
The socket.send(data) call will throw an InvalidStateError if the WebSocket is not in the OPEN state. The parallel React-Native adapter in src/adapters/react-native/network.ts guards this case with a descriptive error. Without this check, callers get an obscure DOM exception instead of a clear SDK error.
🛡️ Proposed fix
- send: (data: string | ArrayBufferView | ArrayBuffer) => socket.send(data),
+ send: (data: string | ArrayBufferView | ArrayBuffer) => {
+ if (socket.readyState !== WebSocket.OPEN) {
+ throw new Error(`Cannot send data — WebSocket is not open (readyState=${socket.readyState}).`);
+ }
+ socket.send(data);
+ },🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/mobile-sdk-alpha/src/adapters/browser/network.ts` at line 21, The
send implementation on the browser network adapter should guard against sending
when the underlying socket isn't open: update the send function (the send
property that calls socket.send) to first check socket.readyState ===
WebSocket.OPEN and if not throw a clear SDK error (matching the React-Native
adapter’s behavior) instead of calling socket.send directly to avoid the DOM
InvalidStateError; reference the send property, socket and readyState symbols
when locating and changing the code.
Summary
Test plan
Native Consolidation Checklist
cd app && yarn jest:run/yarn workspace @selfxyz/rn-sdk-test-app test)Summary by CodeRabbit