Skip to content

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

Go

fix(composer): blur the reply box after a posted reply (#9194)

Timccd53fabeb0e
diff --git a/packages/views/editor/use-composer-submit.ts b/packages/views/editor/use-composer-submit.ts
index 0e691227ad..612d7d421a 100644
--- a/packages/views/editor/use-composer-submit.ts
+++ b/packages/views/editor/use-composer-submit.ts
@@ -22,8 +22,8 @@
* submitted, and anything typed during the request survives.
*
* It also owns the post-send FOCUS decision (`afterAccepted`). Where the caret
- * lands after a send is a per-surface product call — a reply box the user keeps
- * writing in refocuses, a top-level comment ends the turn and drops the caret —
+ * lands after a send is a per-surface product call — chat refocuses so the user
+ * keeps writing, an issue comment or thread reply drops the caret —
* but the mechanics are identical everywhere and easy to get wrong (must run
* after the clear, must survive a dialog focus trap, must not steal focus the
* user moved elsewhere mid-flight). Those live here once.
diff --git a/packages/views/issues/components/comment-composers.test.tsx b/packages/views/issues/components/comment-composers.test.tsx
index 1695ae769e..05b3fe5854 100644
--- a/packages/views/issues/components/comment-composers.test.tsx
+++ b/packages/views/issues/components/comment-composers.test.tsx
@@ -38,8 +38,8 @@ const editorQuickActionMenu = vi.hoisted(() => ({
// Observability + failure control for the write-back insert path (MUL-5181):
// `insertMarkdownAtEnd` returns false while the (simulated) Tiptap instance
// doesn't exist yet, exactly like the real handle.
-// Post-send caret policy: the top-level composer blurs (the page scrolls to the
-// posted comment instead), a thread reply keeps the caret for the next reply.
+// Post-send caret policy: both the top-level composer and a thread reply blur,
+// so the page's keyboard shortcuts work again straight after a send.
const focusCalls = vi.hoisted(() => ({ focused: 0, blurred: 0 }));
const insertMarkdownSpy = vi.hoisted(() => vi.fn());
const insertPlaceholderSpy = vi.hoisted(() => vi.fn());
@@ -636,9 +636,9 @@ describe("comment composers", () => {
expect(screen.getByTestId("editor").closest("[aria-busy]")).toBeNull();
});
- // Post-send caret policy. The two composers deliberately disagree: posting a
- // top-level comment ends the turn and drops the caret, while a thread reply
- // leaves the user mid-conversation with the box ready for the next one.
+ // Post-send caret policy. Both composers drop the caret once the send is
+ // accepted: a focused editor swallows the page's keyboard shortcuts, so
+ // leaving the caret in a reply box traps the user until they click away.
it("blurs the top-level composer after a posted comment", async () => {
const { container } = renderCommentInput();
@@ -653,17 +653,18 @@ describe("comment composers", () => {
expect(focusCalls.focused).toBe(0);
});
- it("keeps the caret in the reply box after a posted reply", async () => {
+ it("blurs the reply box after a posted reply", async () => {
const { container } = renderReplyInput();
activateComposer("reply-composer-shell");
fireEvent.change(screen.getByTestId("editor"), { target: { value: "replied" } });
- // Discard the shell→editor activation focus; what follows is the refocus.
+ // Discard the shell→editor activation focus; what follows is entirely the
+ // post-send policy.
focusCalls.focused = 0;
fireEvent.click(getSubmitButton(container));
- await waitFor(() => expect(focusCalls.focused).toBeGreaterThan(0));
- expect(focusCalls.blurred).toBe(0);
+ await waitFor(() => expect(focusCalls.blurred).toBeGreaterThan(0));
+ expect(focusCalls.focused).toBe(0);
});
it("reports the new reply id as the accepted scroll target", async () => {
@@ -678,7 +679,7 @@ describe("comment composers", () => {
expect(onAccepted).toHaveBeenCalledWith("reply-new");
});
- it("does not refocus the reply box when the send fails", async () => {
+ it("leaves reply focus alone when the send fails", async () => {
const onSubmit = vi.fn().mockResolvedValue(false);
const { container } = renderReplyInput({ onSubmit });
@@ -690,6 +691,7 @@ describe("comment composers", () => {
await waitFor(() => expect(onSubmit).toHaveBeenCalled());
await new Promise((resolve) => requestAnimationFrame(() => resolve(null)));
expect(focusCalls.focused).toBe(0);
+ expect(focusCalls.blurred).toBe(0);
});
// Regression: the tab-switch flush re-writes IDENTICAL content mid-flight;
@@ -752,9 +754,9 @@ describe("comment composers", () => {
expect(focusCalls.blurred).toBe(0);
});
- // Same coupling on the reply side: refocus is bound to having actually wiped
+ // Same coupling on the reply side: the blur is bound to having actually wiped
// the editor, not merely to acceptance.
- it("does not refocus a reply box whose mid-flight draft was kept", async () => {
+ it("does not blur a reply box whose mid-flight draft was kept", async () => {
let resolveSubmit!: (v: boolean) => void;
const onSubmit = vi.fn(() => new Promise<boolean>((r) => { resolveSubmit = r; }));
renderReplyInput({ onSubmit, draftKey: "reply:issue-1:comment-1" });
@@ -776,6 +778,7 @@ describe("comment composers", () => {
"reply A plus more",
);
await new Promise((resolve) => requestAnimationFrame(() => resolve(null)));
+ expect(focusCalls.blurred).toBe(0);
expect(focusCalls.focused).toBe(0);
});
diff --git a/packages/views/issues/components/comment-input.tsx b/packages/views/issues/components/comment-input.tsx
index 06b9abf7f8..10cee585cb 100644
--- a/packages/views/issues/components/comment-input.tsx
+++ b/packages/views/issues/components/comment-input.tsx
@@ -166,7 +166,7 @@ function CommentInput({ issueId, onSubmit, onAccepted, onEditAnnotation }: Comme
},
// A top-level comment ends a turn: the caret is dropped rather than kept,
// so the composer stops reading as "still writing" once the comment is
- // posted above it. Thread replies are the opposite — see ReplyInput.
+ // posted above it. Thread replies do the same — see ReplyInput.
afterAccepted: () => (editorScrubbedRef.current ? "blur" : "none"),
onSubmit: async (content) => {
editorScrubbedRef.current = false;
diff --git a/packages/views/issues/components/reply-input.tsx b/packages/views/issues/components/reply-input.tsx
index a145334775..d66c1ce4e3 100644
--- a/packages/views/issues/components/reply-input.tsx
+++ b/packages/views/issues/components/reply-input.tsx
@@ -162,17 +162,15 @@ function ReplyInput({
const { submitting, submit } = useComposerSubmit({
editorRef,
uploadGate: gate,
- containerRef: composerRef,
normalize: (raw) => {
const current = draftKey ? useCommentDraftStore.getState().getAnnotations(draftKey) : EMPTY_REPLY_ANNOTATIONS;
return !targetMissing && hasReplyIntent(raw, current) ? composeAnnotatedReply(raw, current) : "";
},
- // A thread reply is rarely the last thing the user has to say, so the caret
- // stays in the box for the next one. Unlike a top-level comment, the posted
- // reply lands directly above the box that is still focused — nothing needs
- // to pull the eye elsewhere. `containerRef` keeps this from stealing focus
- // if the user moved to another composer while the reply was in flight.
- afterAccepted: () => (editorScrubbedRef.current ? "refocus" : "none"),
+ // Drop the caret once the reply is posted, same as a top-level comment: a
+ // focused editor swallows the page's keyboard shortcuts, so keeping it here
+ // would trap the user until they click away. Bound to `editorScrubbedRef`
+ // so a draft the stale-submit guard kept stays focused.
+ afterAccepted: () => (editorScrubbedRef.current ? "blur" : "none"),
onSubmit: async (content) => {
editorScrubbedRef.current = false;
const { suppressAgentIds, steerTaskIds } = routing;