GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — perf(mobile): compressed websocket frames for iOS by t3dotgg · Pull Request #4794 · pingdotgg/t3code Conversation
|
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
ApprovabilityVerdict: Needs human review This PR introduces a new native iOS module for WebSocket handling with compression support. The addition of new native networking infrastructure (~400+ lines of new Swift and TypeScript code) that changes runtime WebSocket behavior warrants human review. You can customize Macroscope's approvability policy. Learn more. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
9283c97 to
4e70318
Compare
There was an error while loading. Please reload this page.
React Native's iOS WebSocket is backed by SocketRocket, which never offers permessage-deflate, so the server-side negotiation from #4705 only benefited Android (OkHttp offers it by default). This adds a URLSessionWebSocketTask- backed Expo module (URLSession offers the extension in its handshake) and injects it as the Effect Socket constructor on iOS only, with a fallback to the global WebSocket on Android and on binaries predating the module. Co-Authored-By: Claude Fable 5 <[email protected]>
Bots caught the emit-after-remove race: delegate callbacks deferred the emit onto the serial queue then removed the emitter synchronously, so close/error events never reached JS. Emits now run synchronously on the queue before removal. Also cleans up activeSockets when connect throws, and imports "expo" lazily so test import chains touching runtime.ts do not evaluate expo's dev-only setup (CI __DEV__ failure). Co-Authored-By: Claude Fable 5 <[email protected]>
Verified on the simulator: the socket completed its 101 (with permessage-deflate negotiated) and then died instantly with NSURLErrorDomain -1005, so JS never saw an open event and the supervisor reconnected every 15s. The dev client registers custom URLProtocol classes for its network inspector; they intercept URLSession traffic and do not understand the WebSocket upgrade. Clearing protocolClasses on the session config fixes it: one stable socket, no reconnects over 60s. Co-Authored-By: Claude Fable 5 <[email protected]>
URLSession retains its delegate until invalidated, so cancelAll() left the connections object and its session alive on every module destroy/recreate cycle. Teardown now invalidates and clears the session; the next open() builds a fresh one. Verified on the simulator: environment connects, holds a single socket for 60s, and reconnects cleanly after a full app teardown and relaunch. Co-Authored-By: Claude Fable 5 <[email protected]>
59ce135 to
95f6b12
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 95f6b12. Configure here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
close() during CONNECTING (an Effect open-timeout or scope teardown) leaves the native connect in flight, so its didOpen could still land and flip the socket back to OPEN, firing open handlers on a socket the caller had already given up on. handleOpen now only transitions from CONNECTING. Co-Authored-By: Claude Fable 5 <[email protected]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
apps/mobile/modules/t3-websocket/ios/T3WebSocketModule.swift (1)
30-37: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winReport dropped sends instead of returning silently.
sendBinarydrops the frame when base64 decoding fails.send(line 95) drops the frame when no task exists forid. The JS adapter receives no signal in either case, so a caller sees a successfulsend()for data that never left the device. EmitonErroron both paths.♻️ Proposed change
Function("sendBinary") { (id: Int, base64: String) in - guard let data = Data(base64Encoded: base64) else { return } + guard let data = Data(base64Encoded: base64) else { + self.connections.reportError(id: id, message: "Invalid base64 payload") + return + } self.connections.send(id: id, message: .data(data)) }Add the helper and the missing-task signal in
T3WebSocketConnections:func reportError(id: Int, message: String) { queue.async { self.emitLocked(id: id, event: "onError", payload: ["message": message]) } } func send(id: Int, message: URLSessionWebSocketTask.Message) { queue.async { guard let task = self.tasksById[id] else { self.emitLocked(id: id, event: "onError", payload: ["message": "Socket is not open"]) return } // ... existing send } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/mobile/modules/t3-websocket/ios/T3WebSocketModule.swift` around lines 30 - 37, Update sendBinary and T3WebSocketConnections.send to report failed sends through onError instead of silently returning: use a T3WebSocketConnections.reportError helper for invalid base64 input, and emit an onError event with “Socket is not open” when no task exists for the requested id. Preserve the existing send behavior for valid data and open sockets.apps/mobile/src/lib/nativeWebSocket.test.ts (1)
106-131: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd coverage for
onErrorand for protocol forwarding.The suite does not exercise
handleErroror theprotocolsargument.handleErrordispatches anErrorinstance rather than an event object, which is the least obvious part of the adapter contract. A short test for each closes that gap.💚 Suggested tests
it("dispatches native errors and forwards protocols", async () => { const construct = await loadNativeWebSocketConstructor(); const socket = construct!("wss://example.test/ws", ["t3"]); expect(lastCall("connect")!.args[2]).toEqual(["t3"]); const id = connectionIdOf(socket); const errors: unknown[] = []; socket.addEventListener("error", (event) => errors.push(event)); mocks.emit("onError", { id, message: "boom" }); expect(errors[0]).toBeInstanceOf(Error); });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/mobile/src/lib/nativeWebSocket.test.ts` around lines 106 - 131, Add test coverage in the native WebSocket test suite for the constructor’s protocols argument and the onError path handled by handleError. Instantiate the socket with a protocol list and assert connect receives it, then emit onError, capture the error event, and assert the dispatched value is an Error instance.
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/mobile/src/lib/nativeWebSocket.ts`:
- Around line 46-63: Update attachNativeListeners so nativeListenersAttached is
set to true only after all four module.addListener registrations complete
successfully. Keep the flag false when any registration throws, allowing a later
invocation to retry attaching listeners and deliver events to sockets.
---
Nitpick comments:
In `@apps/mobile/modules/t3-websocket/ios/T3WebSocketModule.swift`:
- Around line 30-37: Update sendBinary and T3WebSocketConnections.send to report
failed sends through onError instead of silently returning: use a
T3WebSocketConnections.reportError helper for invalid base64 input, and emit an
onError event with “Socket is not open” when no task exists for the requested
id. Preserve the existing send behavior for valid data and open sockets.
In `@apps/mobile/src/lib/nativeWebSocket.test.ts`:
- Around line 106-131: Add test coverage in the native WebSocket test suite for
the constructor’s protocols argument and the onError path handled by
handleError. Instantiate the socket with a protocol list and assert connect
receives it, then emit onError, capture the error event, and assert the
dispatched value is an Error instance.
Fix all unresolved CodeRabbit comments on this PR:
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 13b4bc2a-5a6e-4d6f-9422-ebf4f5d26330
apps/mobile/modules/t3-websocket/expo-module.config.jsonapps/mobile/modules/t3-websocket/ios/T3WebSocket.podspecapps/mobile/modules/t3-websocket/ios/T3WebSocketModule.swiftapps/mobile/src/lib/nativeWebSocket.test.tsapps/mobile/src/lib/nativeWebSocket.tsapps/mobile/src/lib/runtime.ts
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| function attachNativeListeners(module: T3WebSocketNativeModule) { | ||
| if (nativeListenersAttached) { | ||
| return; | ||
| } | ||
| nativeListenersAttached = true; | ||
| module.addListener("onOpen", (payload) => { | ||
| activeSockets.get(payload.id)?.handleOpen(); | ||
| }); | ||
| module.addListener("onMessage", (payload) => { | ||
| activeSockets.get(payload.id)?.handleMessage(payload.data ?? "", payload.binary === true); | ||
| }); | ||
| module.addListener("onClose", (payload) => { | ||
| activeSockets.get(payload.id)?.handleClose(payload.code ?? 1006, payload.reason ?? ""); | ||
| }); | ||
| module.addListener("onError", (payload) => { | ||
| activeSockets.get(payload.id)?.handleError(payload.message ?? "WebSocket error"); | ||
| }); | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Set the attached flag only after the listeners attach.
If the first module.addListener call throws, nativeListenersAttached stays true. No later socket then receives native events, and every socket stays in CONNECTING until Effect's open timeout.
if (nativeListenersAttached) {
return;
}
- nativeListenersAttached = true;
module.addListener("onOpen", (payload) => {
@@
module.addListener("onError", (payload) => {
activeSockets.get(payload.id)?.handleError(payload.message ?? "WebSocket error");
});
+ nativeListenersAttached = true;
}
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| function attachNativeListeners(module: T3WebSocketNativeModule) { | |
| if (nativeListenersAttached) { | |
| return; | |
| } | |
| nativeListenersAttached = true; | |
| module.addListener("onOpen", (payload) => { | |
| activeSockets.get(payload.id)?.handleOpen(); | |
| }); | |
| module.addListener("onMessage", (payload) => { | |
| activeSockets.get(payload.id)?.handleMessage(payload.data ?? "", payload.binary === true); | |
| }); | |
| module.addListener("onClose", (payload) => { | |
| activeSockets.get(payload.id)?.handleClose(payload.code ?? 1006, payload.reason ?? ""); | |
| }); | |
| module.addListener("onError", (payload) => { | |
| activeSockets.get(payload.id)?.handleError(payload.message ?? "WebSocket error"); | |
| }); | |
| } | |
| function attachNativeListeners(module: T3WebSocketNativeModule) { | |
| if (nativeListenersAttached) { | |
| return; | |
| } | |
| module.addListener("onOpen", (payload) => { | |
| activeSockets.get(payload.id)?.handleOpen(); | |
| }); | |
| module.addListener("onMessage", (payload) => { | |
| activeSockets.get(payload.id)?.handleMessage(payload.data ?? "", payload.binary === true); | |
| }); | |
| module.addListener("onClose", (payload) => { | |
| activeSockets.get(payload.id)?.handleClose(payload.code ?? 1006, payload.reason ?? ""); | |
| }); | |
| module.addListener("onError", (payload) => { | |
| activeSockets.get(payload.id)?.handleError(payload.message ?? "WebSocket error"); | |
| }); | |
| nativeListenersAttached = true; | |
| } |
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/mobile/src/lib/nativeWebSocket.ts` around lines 46 - 63, Update
attachNativeListeners so nativeListenersAttached is set to true only after all
four module.addListener registrations complete successfully. Keep the flag false
when any registration throws, allowing a later invocation to retry attaching
listeners and deliver events to sockets.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Closing as part of the open-PR backlog sweep (wave 1). Reason: iOS native compressed WS; server permessage-deflate already shipped in #4705. Reopen if this is still wanted and you’re willing to rebase onto current |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.