The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 00:45 UTC
fix(web): sending from an empty citation comment clears the composer (#33440)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 10, 2026 at 12:57 UTC
9cd7a04797184c92a8f636ae1e918f42c139d850
3 files changed
+96
-20
apps/web/src/components/ComposerPromptEditorTiptap.citationDraft.browser.test.tsx
+62
@@ -31,9 +31,11 @@ const promptBefore = `See ${serializeAssistantCitation(citation)} `;
31
function Composer({
32
question,
33
editorRef,
34
+ send = "clears",
35
}: {
36
question: boolean;
37
editorRef: React.RefObject<ComposerPromptEditorHandle | null>;
38
+ send?: "clears" | "blocked" | "refusedLater";
39
}) {
40
const [prompt, setPrompt] = useState(promptBefore);
41
const [answer, setAnswer] = useState("");
@@ -61,6 +63,11 @@ function Composer({
63
onCitationDraftSave={(replacedValue, savedValue) => {
64
if (replacedValue === prompt) setPrompt(savedValue);
65
}}
66
+ onCitationSubmitAndSend={() => {
67
+ if (send === "blocked") return false;
68
+ if (send === "clears") setPrompt("");
69
+ return true;
70
+ }}
71
onPaste={() => {}}
72
/>
73
</>
@@ -97,3 +104,58 @@ it("keeps an unsaved citation comment when a question takes the composer", async
104
);
105
await expect.element(page.getByLabelText("Edit citation comment")).toBeInTheDocument();
106
});
107
+
108
+it("clears the sent prompt when an empty citation comment sends it", async () => {
109
+ const editorRef = createRef<ComposerPromptEditorHandle>();
110
+ await using screen = await render(<Composer question={false} editorRef={editorRef} />);
111
+
112
+ const sourceAnchor = findAssistantCitationSourceAnchor(document, citation);
113
+ if (!sourceAnchor) throw new Error("Citation source did not resolve");
114
+ await act(async () =>
115
+ editorRef.current?.requestCitationComment({
116
+ previousValue: "See ",
117
+ value: promptBefore,
118
+ citationStart: "See ".length,
119
+ sourceAnchor,
120
+ insertedSpaces: { before: false, after: true },
121
+ }),
122
+ );
123
+ const comment = page.getByLabelText("Comment on selected text");
124
+ await expect.element(comment).toHaveFocus();
125
+ await userEvent.keyboard("{Control>}{Enter}{/Control}");
126
+
127
+ await expect.element(comment).not.toBeInTheDocument();
128
+ await expect.element(page.getByTestId("composer-editor")).toHaveFocus();
129
+ await expect.element(screen.getByRole("status")).toHaveAttribute("data-prompt", "");
130
+});
131
+
132
+it.each(["blocked", "refusedLater"] as const)(
133
+ "keeps the caret after the citation when save-and-send is %s",
134
+ async (send) => {
135
+ const editorRef = createRef<ComposerPromptEditorHandle>();
136
+ await using screen = await render(
137
+ <Composer question={false} editorRef={editorRef} send={send} />,
138
+ );
139
+
140
+ const sourceAnchor = findAssistantCitationSourceAnchor(document, citation);
141
+ if (!sourceAnchor) throw new Error("Citation source did not resolve");
142
+ await act(async () =>
143
+ editorRef.current?.requestCitationComment({
144
+ previousValue: "See ",
145
+ value: promptBefore,
146
+ citationStart: "See ".length,
147
+ sourceAnchor,
148
+ insertedSpaces: { before: false, after: true },
149
+ }),
150
+ );
151
+ const comment = page.getByLabelText("Comment on selected text");
152
+ await expect.element(comment).toHaveFocus();
153
+ await userEvent.keyboard("{Control>}{Enter}{/Control}");
154
+ await expect.element(comment).not.toBeInTheDocument();
155
+ await userEvent.keyboard("x");
156
+
157
+ await expect
158
+ .element(screen.getByRole("status"))
159
+ .toHaveAttribute("data-prompt", `See ${serializeAssistantCitation(citation)}x `);
160
+ },
161
+);
apps/web/src/components/ComposerPromptEditorTiptap.tsx
+27
-14
@@ -21,6 +21,7 @@ import {
21
Plugin,
22
PluginKey,
23
TextSelection,
24
+ type Transaction,
25
} from "@tiptap/pm/state";
26
import { Decoration, DecorationSet, type EditorView } from "@tiptap/pm/view";
27
import type { NodeType, ResolvedPos } from "@tiptap/pm/model";
@@ -186,7 +187,7 @@ export interface ComposerPromptEditorProps {
187
onPageScrollKeyDown?: (key: "PageUp" | "PageDown") => void;
188
onPageScrollKeyUp?: (key: string) => void;
189
onPageScrollRelease?: () => void;
189
- onCitationSubmitAndSend?: () => void;
190
+ onCitationSubmitAndSend?: () => boolean;
191
/** Saves unsaved citation text into replacedValue when a controlled rewrite replaces the document. */
192
onCitationDraftSave?: (replacedValue: string, savedValue: string) => void;
193
onPaste: React.ClipboardEventHandler<HTMLElement>;
@@ -213,12 +214,12 @@ const ComposerCitationCommentContext = createContext<{
214
openComment: OpenCitationComment | null;
215
onOpenChange: (citeKey: string, open: boolean) => void;
216
onDraftChange: (citeKey: string, comment: string) => void;
216
- onSubmitAndSend: () => void;
217
+ onSubmitAndSend: () => boolean;
218
}>({
219
openComment: null,
220
onOpenChange: () => {},
221
onDraftChange: () => {},
221
- onSubmitAndSend: () => {},
222
+ onSubmitAndSend: () => false,
223
});
224
225
const RichComposerSkillsContext = createContext<ReadonlyArray<ServerProviderSkill>>([]);
@@ -477,13 +478,23 @@ function ComposerCitationNodeView({ node, editor, getPos }: NodeViewProps) {
478
editor.chain().focus().deleteRange({ from, to }).run();
479
};
480
481
+ const sentRef = useRef(false);
482
const onRestoreFocus = () => {
483
+ const sent = sentRef.current;
484
+ sentRef.current = false;
485
if (!editor.isEditable) return;
486
const pos = nodePos();
483
- if (pos === null) return;
484
- const current = editor.state.doc.nodeAt(pos);
485
- if (!current || current.type.name !== "composer-citation") return;
486
- editor.commands.focus(pos + current.nodeSize);
487
+ const current = pos === null ? null : editor.state.doc.nodeAt(pos);
488
+ if (pos === null || current?.type.name !== "composer-citation") {
489
+ if (sent) editor.view.focus();
490
+ return;
491
+ }
492
+ // The send's controlled rewrite may still be pending; emitting this caret move would restore the old prompt.
493
+ editor
494
+ .chain()
495
+ .setMeta(SILENT_SELECTION_META, sent)
496
+ .focus(pos + current.nodeSize)
497
+ .run();
498
};
499
500
return (
@@ -525,7 +536,7 @@ function ComposerCitationNodeView({ node, editor, getPos }: NodeViewProps) {
536
onDraftChange: (comment) => commentContext.onDraftChange(citeKey, comment),
537
onSaveAndSend: (comment) => {
538
if (!onSaveComment(comment)) return false;
528
- commentContext.onSubmitAndSend();
539
+ sentRef.current = commentContext.onSubmitAndSend();
540
return true;
541
},
542
onRestoreFocus,
@@ -729,6 +740,8 @@ function chipSelectionDecorations({ doc, selection }: EditorState): DecorationSe
740
741
type TiptapEditor = NonNullable<ReturnType<typeof useEditor>>;
742
743
+const SILENT_SELECTION_META = "composerSilentSelection";
744
+
745
function replaceSkillChips(
746
editor: TiptapEditor,
747
replacements: ReturnType<typeof skillChipReplacements>,
@@ -995,10 +1008,10 @@ function ComposerPromptEditorTiptapInner(
1008
onDraftChange: (nodeKey: string, comment: string) => {
1009
citationDraftRef.current = { key: nodeKey, comment };
1010
},
998
- onSubmitAndSend: onCitationSubmitAndSend ?? (() => {}),
1011
+ onSubmitAndSend: onCitationSubmitAndSend ?? (() => false),
1012
};
1013
1001
- const handleEditorChange = (updated: TiptapEditor) => {
1014
+ const handleEditorChange = (updated: TiptapEditor, transaction: Transaction) => {
1015
const map = serializeEditorDoc(updated.state.doc);
1016
const contextIds = literalText ? [] : [...map.contextIds];
1017
const { from, to } = updated.state.selection;
@@ -1025,7 +1038,7 @@ function ComposerPromptEditorTiptapInner(
1038
previousSnapshot.contextIds.length === contextIds.length &&
1039
previousSnapshot.contextIds.every((id, index) => id === contextIds[index])
1040
);
1028
- if (isApplyingControlledUpdateRef.current) return;
1041
+ if (isApplyingControlledUpdateRef.current || transaction.getMeta(SILENT_SELECTION_META)) return;
1042
if (!snapshotChanged) {
1043
if (didComposerSelectionChangeVisibly(previousSelectionRange, nextSelectionRange)) {
1044
readCallbacks().onVisibleSelectionChange?.();
@@ -1459,10 +1472,10 @@ function ComposerPromptEditorTiptapInner(
1472
return;
1473
}
1474
}
1462
- handleEditorChange(updated);
1475
+ handleEditorChange(updated, transaction);
1476
},
1464
- onSelectionUpdate: ({ editor: updated }) => {
1465
- handleEditorChange(updated);
1477
+ onSelectionUpdate: ({ editor: updated, transaction }) => {
1478
+ handleEditorChange(updated, transaction);
1479
},
1480
},
1481
[],
apps/web/src/components/chat/ChatComposer.tsx
+7
-6
@@ -2096,7 +2096,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2096
if (voiceInputActive) {
2097
event?.preventDefault();
2098
submitAfterDictation(() => submitComposerRef.current(dispatchMode, submissionIntent));
2099
- return;
2099
+ return false;
2100
}
2101
if (
2102
noProviderAvailable ||
@@ -2104,7 +2104,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2104
!readEnvironmentScope(environmentId, AuthOrchestrationOperateScope)
2105
) {
2106
event?.preventDefault();
2107
- return;
2107
+ return false;
2108
}
2109
// A send while a pasted image is still compressing would strand that image:
2110
// the turn snapshot wouldn't include it, and it would surface in the *next*
@@ -2116,7 +2116,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2116
title: "Still compressing a pasted image.",
2117
description: "Send again once its thumbnail appears.",
2118
});
2119
- return;
2119
+ return false;
2120
}
2121
if (pendingDraftWork.has(attachmentTargetKey)) {
2122
event?.preventDefault();
@@ -2125,7 +2125,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2125
title: "Still bringing attached context into this message.",
2126
description: "Send again once its chip resolves.",
2127
});
2128
- return;
2128
+ return false;
2129
}
2130
const submission = submitComposerDraft({
2131
prompt: promptRef.current,
@@ -2148,11 +2148,12 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2148
},
2149
});
2150
setComposerSubmissionError(submission.validationMessage);
2151
- if (!submission.didDispatch) return;
2151
+ if (!submission.didDispatch) return false;
2152
onTypingGuardSend();
2153
if (shouldBlurMobileComposerOnSubmit()) {
2154
blurMobileComposerAfterSend();
2155
}
2156
+ return true;
2157
};
2158
const submitComposerStable = useStableCallback(submitComposer);
2159
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- publishes the committed submission handler to the asynchronous dictation completion
@@ -2201,7 +2202,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2202
};
2203
const handleSubmitMessageStable = useStableCallback(handleSubmitMessage);
2204
const submitCitationAndSend = () => {
2204
- submitComposer(
2205
+ return submitComposer(
2206
undefined,
2207
resolveComposerDispatchMode({
2208
running: phase === "running",