Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(chat): drop the page context chip at commit, not after the send settles (MUL-9059) (#10386)
Jiayuan Zhange91a4c30bc77
diff --git a/packages/views/chat/components/chat-input.test.tsx b/packages/views/chat/components/chat-input.test.tsxindex dd9322a1c6..441362d401 100644--- a/packages/views/chat/components/chat-input.test.tsx+++ b/packages/views/chat/components/chat-input.test.tsx@@ -763,7 +763,55 @@ describe("ChatInput page context", () => {fireEvent.click(sendButton());await waitFor(() => expect(onSend).toHaveBeenCalledTimes(1));expect(onSend.mock.calls[0]![0]).toBe("[MUL-1](mention://issue/issue-1)\n\nwhy is this slow?");- await waitFor(() => expect(pageChip()).toBeNull());+ expect(pageChip()).toBeNull();+ });++ // The chip clears in the same commit that scrubs the editor, not once the+ // owner's promise settles: the owner commits before its own follow-up work.+ it("drops the page when the owner commits, while the send is still pending", async () => {+ let finishSend!: (accepted: boolean) => void;+ const onSend = vi.fn<ChatInputOnSend>((_content, _ids, commitInput) => {+ commitInput();+ return new Promise<boolean>((resolve) => { finishSend = resolve; });+ });+ renderInput({ onSend, pageContext: page });+ fireEvent.keyDown(screen.getByTestId("editor"), { key: "Tab" });+ fireEvent.change(screen.getByTestId("editor"), { target: { value: "why is this slow?" } });++ fireEvent.click(sendButton());+ expect(onSend).toHaveBeenCalledTimes(1);+ expect(pageChip()).toBeNull();++ await act(async () => finishSend(true));+ expect(pageChip()).toBeNull();+ });++ // Stop before the task starts: the owner commits, cancels, restores the sent+ // text (mention included) and reports false. A chip left behind would put the+ // page in front of that restored text a second time.+ it("keeps the page off after a committed send the owner then cancels", async () => {+ const onSend = vi.fn<ChatInputOnSend>(async (_content, _ids, commitInput) => {+ commitInput();+ return false;+ });+ renderInput({ onSend, pageContext: page });+ fireEvent.keyDown(screen.getByTestId("editor"), { key: "Tab" });+ fireEvent.change(screen.getByTestId("editor"), { target: { value: "why is this slow?" } });++ await act(async () => fireEvent.click(sendButton()));+ expect(onSend).toHaveBeenCalledTimes(1);+ expect(pageChip()).toBeNull();+ });++ it("keeps the page for a retry when the owner rejects without committing", async () => {+ const onSend = vi.fn<ChatInputOnSend>(async () => false);+ renderInput({ onSend, pageContext: page });+ fireEvent.keyDown(screen.getByTestId("editor"), { key: "Tab" });+ fireEvent.change(screen.getByTestId("editor"), { target: { value: "why is this slow?" } });++ await act(async () => fireEvent.click(sendButton()));+ expect(onSend).toHaveBeenCalledTimes(1);+ expect(pageChip()).toHaveTextContent("MUL-1");});it("leaves Tab alone when the editor already used it, or it came from outside the editor", () => {diff --git a/packages/views/chat/components/chat-input.tsx b/packages/views/chat/components/chat-input.tsxindex 703fe250a1..7c794672c8 100644--- a/packages/views/chat/components/chat-input.tsx+++ b/packages/views/chat/components/chat-input.tsx@@ -546,6 +546,8 @@ export function ChatInput({const pendingFlush = editorRef.current?.flushPendingUpdate?.();if (pendingFlush != null) commitDraft(editorDraftKeyRef.current, pendingFlush);const draftValueAtSend = useChatStore.getState().inputDrafts[keyAtSend];+ // Context is for the message it went with; the next one starts without.+ const pageKeyAtSend = attachedPage ? attachedPageKey : null;let committed = false;const commitInput = (options?: { extraDraftKeys?: string[]; clearEditor?: boolean }) => {if (committed) return;@@ -586,6 +588,11 @@ export function ChatInput({const store = useCommentDraftStore.getState();for (const id of sentAnnotationIds) store.removeAnnotation(annotationKeyAtSend, id);}+ // The page is in the sent message too, and in any restore of it — a+ // cancel-before-task restore that kept the chip would send it twice.+ if (pageKeyAtSend) {+ setAttachedPageKey((current) => (current === pageKeyAtSend ? null : current));+ }};logger.info("input.send", {contentLength: content.length,@@ -608,8 +615,6 @@ export function ChatInput({// retry. Only a commit — here or by the owner — clears it.if (accepted === false) return false;if (!committed) commitInput();- // Context is for the message it went with; the next one starts without.- if (attachedPage) setAttachedPageKey(null);return true;},});