Skip to content

Message stream stays connected after clearing conversation #267

@adliebe

Description

@adliebe

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

  1. Render useMessageStream("conv-123").
  2. Let the mocked EventSource open so isConnected becomes true.
  3. Rerender the hook with conversationId: null.
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions