Bug
useMessageStream can keep returning isConnected: true after the active conversation is cleared.
The hook closes the existing EventSource in the previous effect cleanup, but the next effect exits early when conversationId is null. Because the visible connection state is stored separately from the active conversation id, the UI can still see the old connected state even though there is no active conversation stream.
Reproduction
- Render
useMessageStream("conv-123").
- Let the mocked
EventSource open so isConnected becomes true.
- Rerender the hook with
conversationId: null.
- The previous
EventSource closes, but isConnected remains stale instead of resetting to false.
Expected
When conversationId is cleared, the hook should expose:
isConnected: false
error: null
- no stale typing state for the previous conversation
- no new
EventSource
Impact
Message UI can show a connected state for no selected conversation, and stale async typing/poll results from an old conversation can leak into the current hook output.
Proposed fix
Derive the public connection, error, and typing state from the active conversationId, clear the EventSource ref during cleanup, ignore stale typing poll completions, and add a regression test for clearing the conversation.
Bug
useMessageStreamcan keep returningisConnected: trueafter the active conversation is cleared.The hook closes the existing
EventSourcein the previous effect cleanup, but the next effect exits early whenconversationIdisnull. Because the visible connection state is stored separately from the active conversation id, the UI can still see the old connected state even though there is no active conversation stream.Reproduction
useMessageStream("conv-123").EventSourceopen soisConnectedbecomestrue.conversationId: null.EventSourcecloses, butisConnectedremains stale instead of resetting tofalse.Expected
When
conversationIdis cleared, the hook should expose:isConnected: falseerror: nullEventSourceImpact
Message UI can show a connected state for no selected conversation, and stale async typing/poll results from an old conversation can leak into the current hook output.
Proposed fix
Derive the public connection, error, and typing state from the active
conversationId, clear theEventSourceref during cleanup, ignore stale typing poll completions, and add a regression test for clearing the conversation.