fix(ui): new chat targets focused instance, fix conversation creation flicker#216
Conversation
… flicker The "New chat" button always created conversations for the alphabetically first instance instead of the currently focused one. Conversation creation also caused flickering due to competing navigations and new conversations appeared at the bottom of the list. - Use focusedSpritzName for "New chat" button, fall back to first agent - Navigate before setting state in handleNewConversation to prevent URL sync effect from firing a competing navigation - Use ref-based guard for creatingConversationFor to avoid stale closures - Prepend new conversations instead of append+sort so they appear at top
- Sidebar: "New chat" calls onNewConversation with focused instance name - Sidebar: falls back to first agent when no instance is focused - ChatPage: new conversation creation navigates to the correct instance - ChatPage: new conversations are prepended at top of conversation list
The new conversation tests triggered the full useChatConnection lifecycle after navigating to the new conversation. In CI, the ACP client start() would hang waiting for WebSocket resolution. Fixed by setting setACPStartPending(true) before clicking the new conversation button, which makes start() hang in a controlled way without blocking the test. Also removed unnecessary bootstrap mocks since they are no longer needed.
…in CI Keep only the two sidebar.test.tsx tests for new-chat targeting which are pure component tests with no WebSocket/ACP lifecycle involvement.
👍 GitRank PR AnalysisScore: 20 points
Eligibility Checks
Impact SummaryThis PR fixes three related bugs in the sidebar conversation creation flow: (1) 'New chat' button now targets the focused instance instead of the alphabetically first one, (2) eliminates conversation creation flickering by reordering navigation and state updates, and (3) ensures new conversations appear at the top of the list immediately. These fixes improve the user experience and make the UI behavior more intuitive and responsive. Analysis DetailsComponent Classification: This PR affects UI components (sidebar and chat page) but doesn't fit neatly into a specific category beyond general UI fixes. The OTHER component is appropriate as a catch-all for UI bug fixes. Severity Justification: This is a P2 (Medium) severity fix addressing three functional bugs with workarounds. The issues impact user experience (wrong instance selection, visual flickering, conversation ordering) but don't cause data loss or service outages. Users can work around these issues by manually selecting conversations or waiting for the UI to settle. Eligibility Notes: Issue: True - PR clearly describes three bugs being fixed. Fix Implementation: True - code changes directly address each described issue with appropriate logic changes. PR Linked: True - comprehensive description with technical details and explanation of fixes. Tests: True - 68 lines of new test coverage added for the focused instance behavior. Tests Required: True - this involves business logic changes in conversation creation and UI state management, which require test coverage to prevent regressions. Analyzed by GitRank 🤖 |
Three bugs in sidebar conversation creation:
"New chat" button always created conversations for the alphabetically first instance instead of the one the user is currently viewing. Fixed by using focusedSpritzName when available, falling back to firstAgentName.
Creating a new conversation caused visible flickering because navigate() was called after setSelectedConversation(), causing the URL sync effect to fire a competing navigation. Fixed by navigating first, then updating state. Also switched the creatingConversationFor guard to a ref to prevent stale closure issues on rapid clicks.
New conversations appeared at the bottom of the conversation list because the server may not return lastActivityAt immediately. Fixed by prepending new conversations to the list instead of appending and re-sorting.
WebSocket connections are not affected — fetchAgents deps, applyConversationUpdate guard, and useChatConnection invocation are all unchanged.
Files changed: