Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(chat): stop cancelled-run drafts resurrecting after deletion (#4486)

Naiyuan Qinga898e5317eaf
diff --git a/packages/views/chat/components/chat-input.tsx b/packages/views/chat/components/chat-input.tsx
index 428b3c3f63..43c9f77863 100644
--- a/packages/views/chat/components/chat-input.tsx
+++ b/packages/views/chat/components/chat-input.tsx
@@ -110,8 +110,11 @@ export function ChatInput({
//
// `editorKey` — React `key` on the ContentEditor. Used to force a
// remount when the user explicitly switches agent (so Tiptap's
- // Placeholder, which only reads on mount, refreshes to "Tell {agent}…")
- // or when a cancelled empty run restores a draft from the server.
+ // Placeholder, which only reads on mount, refreshes to "Tell {agent}…").
+ // A cancelled-run draft restore does NOT bump this key: it just writes
+ // the restored text into `inputDraft`, and the editor's own
+ // defaultValue-sync effect (content-editor.tsx) pushes it into the live
+ // instance. There is no second copy of the draft to drift or resurface.
// Crucially this does NOT include `activeSessionId`: when the user
// uploads a file in a brand-new chat, `handleUploadFile` first awaits
// `ensureSession` which lazily creates the session and flips
@@ -134,14 +137,8 @@ export function ChatInput({
const clearInputDraft = useChatStore((s) => s.clearInputDraft);
const [isEmpty, setIsEmpty] = useState(!inputDraft.trim());
const [isSubmitting, setIsSubmitting] = useState(false);
- const [editorRestore, setEditorRestore] = useState<{
- id: string;
- content: string;
- draftKey: string;
- } | null>(null);
const consumedRestoreIdRef = useRef<string | null>(null);
- const activeRestore = editorRestore?.draftKey === draftKey ? editorRestore : null;
- const editorKey = `${selectedAgentId ?? "no-agent"}:${activeRestore?.id ?? "base"}`;
+ const editorKey = selectedAgentId ?? "no-agent";
// Number of in-flight uploads. We track this explicitly (rather than
// peeking at the editor on every render) so the SubmitButton visibly
// disables the instant an upload starts and re-enables the instant it
@@ -190,11 +187,6 @@ export function ChatInput({
setInputDraft(draftKey, restoreDraftRequest.content);
setInputDraftAttachments(draftKey, restoreDraftRequest.attachments ?? []);
setIsEmpty(!restoreDraftRequest.content.trim());
- setEditorRestore({
- id: restoreDraftRequest.id,
- content: restoreDraftRequest.content,
- draftKey,
- });
onRestoreDraftConsumed?.();
}, [
draftKey,
@@ -366,7 +358,7 @@ export function ChatInput({
// intentionally does not depend on activeSessionId.
key={editorKey}
ref={editorRef}
- defaultValue={activeRestore?.content ?? inputDraft}
+ defaultValue={inputDraft}
placeholder={placeholder}
onUpdate={(md) => {
setIsEmpty(!md.trim());