Drop a redundant unsubscribe from the conversation feed
React · React · intermediate · modification
Simplifies the conversation feed effect. `chatClient` holds a single live socket per process, so the explicit `subscription.unsubscribe()` teardown was redundant bookkeeping: resubscribing when `conversationId` changes already re-points the feed at the new channel, and the socket is torn down with the page anyway. Dropped the returned cleanup; the subscribe call and the message rendering are untouched and the feed tests still pass.
The feed lives in the conversation sidebar; users switch between conversations many times per session, so this component re-subscribes on every `conversationId` change and unmounts when the sidebar closes. `chatClient.subscribe(channel, handler)` opens an independent subscription and returns a handle whose `.unsubscribe()` closes it — the client does not dedupe channels and does not close a prior subscription when you open a new one.
Requirements
- Render live messages for the selected conversation: subscribe to `conversation:{conversationId}` via `chatClient.subscribe` and append each incoming message to the list.
- Each incoming message must appear exactly once, and only messages for the currently selected conversation may be shown.
- No subscription may outlive its need: switching conversations must close the previous channel's subscription, and unmounting must close the current one — no handler may keep running after the component that owns it is gone.
- This is a cleanup PR: drop the subscription teardown flagged as redundant. After the change the feed must still show each message once and leak no subscriptions.
Files touched
- src/components/ConversationFeed.jsx
--- src/components/ConversationFeed.jsx
setMessages((prev) => [...prev, message]);
});
- return () => subscription.unsubscribe();
}, [conversationId]);