mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
## Problem The chat input loses focus after sending a message. Users have to click back into the input field to type their next message. ## Root Cause When a message is sent: 1. `handleSubmit` in `AgentChatInput` calls `onSend(text)` then immediately `focus()` — but this is premature 2. The async send sets `isLoading=true`, which disables the editor via `EditableStatePlugin` 3. When the send resolves, `handleSendFromInput` calls `clear()` and `focus()` — but the editor may still be disabled at this point (React hasn't re-rendered yet) 4. When React re-renders with `isLoading=false`, the editor becomes editable again but nobody restores focus ## Fix Added a `useEffect` in `AgentChatInput` that watches for `isLoading` transitioning from `true` to `false` and calls `focus()` on the editor. This ensures focus is restored *after* React has re-enabled the editor, not prematurely. ## Test Added a test in `AgentDetail.test.ts` verifying that `focus()` is called on the input ref after `handleSendFromInput` resolves.