fix(socket): preserve queued once listeners#1978
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughSocketService now records queued listeners with an ChangesSocket listener queue once() behavior fix
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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 |
8c95ad0 to
ed8019d
Compare
|
Follow-up update: I added coverage for the queued regular on() listener path as well. The previous Coverage Gate failure is fixed now, and all current CI checks are green. This PR is ready for maintainer review/merge. |
|
@coderabbitai can u explain this pr in detail? |
|
Tip For best results, initiate chat on the files or code changes.
🐛 The Bug (Issue
|
| Test | Verifies |
|---|---|
once() before connect |
After connecting, the socket's .once() is called with the queued listener — and .on() is not called with it |
on() before connect |
After connecting, the socket's .on() is called with the queued listener — and .once() is not called with it |
Both tests:
- Call
socketService.disconnect()to clear any existing socket - Register a listener before calling
connect() - Trigger
connect(...)to create the socket - Inspect the mock socket to confirm the correct method was used
📁 Files Changed
| File | Change |
|---|---|
app/src/services/socketService.ts |
+15 / -5 lines — adds once flag to PendingSocketListener, updates queue and flush logic |
app/src/services/__tests__/socketService.test.ts |
+54 / -0 lines — adds two regression tests |
In short: a small but impactful correctness fix ensuring one-shot event handlers stay one-shot, even when registered before the socket connection is established. 🐇
Summary
once()semantics for listeners queued before the socket existssocket.once()instead ofsocket.on()once()listenersCloses #1932
Tests
pnpm --filter openhuman-app exec vitest run --config test/vitest.config.ts src/services/__tests__/socketService.test.tspnpm --filter openhuman-app compilegit diff --checkSummary by CodeRabbit