Skip to content

fix(chat): clear stale mode initialValue on message submit#279

Merged
LeeCheneler merged 2 commits intomainfrom
fix/stale-mode-initial-value-after-send
Apr 11, 2026
Merged

fix(chat): clear stale mode initialValue on message submit#279
LeeCheneler merged 2 commits intomainfrom
fix/stale-mode-initial-value-after-send

Conversation

@LeeCheneler
Copy link
Copy Markdown
Owner

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

handleMessage in src/chat/chat.tsx never reset mode.initialValue after dispatching a message. mode.initialValue is set by two paths — handleSelected (selecting a history entry) and handleExit (exiting history mode with a draft) — and stays on the mode object indefinitely because ChatInput'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.

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.
@github-actions github-actions Bot added the fix Bug fix label Apr 11, 2026
@LeeCheneler LeeCheneler merged commit 5b20459 into main Apr 11, 2026
4 checks passed
@LeeCheneler LeeCheneler deleted the fix/stale-mode-initial-value-after-send branch April 11, 2026 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant