fix(chat): clear stale mode initialValue on message submit#279
Merged
LeeCheneler merged 2 commits intomainfrom Apr 11, 2026
Merged
fix(chat): clear stale mode initialValue on message submit#279LeeCheneler merged 2 commits intomainfrom
LeeCheneler merged 2 commits intomainfrom
Conversation
handleMessage never reset `mode.initialValue` after the user sent a
message, so when a history-recalled entry was submitted and an ask
or confirm prompt then unmounted ChatInput, the stale value would
re-hydrate the input on remount and the just-sent message would
reappear in the prompt.
Resetting `mode` to a fresh `{ kind: "input" }` at the top of
handleMessage clears the leftover initialValue and initialImages
from history recalls and draft restores, fixing the remount path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
After a user recalled a prior message from history and resubmitted it, a subsequent ask or confirm prompt would unmount ChatInput and the previously-sent message would re-hydrate the input when ChatInput remounted — forcing the user to clear it manually on every question.
GitHub Issue
N/A
What Changed
handleMessageinsrc/chat/chat.tsxnever resetmode.initialValueafter dispatching a message.mode.initialValueis set by two paths —handleSelected(selecting a history entry) andhandleExit(exiting history mode with a draft) — and stays on themodeobject indefinitely becauseChatInput's internal `useState` only uses it on mount.Normally that's invisible: ChatInput stays mounted after submit, its local state is cleared by `applyChange("")`, and nobody looks at `mode.initialValue` again. But when an ask/confirm prompt fires, chat.tsx's JSX guard at line 660 swaps ChatInput out for the prompt. Answering the prompt re-renders ChatInput, which reads `mode.initialValue` from props and re-seeds its local value — resurrecting the just-sent message.
Fix: reset `mode` to a fresh `{ kind: "input" }` at the top of `handleMessage`. This clears any leftover `initialValue`/`initialImages` before the message is dispatched, so the remount path reads `undefined` and lands empty.
Notes for Reviewers
Regression test in `chat.test.tsx` drives the full flow via MSW: seed history with a message, recall it via up-arrow + enter, resubmit, trigger an ask tool call, answer the ask, assert the chat input area is empty. Verified failing before the fix (frame literally showed `❯ recallme` in the input) and passing after.