The best way to control Claude Code, Codex and more from any computer or phone
fix(web): remove inserted citations on cancel (#10518)
Exotic committed
Sep 7, 2026 at 18:29 UTC
fe07ffe7c0bf1858ba4d1cd1ce0a67b10802a747
2 files changed
+19
-7
apps/web/src/components/ComposerCitationNode.tsx
+11
-6
@@ -42,6 +42,7 @@ export type ComposerCitationCommentRequest = {
42
export type ComposerCitationCommentTarget = {
43
nodeKey: NodeKey;
44
sourceAnchor?: AssistantCitationSourceAnchor;
45
+ removeOnCancel?: boolean;
46
};
47
48
export const ComposerCitationCommentContext = createContext<{
@@ -68,7 +69,11 @@ export function $consumeComposerCitationCommentRequest(requestRef: {
69
let offset = 0;
70
for (const node of paragraph.getChildren()) {
71
if (offset === request.citationStart && node instanceof ComposerCitationNode) {
71
- return { nodeKey: node.getKey(), sourceAnchor: request.sourceAnchor };
72
+ return {
73
+ nodeKey: node.getKey(),
74
+ sourceAnchor: request.sourceAnchor,
75
+ removeOnCancel: true,
76
+ };
77
}
78
offset += node.getTextContentSize();
79
}
@@ -78,6 +83,8 @@ export function $consumeComposerCitationCommentRequest(requestRef: {
83
function ComposerCitationDecorator(props: { citation: AssistantCitation; nodeKey: NodeKey }) {
84
const [editor] = useLexicalComposerContext();
85
const commentContext = use(ComposerCitationCommentContext);
86
+ const commentTarget =
87
+ commentContext.openComment?.nodeKey === props.nodeKey ? commentContext.openComment : null;
88
const onSaveComment = (comment: string): boolean => {
89
if (!editor.isEditable()) return false;
90
let accepted = false;
@@ -118,15 +125,13 @@ function ComposerCitationDecorator(props: { citation: AssistantCitation; nodeKey
125
<AssistantCitationChip
126
citation={props.citation}
127
commentEditor={{
121
- open: commentContext.openComment?.nodeKey === props.nodeKey,
122
- sourceAnchor:
123
- commentContext.openComment?.nodeKey === props.nodeKey
124
- ? commentContext.openComment.sourceAnchor
125
- : undefined,
128
+ open: commentTarget !== null,
129
+ sourceAnchor: commentTarget?.sourceAnchor,
130
onOpenChange: (open) => {
131
if (open && !editor.isEditable()) return;
132
commentContext.onOpenChange(props.nodeKey, open);
133
},
134
+ ...(commentTarget?.removeOnCancel ? { onCancel: onRemove } : {}),
135
onSave: onSaveComment,
136
onSaveAndSend: (comment) => {
137
if (!onSaveComment(comment)) return false;
apps/web/src/components/chat/AssistantCitationChip.tsx
+8
-1
@@ -41,6 +41,7 @@ export function AssistantCitationChip({
41
open: boolean;
42
sourceAnchor?: AssistantCitationSourceAnchor | undefined;
43
onOpenChange: (open: boolean) => void;
44
+ onCancel?: () => void;
45
onSave: (comment: string) => boolean;
46
onSaveAndSend?: (comment: string) => boolean;
47
};
@@ -168,7 +169,13 @@ export function AssistantCitationChip({
169
},
170
}
171
: {})}
171
- onCancel={() => commentEditor.onOpenChange(false)}
172
+ onCancel={() => {
173
+ if (commentEditor.onCancel) {
174
+ commentEditor.onCancel();
175
+ } else {
176
+ commentEditor.onOpenChange(false);
177
+ }
178
+ }}
179
/>
180
</PopoverPopup>
181
) : null}