From 451e0956e73fc26c7f770cd2b427ca8497de128c Mon Sep 17 00:00:00 2001 From: Tony <97451137+TonybynMp4@users.noreply.github.com> Date: Wed, 11 Nov 2026 18:09:53 +0100 Subject: [PATCH 01/17] feat(web): reply to review threads and quote comments from the PR Summary tab Co-Authored-By: Claude Opus 5.5 --- .../pullRequest/PullRequestCommentForm.tsx | 27 +++ .../pullRequest/PullRequestComposer.tsx | 11 +- .../pullRequest/PullRequestDetailPanel.tsx | 6 + .../PullRequestReviewAnnotation.tsx | 187 +++++++++++------- .../pullRequest/PullRequestSummaryTab.tsx | 69 +++++++ .../pullRequestDetail.logic.test.ts | 14 ++ .../pullRequest/pullRequestDetail.logic.ts | 13 ++ 7 files changed, 254 insertions(+), 73 deletions(-) diff --git a/apps/web/src/components/pullRequest/PullRequestCommentForm.tsx b/apps/web/src/components/pullRequest/PullRequestCommentForm.tsx index b56dc413f1ab4..0c0c3008b2642 100644 --- a/apps/web/src/components/pullRequest/PullRequestCommentForm.tsx +++ b/apps/web/src/components/pullRequest/PullRequestCommentForm.tsx @@ -22,6 +22,9 @@ import { useInlineActionConfirm } from "./useInlineActionConfirm"; import { changeRequestTermKind } from "./changeRequestTerm"; +/** A fresh object each time, so quoting the same comment twice still lands. */ +export type PullRequestQuoteRequest = { readonly text: string }; + export function PullRequestCommentForm({ environmentId, active, @@ -29,6 +32,7 @@ export function PullRequestCommentForm({ detail, actionPending, textareaRef, + quoteRequest, onCommentAction, onCommented, onClose, @@ -40,6 +44,7 @@ export function PullRequestCommentForm({ detail: PullRequestDetailView; actionPending: boolean; textareaRef: RefObject; + quoteRequest?: PullRequestQuoteRequest | undefined; onCommentAction: ( body: string, action: "close" | "reopen", @@ -49,6 +54,28 @@ export function PullRequestCommentForm({ }) { const gt = useGT(); const [body, setBody] = useState(""); + const [answeredQuoteRequest, setAnsweredQuoteRequest] = useState(quoteRequest); + const [caretAfterQuote, setCaretAfterQuote] = useState(false); + if (quoteRequest !== answeredQuoteRequest) { + setAnsweredQuoteRequest(quoteRequest); + if (quoteRequest) { + setBody((draft) => + draft.trim().length === 0 + ? quoteRequest.text + : `${draft.trimEnd()}\n\n${quoteRequest.text}`, + ); + setCaretAfterQuote(true); + } + } + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- moves the DOM caret after a quote the textarea just received + useEffect(() => { + const textarea = textareaRef.current; + if (!caretAfterQuote || !textarea) return; + setCaretAfterQuote(false); + textarea.focus({ preventScroll: true }); + textarea.setSelectionRange(textarea.value.length, textarea.value.length); + textarea.scrollTop = textarea.scrollHeight; + }, [caretAfterQuote, textareaRef]); const [submitting, setSubmitting] = useState<"comment" | "close" | "reopen" | null>(null); const locked = submitting !== null || actionPending; const speech = useTextFieldSpeech({ diff --git a/apps/web/src/components/pullRequest/PullRequestComposer.tsx b/apps/web/src/components/pullRequest/PullRequestComposer.tsx index e59580d43bddd..e4466b5407ba2 100644 --- a/apps/web/src/components/pullRequest/PullRequestComposer.tsx +++ b/apps/web/src/components/pullRequest/PullRequestComposer.tsx @@ -7,7 +7,7 @@ import { useRef, useState } from "react"; import { Button } from "../ui/button"; import { Popover, PopoverClose, PopoverPopup, PopoverTitle, PopoverTrigger } from "../ui/popover"; import { Toggle, ToggleGroup } from "../ui/toggle-group"; -import { PullRequestCommentForm } from "./PullRequestCommentForm"; +import { PullRequestCommentForm, type PullRequestQuoteRequest } from "./PullRequestCommentForm"; import { PullRequestReviewForm } from "./PullRequestReviewForm"; import { pullRequestReviewKey, @@ -27,6 +27,7 @@ export function PullRequestComposer({ onCommented, onReviewSubmitted, openReviewRequest, + quoteRequest, }: { environmentId: EnvironmentId; reference: PullRequestRef; @@ -39,6 +40,7 @@ export function PullRequestComposer({ onCommented: () => void; onReviewSubmitted: () => void; openReviewRequest?: number | undefined; + quoteRequest?: PullRequestQuoteRequest | undefined; }) { const gt = useGT(); const term = changeRequestTermKind(sourceControlClients.get(detail.provider).changeRequest); @@ -61,6 +63,12 @@ export function PullRequestComposer({ setRequestedMode("review"); setOpen(true); } + const [answeredQuoteRequest, setAnsweredQuoteRequest] = useState(quoteRequest); + if (quoteRequest !== answeredQuoteRequest) { + setAnsweredQuoteRequest(quoteRequest); + setRequestedMode("comment"); + setOpen(true); + } const canComment = detail.capabilities.comment && detail.viewerPermissions.comment; const verdicts = detail.capabilities.review.verdicts.filter((verdict) => @@ -205,6 +213,7 @@ export function PullRequestComposer({ detail={detail} actionPending={actionPending} textareaRef={commentRef} + quoteRequest={quoteRequest} onCommentAction={onCommentAction} onCommented={onCommented} onClose={() => setOpen(false)} diff --git a/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx b/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx index d0ad2e02f8e12..250d9a9a178ef 100644 --- a/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx +++ b/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx @@ -114,6 +114,7 @@ import { openOnHostLabel } from "./pullRequestLinkContextMenu"; import { PullRequestMarkdownContext } from "./PullRequestMarkdown"; import { pullRequestMarkdownPlugins } from "./pullRequestMarkdown.logic"; import { PullRequestComposer } from "./PullRequestComposer"; +import type { PullRequestQuoteRequest } from "./PullRequestCommentForm"; import { PullRequestSummaryTab } from "./PullRequestSummaryTab"; import { PullRequestTimelineTab } from "./PullRequestTimelineTab"; import { @@ -433,6 +434,7 @@ export function PullRequestDetailPanel({ useEnvironmentQuery(pullRequestEnvironment.changeBreakdown({ environmentId, input: reference })); const [threadPickerOpen, setThreadPickerOpen] = useState(false); const [openReviewRequest, setOpenReviewRequest] = useState(0); + const [quoteRequest, setQuoteRequest] = useState(); const { canWriteSourceControl, detailQuery, @@ -2096,6 +2098,9 @@ export function PullRequestDetailPanel({ fixCheckLabel={handoffLabels.fixCheck} {...(canFixFindings ? { onFixFinding: startFixFinding } : {})} {...(attachTarget === null ? {} : { onAddToChat: addCommentToChat })} + {...(detail.capabilities.comment && detail.viewerPermissions.comment + ? { onQuoteReply: (text: string) => setQuoteRequest({ text }) } + : {})} onRefresh={refreshDetail} onRefreshChecks={refreshFromHost} /> @@ -2217,6 +2222,7 @@ export function PullRequestDetailPanel({ onCommented={refreshDetail} onReviewSubmitted={refreshDetail} openReviewRequest={openReviewRequest} + quoteRequest={quoteRequest} /> ) : null} diff --git a/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx b/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx index 91cb4d5863db5..34f1261e65e4a 100644 --- a/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx +++ b/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx @@ -233,12 +233,8 @@ export function ReviewThreadCard({ }) { const gt = useGT(); const [expanded, setExpanded] = useState(hidden !== undefined || !thread.isResolved); - const [replying, setReplying] = useState(false); - const [reply, setReply] = useState(""); const [editingId, setEditingId] = useState(null); const [savingEdit, setSavingEdit] = useState(false); - const sendingRef = useRef(false); - const replyRef = useRef(null); const [loadedPage, setLoadedPage] = useState< (PullRequestThreadCommentsResult & { readonly threadId: string }) | null >(null); @@ -267,15 +263,8 @@ export function ReviewThreadCard({ } }; - const send = async (text: string) => { - const trimmed = text.trim(); - if (trimmed.length === 0 || pending || sendingRef.current) return; - sendingRef.current = true; - const result = await settlePromise(() => onReply(trimmed)); - sendingRef.current = false; - if (result._tag === "Failure") throw squashAtomCommandFailure(result); - if (!result.value) return; - // Replies return no comment; retain loaded data and reopen pagination for a later read. + // Replies return no comment; retain loaded data and reopen pagination for a later read. + const keepLoadedPage = () => setLoadedPage((previous) => previous?.threadId === thread.id ? { @@ -284,9 +273,6 @@ export function ReviewThreadCard({ } : previous, ); - setReply(""); - setReplying(false); - }; const loadMore = async () => { if (nextCommentsCursor === null || loadingMore) return; setLoadingMore(true); @@ -435,65 +421,122 @@ export function ReviewThreadCard({ ) : null} {canReply ? ( - replying ? ( - - {(speech) => ( -
- speech.submitAfterDictation((text) => void send(text)), - onCancel: () => - speech.state.phase === "idle" ? setReplying(false) : speech.cancel(), - })} - /> -
- - - -
-
- )} -
- ) : ( - - ) + ) : null} ) : null} ); } + +export function PullRequestThreadReplyForm({ + environmentId, + reference, + threadId, + completionScope, + pending, + className, + onReply, + onSent, +}: { + environmentId: EnvironmentId; + reference: PullRequestRef; + threadId: string; + completionScope: PullRequestCompletionScope | null; + pending: boolean; + className?: string; + onReply: (body: string) => Promise; + onSent?: () => void; +}) { + const [replying, setReplying] = useState(false); + const [reply, setReply] = useState(""); + const sendingRef = useRef(false); + const replyRef = useRef(null); + const gt = useGT(); + + const send = async (text: string) => { + const trimmed = text.trim(); + if (trimmed.length === 0 || pending || sendingRef.current) return; + sendingRef.current = true; + const result = await settlePromise(() => onReply(trimmed)); + sendingRef.current = false; + if (result._tag === "Failure") throw squashAtomCommandFailure(result); + if (!result.value) return; + onSent?.(); + setReply(""); + setReplying(false); + }; + + if (!replying) { + return ( + + ); + } + return ( + + {(speech) => ( +
+ speech.submitAfterDictation((text) => void send(text)), + onCancel: () => + speech.state.phase === "idle" ? setReplying(false) : speech.cancel(), + })} + /> +
+ + + +
+
+ )} +
+ ); +} diff --git a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx index 0e8a530c5bebb..6485257387c22 100644 --- a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx +++ b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx @@ -20,6 +20,7 @@ import { HammerIcon, ListFilterIcon, MessageSquarePlusIcon, + ReplyIcon, TagIcon, UsersIcon, } from "lucide-react"; @@ -73,6 +74,7 @@ import { pullRequestConversationItemComments, pullRequestConversationItems, pullRequestFindingKey, + pullRequestQuoteReply, pullRequestReviewOutcome, visibleBody, type PullRequestChatSubject, @@ -99,6 +101,7 @@ import { import { PullRequestReactionBar } from "./PullRequestReactions"; import { canReactPullRequestComment } from "@t3tools/client-runtime/pull-request-reactions"; import { PullRequestResolveThreadButton } from "./PullRequestResolveThreadButton"; +import { PullRequestThreadReplyForm } from "./PullRequestReviewAnnotation"; import { PullRequestConversationGhost } from "./PullRequestGhosts"; import { sectionCollapseAnchorScrollTop } from "./pullRequestSummaryScroll.logic"; @@ -290,6 +293,7 @@ function CollapsedComment({ replyCount = 0, replies = null, moreReplies = null, + replyForm = null, onAddToChat, }: { comment: PullRequestComment; @@ -303,6 +307,7 @@ function CollapsedComment({ replyCount?: number; replies?: ReactNode; moreReplies?: ReactNode; + replyForm?: ReactNode; onAddToChat?: (() => void) | undefined; }) { const gt = useGT(); @@ -353,6 +358,7 @@ function CollapsedComment({ )} {replies ?
{replies}
: null} + {replyForm} ) : null} @@ -481,6 +487,7 @@ export function PullRequestSummaryTab({ fixCheckLabel: requestedFixCheckLabel, onFixFinding, onAddToChat, + onQuoteReply, onRefresh, onRefreshChecks = onRefresh, }: { @@ -501,6 +508,8 @@ export function PullRequestSummaryTab({ onFixFinding?: (finding: PullRequestFinding) => void; /** Absent where there is no composer beside the panel to add a remark to. */ onAddToChat?: (subject: PullRequestChatSubject) => void; + /** Absent when the viewer cannot comment; opens the composer with the comment quoted. */ + onQuoteReply?: (quote: string) => void; onRefresh: () => void; onRefreshChecks?: () => void; }) { @@ -701,6 +710,37 @@ export function PullRequestSummaryTab({ }; const completionScope = pullRequestCompletionScope(detail, environmentId, reference); + const replyToThread = useAtomCommand(pullRequestEnvironment.replyToThread, { + reportFailure: false, + }); + const [threadReplyPending, setThreadReplyPending] = useState(false); + const canReplyToThreads = detail.capabilities.review.reply && detail.viewerPermissions.comment; + const sendThreadReply = async (threadId: string, body: string) => { + if (threadReplyPending) return false; + setThreadReplyPending(true); + const result = await replyToThread({ environmentId, input: { ...reference, threadId, body } }); + setThreadReplyPending(false); + if (result._tag === "Failure") { + toastManager.add({ type: "error", title: "Reply could not be posted" }); + return false; + } + onRefresh(); + return true; + }; + const threadReplyForm = (thread: PullRequestConversationThread, className?: string) => + canReplyToThreads ? ( + sendThreadReply(thread.id, body)} + /> + ) : null; const commentEditing: CommentEditing = { cwd: detail.workspaceRoot, environmentId, @@ -770,6 +810,8 @@ export function PullRequestSummaryTab({ : { kind: "thread", thread }; // A reply goes with its conversation, from the card that heads it. const chat = reply ? null : chatSubject(comment, thread); + // Review threads take real replies; anything else can only be answered by quoting it. + const canQuote = onQuoteReply && !reply && thread === undefined && body !== null; return (
onAddToChat(chat)} /> ) : null} + {onQuoteReply && canQuote ? ( + + ) : null} {reactionBarFor(comment)} {reply ? null : ( @@ -849,6 +916,7 @@ export function PullRequestSummaryTab({ replyCount={item.kind === "thread" ? item.replies.length + item.moreReplies : 0} replies={replies} moreReplies={moreReplies} + replyForm={thread ? threadReplyForm(thread) : null} onAddToChat={onAddToChat && chat !== null ? () => onAddToChat(chat) : undefined} reactionBar={reactionBarFor(comment)} resolveButton={resolveButtonFor(thread)} @@ -861,6 +929,7 @@ export function PullRequestSummaryTab({ {renderCommentCard(comment, thread)} {replies} {moreReplies} + {thread ? threadReplyForm(thread, "mt-0") : null} ); }; diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts index 4f25b26f3276e..24d4b2c92d405 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts @@ -60,6 +60,7 @@ import { pullRequestLinkSubject, writePullRequestDetailSnapshot, readableFailure, + pullRequestQuoteReply, } from "./pullRequestDetail.logic"; import type { ReviewCommentContext } from "~/reviewCommentContext"; @@ -552,6 +553,19 @@ describe("review thread conversations", () => { comments: [lastReply, { ...finding, body: "Stale finding" }, reply], }; + it("quotes a comment without its hidden markup and mentions a bot by its handle", () => { + expect( + pullRequestQuoteReply({ + ...finding, + body: "\r\nFirst line\r\n\r\nSecond line", + }), + ).toBe("> First line\n>\n> Second line\n\n@review "); + expect(pullRequestQuoteReply({ ...loose, author: null, body: "Hi" })).toBe("> Hi\n\n"); + expect(pullRequestQuoteReply({ ...loose, author: null }, " picked\nlines ")).toBe( + "> picked\n> lines\n\n", + ); + }); + it("keeps a timeline finding and its replies in one row at the finding time", () => { const events = buildPullRequestTimeline({ ...TIMELINE_SOURCE, diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts index 238038730b93f..1fb9302163e1d 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -548,6 +548,19 @@ export function visibleBody(body: string): string | null { return body.replace(//gu, "").trim().length === 0 ? null : body.trim(); } +/** Quotes `selection` when the reader picked part of the comment, else the whole body. */ +export function pullRequestQuoteReply(comment: PullRequestComment, selection?: string): string { + const quote = (selection?.trim() || comment.body) + .replace(//gu, "") + .trim() + .split(/\r?\n/u) + .map((line) => (line.trim().length === 0 ? ">" : `> ${line}`)) + .join("\n"); + // GitHub bot logins carry a "[bot]" suffix that does not resolve as a mention. + const login = comment.author?.login.replace(/\[bot\]$/u, ""); + return `${quote}\n\n${login ? `@${login} ` : ""}`; +} + function commentTimelineEvent(comment: PullRequestComment): PullRequestTimelineEvent { return { comment, From 0c2448c301ba98e55acb129ade6a4a14cd264a97 Mon Sep 17 00:00:00 2001 From: Tony <97451137+TonybynMp4@users.noreply.github.com> Date: Wed, 11 Nov 2026 18:22:09 +0100 Subject: [PATCH 02/17] fix(web): keep reply drafts across collapse and quotes made while posting Co-Authored-By: Claude Opus 5.5 --- .../pullRequest/PullRequestCommentForm.tsx | 7 ++--- .../PullRequestReviewAnnotation.tsx | 26 ++++++++++--------- .../pullRequest/PullRequestSummaryTab.tsx | 9 +++++-- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/apps/web/src/components/pullRequest/PullRequestCommentForm.tsx b/apps/web/src/components/pullRequest/PullRequestCommentForm.tsx index 0c0c3008b2642..8fadb460726a5 100644 --- a/apps/web/src/components/pullRequest/PullRequestCommentForm.tsx +++ b/apps/web/src/components/pullRequest/PullRequestCommentForm.tsx @@ -54,9 +54,12 @@ export function PullRequestCommentForm({ }) { const gt = useGT(); const [body, setBody] = useState(""); + const [submitting, setSubmitting] = useState<"comment" | "close" | "reopen" | null>(null); + const locked = submitting !== null || actionPending; const [answeredQuoteRequest, setAnsweredQuoteRequest] = useState(quoteRequest); const [caretAfterQuote, setCaretAfterQuote] = useState(false); - if (quoteRequest !== answeredQuoteRequest) { + // A successful post clears the draft, so a quote waits until posting settles. + if (quoteRequest !== answeredQuoteRequest && !locked) { setAnsweredQuoteRequest(quoteRequest); if (quoteRequest) { setBody((draft) => @@ -76,8 +79,6 @@ export function PullRequestCommentForm({ textarea.setSelectionRange(textarea.value.length, textarea.value.length); textarea.scrollTop = textarea.scrollHeight; }, [caretAfterQuote, textareaRef]); - const [submitting, setSubmitting] = useState<"comment" | "close" | "reopen" | null>(null); - const locked = submitting !== null || actionPending; const speech = useTextFieldSpeech({ environmentId, projectId: reference.projectId, diff --git a/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx b/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx index 34f1261e65e4a..cb37498e74885 100644 --- a/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx +++ b/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx @@ -419,20 +419,22 @@ export function ReviewThreadCard({ ) : null} - - {canReply ? ( - - ) : null} ) : null} + {/* Stays mounted while collapsed so an unsent reply survives. */} + {canReply ? ( + + ) : null} ); } diff --git a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx index 6485257387c22..3fb5b64c0c8fe 100644 --- a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx +++ b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx @@ -358,10 +358,15 @@ function CollapsedComment({ )} {replies ?
{replies}
: null} - {replyForm} ) : null} + {/* Stays mounted while collapsed so an unsent reply survives. */} + {replyForm ? ( + + ) : null} {moreReplies ?
{moreReplies}
: null}
@@ -916,7 +921,7 @@ export function PullRequestSummaryTab({ replyCount={item.kind === "thread" ? item.replies.length + item.moreReplies : 0} replies={replies} moreReplies={moreReplies} - replyForm={thread ? threadReplyForm(thread) : null} + replyForm={thread ? threadReplyForm(thread, "mt-0") : null} onAddToChat={onAddToChat && chat !== null ? () => onAddToChat(chat) : undefined} reactionBar={reactionBarFor(comment)} resolveButton={resolveButtonFor(thread)} From fa6fcf7cde8381b2ef6327505bde0b94a38a92a1 Mon Sep 17 00:00:00 2001 From: Tony <97451137+TonybynMp4@users.noreply.github.com> Date: Wed, 11 Nov 2026 18:28:13 +0100 Subject: [PATCH 03/17] test(web): cover an unsent PR reply surviving collapse Co-Authored-By: Claude Opus 5.5 --- .../PullRequestSummaryTab.browser.test.tsx | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/apps/web/src/components/pullRequest/PullRequestSummaryTab.browser.test.tsx b/apps/web/src/components/pullRequest/PullRequestSummaryTab.browser.test.tsx index 8ecb158a8f2d0..c25d5fa19ddd2 100644 --- a/apps/web/src/components/pullRequest/PullRequestSummaryTab.browser.test.tsx +++ b/apps/web/src/components/pullRequest/PullRequestSummaryTab.browser.test.tsx @@ -202,6 +202,52 @@ it("leaves description checkboxes read-only without the right to edit it", async ); }); +it("keeps an unsent reply when a resolved conversation is collapsed and reopened", async () => { + setup(); + const note = { + author: { login: "reviewer", name: null, avatarUrl: null }, + createdAt: "2026-09-01T00:00:00Z", + url: null, + }; + const body = "Rename this helper"; + const filterKey = "t3code:pull-request-comment-filter:v1"; + localStorage.setItem(filterKey, JSON.stringify({ bots: false, resolved: true })); + using _filter = { [Symbol.dispose]: () => localStorage.removeItem(filterKey) }; + await using screen = await render({ + ...detail, + capabilities: { + ...detail.capabilities, + review: { ...detail.capabilities.review, reply: true }, + }, + comments: [ + { ...note, id: "10", kind: "review-comment", body, path: "src/a.ts", reviewState: null }, + ], + reviewThreads: [ + { + id: "thread", + path: "src/a.ts", + line: 3, + side: "right", + isResolved: true, + isOutdated: false, + comments: [{ ...note, id: "10", body }], + }, + ], + }); + const status = screen.getByRole("button", { name: "Resolved" }); + + await userEvent.click(status); + await userEvent.click(screen.getByRole("button", { name: "Reply" })); + await userEvent.type(screen.getByLabelText("Reply to this conversation"), "Unsent reply"); + await userEvent.click(status); + await expect.element(screen.getByLabelText("Reply to this conversation")).not.toBeVisible(); + await userEvent.click(status); + + await expect + .element(screen.getByLabelText("Reply to this conversation")) + .toHaveValue("Unsent reply"); +}); + it("fixes an overview thread as its opening remark, since it has no line to attach", async () => { setup(); const author = { login: "reviewer", name: null, avatarUrl: null }; From 1e8437317bbaee760ded881c9ad1219369a1513d Mon Sep 17 00:00:00 2001 From: Tony <97451137+TonybynMp4@users.noreply.github.com> Date: Wed, 11 Nov 2026 18:30:20 +0100 Subject: [PATCH 04/17] fix(web): keep HTML comments written inside code when quoting Co-Authored-By: Claude Opus 5.5 --- .../pullRequest/PullRequestReviewAnnotation.tsx | 13 +++++-------- .../pullRequest/pullRequestDetail.logic.test.ts | 7 +++++++ .../pullRequest/pullRequestDetail.logic.ts | 3 ++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx b/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx index cb37498e74885..c0875798496e7 100644 --- a/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx +++ b/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx @@ -479,14 +479,11 @@ export function PullRequestThreadReplyForm({ if (!replying) { return ( - +
+ +
); } return ( diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts index 24d4b2c92d405..ca38c1f4dd276 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts @@ -564,6 +564,13 @@ describe("review thread conversations", () => { expect(pullRequestQuoteReply({ ...loose, author: null }, " picked\nlines ")).toBe( "> picked\n> lines\n\n", ); + expect( + pullRequestQuoteReply({ + ...loose, + author: null, + body: "Use ``:\n```html\n\n```", + }), + ).toBe("> Use ``:\n> ```html\n> \n> ```\n\n"); }); it("keeps a timeline finding and its replies in one row at the finding time", () => { diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts index 1fb9302163e1d..49fda94724c83 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -551,7 +551,8 @@ export function visibleBody(body: string): string | null { /** Quotes `selection` when the reader picked part of the comment, else the whole body. */ export function pullRequestQuoteReply(comment: PullRequestComment, selection?: string): string { const quote = (selection?.trim() || comment.body) - .replace(//gu, "") + // Drops hidden HTML comments, but keeps ones written inside code as examples. + .replace(/(```[\s\S]*?```|`[^`\n]*`)|/gu, (_, code?: string) => code ?? "") .trim() .split(/\r?\n/u) .map((line) => (line.trim().length === 0 ? ">" : `> ${line}`)) From c7400b13ca04115f24a842bc84a96c1ce838b3e9 Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Wed, 11 Nov 2026 20:36:23 +0000 Subject: [PATCH 05/17] fix(web): preserve visible code in selected PR quotes --- .../pullRequest/pullRequestDetail.logic.test.ts | 3 +++ .../components/pullRequest/pullRequestDetail.logic.ts | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts index ca38c1f4dd276..3dbe10adfa6a0 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts @@ -564,6 +564,9 @@ describe("review thread conversations", () => { expect(pullRequestQuoteReply({ ...loose, author: null }, " picked\nlines ")).toBe( "> picked\n> lines\n\n", ); + expect(pullRequestQuoteReply({ ...loose, author: null }, "")).toBe( + "> \n\n", + ); expect( pullRequestQuoteReply({ ...loose, diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts index 49fda94724c83..c23ddf1c16340 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -550,9 +550,13 @@ export function visibleBody(body: string): string | null { /** Quotes `selection` when the reader picked part of the comment, else the whole body. */ export function pullRequestQuoteReply(comment: PullRequestComment, selection?: string): string { - const quote = (selection?.trim() || comment.body) - // Drops hidden HTML comments, but keeps ones written inside code as examples. - .replace(/(```[\s\S]*?```|`[^`\n]*`)|/gu, (_, code?: string) => code ?? "") + const body = + selection?.trim() || + comment.body.replace( + /(```[\s\S]*?```|`[^`\n]*`)|/gu, + (_, code?: string) => code ?? "", + ); + const quote = body .trim() .split(/\r?\n/u) .map((line) => (line.trim().length === 0 ? ">" : `> ${line}`)) From 97c4f6fdd0f61e1d68f74448082542a250c410f1 Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Wed, 11 Nov 2026 20:55:28 +0000 Subject: [PATCH 06/17] fix(web): escape selected PR quote text for rendering --- .../components/pullRequest/pullRequestDetail.logic.test.ts | 5 ++++- .../src/components/pullRequest/pullRequestDetail.logic.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts index 3dbe10adfa6a0..ac10602164170 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts @@ -565,7 +565,10 @@ describe("review thread conversations", () => { "> picked\n> lines\n\n", ); expect(pullRequestQuoteReply({ ...loose, author: null }, "")).toBe( - "> \n\n", + "> \\<\\!\\-\\- keep \\-\\-\\>\n\n", + ); + expect(pullRequestQuoteReply({ ...loose, author: null }, "# Heading")).toBe( + "> \\# Heading\n\n", ); expect( pullRequestQuoteReply({ diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts index c23ddf1c16340..30c40fb4692e4 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -551,7 +551,7 @@ export function visibleBody(body: string): string | null { /** Quotes `selection` when the reader picked part of the comment, else the whole body. */ export function pullRequestQuoteReply(comment: PullRequestComment, selection?: string): string { const body = - selection?.trim() || + selection?.trim().replace(/[\\`*_[\]{}()#+.!|~<>-]/gu, "\\$&") || comment.body.replace( /(```[\s\S]*?```|`[^`\n]*`)|/gu, (_, code?: string) => code ?? "", From 8e016fd1ce4fd2c25f2bf3805bc637c34b7d38ae Mon Sep 17 00:00:00 2001 From: Tony <97451137+TonybynMp4@users.noreply.github.com> Date: Wed, 11 Nov 2026 22:50:06 +0100 Subject: [PATCH 07/17] fix(web): keep quotes and reply drafts through posts and resolution Quotes made while a comment posts now queue and reopen the composer once the post settles. Thread reply drafts survive resolving, reopening, or filtering. Selected quotes keep indentation and escape ampersands, and hidden comments between escaped backticks are stripped. Co-Authored-By: Claude Opus 5.5 --- .../pullRequest/PullRequestCommentForm.tsx | 29 +++++++++++-------- .../pullRequest/PullRequestComposer.tsx | 4 +++ .../PullRequestReviewAnnotation.tsx | 13 +++++++-- .../pullRequest/PullRequestSummaryTab.tsx | 14 ++++++--- .../pullRequestDetail.logic.test.ts | 8 +++-- .../pullRequest/pullRequestDetail.logic.ts | 19 ++++++++---- 6 files changed, 61 insertions(+), 26 deletions(-) diff --git a/apps/web/src/components/pullRequest/PullRequestCommentForm.tsx b/apps/web/src/components/pullRequest/PullRequestCommentForm.tsx index 8fadb460726a5..7a90fbecc974c 100644 --- a/apps/web/src/components/pullRequest/PullRequestCommentForm.tsx +++ b/apps/web/src/components/pullRequest/PullRequestCommentForm.tsx @@ -36,6 +36,7 @@ export function PullRequestCommentForm({ onCommentAction, onCommented, onClose, + onQuoted, }: { environmentId: EnvironmentId; /** False while the form stays mounted but hidden; dictation is cancelled then. */ @@ -51,34 +52,38 @@ export function PullRequestCommentForm({ ) => Promise<{ readonly commentPosted: boolean }>; onCommented: () => void; onClose: () => void; + /** A quote deferred past a successful post lands after `onClose`, so the form asks to be shown again. */ + onQuoted: () => void; }) { const gt = useGT(); const [body, setBody] = useState(""); const [submitting, setSubmitting] = useState<"comment" | "close" | "reopen" | null>(null); const locked = submitting !== null || actionPending; const [answeredQuoteRequest, setAnsweredQuoteRequest] = useState(quoteRequest); + const [pendingQuotes, setPendingQuotes] = useState>([]); const [caretAfterQuote, setCaretAfterQuote] = useState(false); - // A successful post clears the draft, so a quote waits until posting settles. - if (quoteRequest !== answeredQuoteRequest && !locked) { + if (quoteRequest !== answeredQuoteRequest) { setAnsweredQuoteRequest(quoteRequest); - if (quoteRequest) { - setBody((draft) => - draft.trim().length === 0 - ? quoteRequest.text - : `${draft.trimEnd()}\n\n${quoteRequest.text}`, - ); - setCaretAfterQuote(true); - } + if (quoteRequest) setPendingQuotes((quotes) => [...quotes, quoteRequest.text]); + } + // A successful post clears the draft, so quotes wait until posting settles. + if (pendingQuotes.length > 0 && !locked) { + setPendingQuotes([]); + setBody((draft) => + [draft.trimEnd(), ...pendingQuotes].filter((part) => part.length > 0).join("\n\n"), + ); + setCaretAfterQuote(true); } - // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- moves the DOM caret after a quote the textarea just received + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- reveals the composer and moves the DOM caret after a quote lands useEffect(() => { const textarea = textareaRef.current; if (!caretAfterQuote || !textarea) return; setCaretAfterQuote(false); + onQuoted(); textarea.focus({ preventScroll: true }); textarea.setSelectionRange(textarea.value.length, textarea.value.length); textarea.scrollTop = textarea.scrollHeight; - }, [caretAfterQuote, textareaRef]); + }, [caretAfterQuote, textareaRef, onQuoted]); const speech = useTextFieldSpeech({ environmentId, projectId: reference.projectId, diff --git a/apps/web/src/components/pullRequest/PullRequestComposer.tsx b/apps/web/src/components/pullRequest/PullRequestComposer.tsx index e4466b5407ba2..da86cc7543bb6 100644 --- a/apps/web/src/components/pullRequest/PullRequestComposer.tsx +++ b/apps/web/src/components/pullRequest/PullRequestComposer.tsx @@ -217,6 +217,10 @@ export function PullRequestComposer({ onCommentAction={onCommentAction} onCommented={onCommented} onClose={() => setOpen(false)} + onQuoted={() => { + setRequestedMode("comment"); + setOpen(true); + }} /> ) : null} diff --git a/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx b/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx index c0875798496e7..5534913652c66 100644 --- a/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx +++ b/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx @@ -446,6 +446,8 @@ export function PullRequestThreadReplyForm({ completionScope, pending, className, + initialReply = "", + onReplyChange, onReply, onSent, }: { @@ -455,11 +457,18 @@ export function PullRequestThreadReplyForm({ completionScope: PullRequestCompletionScope | null; pending: boolean; className?: string; + /** Lets a parent keep the draft when this form remounts elsewhere. */ + initialReply?: string; + onReplyChange?: (reply: string) => void; onReply: (body: string) => Promise; onSent?: () => void; }) { - const [replying, setReplying] = useState(false); - const [reply, setReply] = useState(""); + const [replying, setReplying] = useState(initialReply.length > 0); + const [reply, setReplyState] = useState(initialReply); + const setReply = (next: string) => { + setReplyState(next); + onReplyChange?.(next); + }; const sendingRef = useRef(false); const replyRef = useRef(null); const gt = useGT(); diff --git a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx index 3fb5b64c0c8fe..2a840c43abbf9 100644 --- a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx +++ b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx @@ -719,6 +719,8 @@ export function PullRequestSummaryTab({ reportFailure: false, }); const [threadReplyPending, setThreadReplyPending] = useState(false); + // Resolving, reopening, or filtering remounts a reply form; a mutable map keeps keystrokes from re-rendering the tab. + const [replyDrafts] = useState(() => new Map()); const canReplyToThreads = detail.capabilities.review.reply && detail.viewerPermissions.comment; const sendThreadReply = async (threadId: string, body: string) => { if (threadReplyPending) return false; @@ -732,20 +734,24 @@ export function PullRequestSummaryTab({ onRefresh(); return true; }; - const threadReplyForm = (thread: PullRequestConversationThread, className?: string) => - canReplyToThreads ? ( + const threadReplyForm = (thread: PullRequestConversationThread, className?: string) => { + // Host thread ids can collide across pull requests. + const replyKey = `${detail.url}:${thread.id}`; + return canReplyToThreads ? ( replyDrafts.set(replyKey, reply)} onReply={(body) => sendThreadReply(thread.id, body)} /> ) : null; + }; const commentEditing: CommentEditing = { cwd: detail.workspaceRoot, environmentId, diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts index ac10602164170..d73f88b8240c1 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts @@ -561,9 +561,10 @@ describe("review thread conversations", () => { }), ).toBe("> First line\n>\n> Second line\n\n@review "); expect(pullRequestQuoteReply({ ...loose, author: null, body: "Hi" })).toBe("> Hi\n\n"); - expect(pullRequestQuoteReply({ ...loose, author: null }, " picked\nlines ")).toBe( - "> picked\n> lines\n\n", + expect(pullRequestQuoteReply({ ...loose, author: null }, "\n picked\n\tlines \n")).toBe( + "> \u00a0\u00a0picked\n> \u00a0\u00a0\u00a0\u00a0lines\n\n", ); + expect(pullRequestQuoteReply({ ...loose, author: null }, "©")).toBe("> \\©\n\n"); expect(pullRequestQuoteReply({ ...loose, author: null }, "")).toBe( "> \\<\\!\\-\\- keep \\-\\-\\>\n\n", ); @@ -577,6 +578,9 @@ describe("review thread conversations", () => { body: "Use ``:\n```html\n\n```", }), ).toBe("> Use ``:\n> ```html\n> \n> ```\n\n"); + expect( + pullRequestQuoteReply({ ...loose, author: null, body: "Not code \\`\\`" }), + ).toBe("> Not code \\`\\`\n\n"); }); it("keeps a timeline finding and its replies in one row at the finding time", () => { diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts index 30c40fb4692e4..12d3cdc317135 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -550,14 +550,21 @@ export function visibleBody(body: string): string | null { /** Quotes `selection` when the reader picked part of the comment, else the whole body. */ export function pullRequestQuoteReply(comment: PullRequestComment, selection?: string): string { + // Selected text is what the reader saw, so it is escaped to render literally. Blockquotes + // drop leading spaces, so its indentation becomes non-breaking spaces. + const selected = selection + ?.replace(/^\s*\n|\s+$/gu, "") + .replace(/[\\`*_[\]{}()#+.!|~<>&-]/gu, "\\$&") + .replace(/^[ \t]+/gmu, (indent) => indent.replace(/\t/gu, " ").replace(/ /gu, "\u00a0")); const body = - selection?.trim().replace(/[\\`*_[\]{}()#+.!|~<>-]/gu, "\\$&") || - comment.body.replace( - /(```[\s\S]*?```|`[^`\n]*`)|/gu, - (_, code?: string) => code ?? "", - ); + selected || + comment.body + .replace( + /(\\[\s\S]|```[\s\S]*?```|`[^`\n]*`)|/gu, + (_, kept?: string) => kept ?? "", + ) + .trim(); const quote = body - .trim() .split(/\r?\n/u) .map((line) => (line.trim().length === 0 ? ">" : `> ${line}`)) .join("\n"); From 8e87977557e66ebd1b32bf6ee45650b66eacf5b1 Mon Sep 17 00:00:00 2001 From: Tony <97451137+TonybynMp4@users.noreply.github.com> Date: Wed, 11 Nov 2026 23:16:38 +0100 Subject: [PATCH 08/17] fix(web): clear a remounted thread reply once its post succeeds Thread reply drafts now live in the review store, so the mounted form reads the live draft and a successful post clears it wherever the form is now shown. Co-Authored-By: Claude Opus 5.5 --- .../PullRequestReviewAnnotation.tsx | 26 +++++++++---------- .../pullRequest/PullRequestSummaryTab.tsx | 14 +++------- .../pullRequestReviewStore.test.ts | 8 +++++- .../pullRequest/pullRequestReviewStore.ts | 16 ++++++++++++ 4 files changed, 40 insertions(+), 24 deletions(-) diff --git a/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx b/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx index 5534913652c66..629b681c7bf72 100644 --- a/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx +++ b/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx @@ -37,7 +37,11 @@ import { PullRequestActorAvatar, PullRequestActorLabel } from "./pullRequestPres import { PullRequestMarkdown } from "./PullRequestMarkdown"; import { PullRequestMarkdownEditor } from "./PullRequestMarkdownEditor"; import { PullRequestReactionBar } from "./PullRequestReactions"; -import type { PendingReviewComment } from "./pullRequestReviewStore"; +import { + pullRequestThreadReplyKey, + usePullRequestReviewStore, + type PendingReviewComment, +} from "./pullRequestReviewStore"; import { PullRequestMarkdownTextarea, type PullRequestCompletionScope, @@ -446,8 +450,6 @@ export function PullRequestThreadReplyForm({ completionScope, pending, className, - initialReply = "", - onReplyChange, onReply, onSent, }: { @@ -457,18 +459,16 @@ export function PullRequestThreadReplyForm({ completionScope: PullRequestCompletionScope | null; pending: boolean; className?: string; - /** Lets a parent keep the draft when this form remounts elsewhere. */ - initialReply?: string; - onReplyChange?: (reply: string) => void; onReply: (body: string) => Promise; onSent?: () => void; }) { - const [replying, setReplying] = useState(initialReply.length > 0); - const [reply, setReplyState] = useState(initialReply); - const setReply = (next: string) => { - setReplyState(next); - onReplyChange?.(next); - }; + // Resolving, reopening, or filtering remounts the form, so the draft lives in the store. + const replyKey = pullRequestThreadReplyKey(reference, threadId); + const reply = usePullRequestReviewStore((store) => store.replies[replyKey] ?? ""); + const storeReply = usePullRequestReviewStore((store) => store.setReply); + const clearReply = usePullRequestReviewStore((store) => store.clearReply); + const setReply = (next: string) => storeReply(replyKey, next); + const [replying, setReplying] = useState(reply.length > 0); const sendingRef = useRef(false); const replyRef = useRef(null); const gt = useGT(); @@ -482,7 +482,7 @@ export function PullRequestThreadReplyForm({ if (result._tag === "Failure") throw squashAtomCommandFailure(result); if (!result.value) return; onSent?.(); - setReply(""); + clearReply(replyKey, trimmed); setReplying(false); }; diff --git a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx index 2a840c43abbf9..3fb5b64c0c8fe 100644 --- a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx +++ b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx @@ -719,8 +719,6 @@ export function PullRequestSummaryTab({ reportFailure: false, }); const [threadReplyPending, setThreadReplyPending] = useState(false); - // Resolving, reopening, or filtering remounts a reply form; a mutable map keeps keystrokes from re-rendering the tab. - const [replyDrafts] = useState(() => new Map()); const canReplyToThreads = detail.capabilities.review.reply && detail.viewerPermissions.comment; const sendThreadReply = async (threadId: string, body: string) => { if (threadReplyPending) return false; @@ -734,24 +732,20 @@ export function PullRequestSummaryTab({ onRefresh(); return true; }; - const threadReplyForm = (thread: PullRequestConversationThread, className?: string) => { - // Host thread ids can collide across pull requests. - const replyKey = `${detail.url}:${thread.id}`; - return canReplyToThreads ? ( + const threadReplyForm = (thread: PullRequestConversationThread, className?: string) => + canReplyToThreads ? ( replyDrafts.set(replyKey, reply)} onReply={(body) => sendThreadReply(thread.id, body)} /> ) : null; - }; const commentEditing: CommentEditing = { cwd: detail.workspaceRoot, environmentId, diff --git a/apps/web/src/components/pullRequest/pullRequestReviewStore.test.ts b/apps/web/src/components/pullRequest/pullRequestReviewStore.test.ts index 2ba71f34eb080..9772ed785fdd2 100644 --- a/apps/web/src/components/pullRequest/pullRequestReviewStore.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestReviewStore.test.ts @@ -54,12 +54,18 @@ describe("pull request review drafts", () => { expect(usePullRequestReviewStore.getState().summaries[publicKey]).toBe("Public review"); }); - it("does not clear a summary revised while submission is in flight", () => { + it("does not clear a summary or reply revised while submission is in flight", () => { const store = usePullRequestReviewStore.getState(); store.setSummary("review-a", "Submitted body"); usePullRequestReviewStore.getState().setSummary("review-a", "Revised body"); usePullRequestReviewStore.getState().clearSummary("review-a", "Submitted body"); expect(usePullRequestReviewStore.getState().summaries["review-a"]).toBe("Revised body"); + + store.setReply("reply-a", "Revised reply"); + store.clearReply("reply-a", "Sent reply"); + expect(usePullRequestReviewStore.getState().replies["reply-a"]).toBe("Revised reply"); + store.clearReply("reply-a", "Revised reply"); + expect(usePullRequestReviewStore.getState().replies["reply-a"]).toBeUndefined(); }); }); diff --git a/apps/web/src/components/pullRequest/pullRequestReviewStore.ts b/apps/web/src/components/pullRequest/pullRequestReviewStore.ts index d48695ed8f5a2..03e0dc4ede877 100644 --- a/apps/web/src/components/pullRequest/pullRequestReviewStore.ts +++ b/apps/web/src/components/pullRequest/pullRequestReviewStore.ts @@ -23,12 +23,16 @@ export function pullRequestReviewKey(reference: PullRequestRef): string { interface PullRequestReviewStoreState { readonly drafts: Readonly>>; readonly summaries: Readonly>; + /** Unsent thread replies, so a reply form that remounts elsewhere reads the live draft. */ + readonly replies: Readonly>; readonly addComment: (key: string, comment: PendingReviewComment) => void; readonly removeComment: (key: string, commentId: string) => void; readonly removeComments: (key: string, commentIds: ReadonlyArray) => void; readonly clear: (key: string) => void; readonly setSummary: (key: string, body: string) => void; readonly clearSummary: (key: string, submittedBody: string) => void; + readonly setReply: (key: string, body: string) => void; + readonly clearReply: (key: string, submittedBody: string) => void; } const EMPTY: ReadonlyArray = []; @@ -36,6 +40,7 @@ const EMPTY: ReadonlyArray = []; export const usePullRequestReviewStore = create()((set) => ({ drafts: {}, summaries: {}, + replies: {}, addComment: (key, comment) => set((state) => ({ drafts: { ...state.drafts, [key]: [...(state.drafts[key] ?? EMPTY), comment] }, @@ -68,8 +73,19 @@ export const usePullRequestReviewStore = create()(( const { [key]: _removed, ...rest } = state.summaries; return { summaries: rest }; }), + setReply: (key, body) => set((state) => ({ replies: { ...state.replies, [key]: body } })), + clearReply: (key, submittedBody) => + set((state) => { + if (state.replies[key]?.trim() !== submittedBody) return state; + const { [key]: _removed, ...rest } = state.replies; + return { replies: rest }; + }), })); +export function pullRequestThreadReplyKey(reference: PullRequestRef, threadId: string): string { + return JSON.stringify([pullRequestReviewKey(reference), threadId]); +} + export function usePendingReviewComments( reference: PullRequestRef, ): ReadonlyArray { From bba9fb84dd1daa4594ad8a4b71126177e1a6af77 Mon Sep 17 00:00:00 2001 From: Tony <97451137+TonybynMp4@users.noreply.github.com> Date: Wed, 11 Nov 2026 23:51:38 +0100 Subject: [PATCH 09/17] fix(web): keep a quote made as posting settles, and code in tilde fences A quote that arrived in the same render the comment form unlocked was marked answered but dropped from the draft. Quoting a comment also stripped HTML comments inside ~~~ fenced code. Co-Authored-By: Claude Opus 5.5 --- .../PullRequestCommentForm.browser.test.tsx | 51 +++++++++++++++++++ .../pullRequest/PullRequestCommentForm.tsx | 11 ++-- .../pullRequestDetail.logic.test.ts | 3 ++ .../pullRequest/pullRequestDetail.logic.ts | 2 +- 4 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 apps/web/src/components/pullRequest/PullRequestCommentForm.browser.test.tsx diff --git a/apps/web/src/components/pullRequest/PullRequestCommentForm.browser.test.tsx b/apps/web/src/components/pullRequest/PullRequestCommentForm.browser.test.tsx new file mode 100644 index 0000000000000..dc5f54b4fc84e --- /dev/null +++ b/apps/web/src/components/pullRequest/PullRequestCommentForm.browser.test.tsx @@ -0,0 +1,51 @@ +import { + EnvironmentId, + ProjectId, + SourceControlProviderKind, + type PullRequestDetailView, +} from "@t3tools/contracts"; +import { createRef } from "react"; +import { expect, it, vi } from "vite-plus/test"; + +import { render } from "../../../test/render"; +import { PullRequestCommentForm, type PullRequestQuoteRequest } from "./PullRequestCommentForm"; + +vi.mock("~/speech/useTextFieldSpeech", () => ({ + TextFieldSpeechControls: () => null, + useTextFieldSpeech: () => ({ blocksSubmission: false, cancel: () => {} }), +})); +vi.mock("~/state/use-atom-command", () => ({ useAtomCommand: () => vi.fn() })); +vi.mock(import("~/state/pullRequests"), async (original) => ({ + ...(await original()), + pullRequestEnvironment: { comment: {} } as never, +})); + +const detail = { + provider: SourceControlProviderKind.make("github"), + state: "open", + capabilities: { actions: [] }, + viewerPermissions: { actions: [] }, +} as unknown as PullRequestDetailView; +const reference = { projectId: ProjectId.make("project"), repository: "owner/repo", number: 1 }; + +it("adds a quote that arrives as posting settles along with the ones queued before it", async () => { + const form = (actionPending: boolean, quoteRequest: PullRequestQuoteRequest) => ( + + ); + await using screen = await render(form(true, { text: "> first" })); + await screen.rerender(form(true, { text: "> second" })); + await screen.rerender(form(false, { text: "> third" })); + await expect.element(screen.getByRole("textbox")).toHaveValue("> second\n\n> third"); +}); diff --git a/apps/web/src/components/pullRequest/PullRequestCommentForm.tsx b/apps/web/src/components/pullRequest/PullRequestCommentForm.tsx index 7a90fbecc974c..ea8e4bf467242 100644 --- a/apps/web/src/components/pullRequest/PullRequestCommentForm.tsx +++ b/apps/web/src/components/pullRequest/PullRequestCommentForm.tsx @@ -62,17 +62,18 @@ export function PullRequestCommentForm({ const [answeredQuoteRequest, setAnsweredQuoteRequest] = useState(quoteRequest); const [pendingQuotes, setPendingQuotes] = useState>([]); const [caretAfterQuote, setCaretAfterQuote] = useState(false); + let quotes = pendingQuotes; if (quoteRequest !== answeredQuoteRequest) { setAnsweredQuoteRequest(quoteRequest); - if (quoteRequest) setPendingQuotes((quotes) => [...quotes, quoteRequest.text]); + if (quoteRequest) quotes = [...quotes, quoteRequest.text]; } // A successful post clears the draft, so quotes wait until posting settles. - if (pendingQuotes.length > 0 && !locked) { + if (quotes.length > 0 && !locked) { setPendingQuotes([]); - setBody((draft) => - [draft.trimEnd(), ...pendingQuotes].filter((part) => part.length > 0).join("\n\n"), - ); + setBody((draft) => [draft.trimEnd(), ...quotes].filter((part) => part.length > 0).join("\n\n")); setCaretAfterQuote(true); + } else if (quotes !== pendingQuotes) { + setPendingQuotes(quotes); } // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- reveals the composer and moves the DOM caret after a quote lands useEffect(() => { diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts index d73f88b8240c1..7ef84745db607 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts @@ -578,6 +578,9 @@ describe("review thread conversations", () => { body: "Use ``:\n```html\n\n```", }), ).toBe("> Use ``:\n> ```html\n> \n> ```\n\n"); + expect( + pullRequestQuoteReply({ ...loose, author: null, body: "~~~html\n\n~~~" }), + ).toBe("> ~~~html\n> \n> ~~~\n\n"); expect( pullRequestQuoteReply({ ...loose, author: null, body: "Not code \\`\\`" }), ).toBe("> Not code \\`\\`\n\n"); diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts index 12d3cdc317135..10af724bb8736 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -560,7 +560,7 @@ export function pullRequestQuoteReply(comment: PullRequestComment, selection?: s selected || comment.body .replace( - /(\\[\s\S]|```[\s\S]*?```|`[^`\n]*`)|/gu, + /(\\[\s\S]|```[\s\S]*?```|~~~[\s\S]*?~~~|`[^`\n]*`)|/gu, (_, kept?: string) => kept ?? "", ) .trim(); From a649f06da1278336bf49fc5f449f2b7fc1e79719 Mon Sep 17 00:00:00 2001 From: Tony <97451137+TonybynMp4@users.noreply.github.com> Date: Thu, 12 Nov 2026 09:48:55 +0100 Subject: [PATCH 10/17] test(web): move the late-quote test into the PR summary browser tests Co-Authored-By: Claude Sonnet 5.5 --- .../PullRequestCommentForm.browser.test.tsx | 51 ------------------- .../PullRequestSummaryTab.browser.test.tsx | 25 +++++++++ 2 files changed, 25 insertions(+), 51 deletions(-) delete mode 100644 apps/web/src/components/pullRequest/PullRequestCommentForm.browser.test.tsx diff --git a/apps/web/src/components/pullRequest/PullRequestCommentForm.browser.test.tsx b/apps/web/src/components/pullRequest/PullRequestCommentForm.browser.test.tsx deleted file mode 100644 index dc5f54b4fc84e..0000000000000 --- a/apps/web/src/components/pullRequest/PullRequestCommentForm.browser.test.tsx +++ /dev/null @@ -1,51 +0,0 @@ -import { - EnvironmentId, - ProjectId, - SourceControlProviderKind, - type PullRequestDetailView, -} from "@t3tools/contracts"; -import { createRef } from "react"; -import { expect, it, vi } from "vite-plus/test"; - -import { render } from "../../../test/render"; -import { PullRequestCommentForm, type PullRequestQuoteRequest } from "./PullRequestCommentForm"; - -vi.mock("~/speech/useTextFieldSpeech", () => ({ - TextFieldSpeechControls: () => null, - useTextFieldSpeech: () => ({ blocksSubmission: false, cancel: () => {} }), -})); -vi.mock("~/state/use-atom-command", () => ({ useAtomCommand: () => vi.fn() })); -vi.mock(import("~/state/pullRequests"), async (original) => ({ - ...(await original()), - pullRequestEnvironment: { comment: {} } as never, -})); - -const detail = { - provider: SourceControlProviderKind.make("github"), - state: "open", - capabilities: { actions: [] }, - viewerPermissions: { actions: [] }, -} as unknown as PullRequestDetailView; -const reference = { projectId: ProjectId.make("project"), repository: "owner/repo", number: 1 }; - -it("adds a quote that arrives as posting settles along with the ones queued before it", async () => { - const form = (actionPending: boolean, quoteRequest: PullRequestQuoteRequest) => ( - - ); - await using screen = await render(form(true, { text: "> first" })); - await screen.rerender(form(true, { text: "> second" })); - await screen.rerender(form(false, { text: "> third" })); - await expect.element(screen.getByRole("textbox")).toHaveValue("> second\n\n> third"); -}); diff --git a/apps/web/src/components/pullRequest/PullRequestSummaryTab.browser.test.tsx b/apps/web/src/components/pullRequest/PullRequestSummaryTab.browser.test.tsx index c25d5fa19ddd2..22d7b3dfa2805 100644 --- a/apps/web/src/components/pullRequest/PullRequestSummaryTab.browser.test.tsx +++ b/apps/web/src/components/pullRequest/PullRequestSummaryTab.browser.test.tsx @@ -4,6 +4,7 @@ import { type ClientSettings, } from "@t3tools/contracts"; import { EnvironmentId, ProjectId, type PullRequestDetailView } from "@t3tools/contracts"; +import { createRef } from "react"; import { expect, it, vi } from "vite-plus/test"; import { userEvent } from "vite-plus/test/browser"; @@ -54,6 +55,7 @@ function setup() { } import { act, render as renderUi } from "../../../test/render"; +import { PullRequestCommentForm, type PullRequestQuoteRequest } from "./PullRequestCommentForm"; import { PullRequestSummaryTab } from "./PullRequestSummaryTab"; const detail: PullRequestDetailView = { @@ -316,3 +318,26 @@ it("shows a comment's exact time in the chosen 24-hour clock", async () => { expect(document.querySelector('[data-slot="tooltip-popup"]')?.textContent).toBe(expected), ); }); + +it("adds a quote that arrives as posting settles along with the ones queued before it", async () => { + setup(); + const form = (actionPending: boolean, quoteRequest: PullRequestQuoteRequest) => ( + + ); + await using screen = await renderUi(form(true, { text: "> first" })); + await screen.rerender(form(true, { text: "> second" })); + await screen.rerender(form(false, { text: "> third" })); + await expect.element(screen.getByRole("textbox")).toHaveValue("> second\n\n> third"); +}); From 1a95c835ed6ca9c9d2d5f3b7497bf62fe4c2f9fc Mon Sep 17 00:00:00 2001 From: Tony <97451137+TonybynMp4@users.noreply.github.com> Date: Tue, 17 Nov 2026 12:02:59 +0100 Subject: [PATCH 11/17] test(web): reset stored thread replies between PR Code tab tests A draft left by one test opened the next test's reply form, so its Reply click posted through an unmocked command and failed the run with an unhandled rejection. Co-Authored-By: Claude Sonnet 5.5 --- .../components/pullRequest/PullRequestCodeTab.browser.test.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/web/src/components/pullRequest/PullRequestCodeTab.browser.test.tsx b/apps/web/src/components/pullRequest/PullRequestCodeTab.browser.test.tsx index 4d305c4da66ed..ac0f02e4dcd75 100644 --- a/apps/web/src/components/pullRequest/PullRequestCodeTab.browser.test.tsx +++ b/apps/web/src/components/pullRequest/PullRequestCodeTab.browser.test.tsx @@ -116,6 +116,7 @@ vi.mock(import("~/state/pullRequests"), async (original) => { import { render } from "../../../test/render"; import PullRequestCodeTab from "./PullRequestCodeTab"; +import { usePullRequestReviewStore } from "./pullRequestReviewStore"; const detail: PullRequestDetailView = { provider: SourceControlProviderKind.make("github"), @@ -176,6 +177,7 @@ function setup({ paged }: { paged: boolean }) { mocks.diffCommits = []; mocks.viewedPaths = null; mocks.viewedListeners.clear(); + usePullRequestReviewStore.setState({ replies: {} }); } const tab = ( From a61fb7d048045614e340a84c78319a41e6765de6 Mon Sep 17 00:00:00 2001 From: Tony <97451137+TonybynMp4@users.noreply.github.com> Date: Wed, 18 Nov 2026 11:31:42 +0100 Subject: [PATCH 12/17] fix(web): translate the PR summary quote and reply failure copy Co-Authored-By: Claude Opus 5.5 --- .../src/components/pullRequest/PullRequestSummaryTab.tsx | 6 ++++-- apps/web/src/i18n/translations/de.json | 1 + apps/web/src/i18n/translations/en.json | 1 + apps/web/src/i18n/translations/es.json | 1 + apps/web/src/i18n/translations/fr.json | 1 + apps/web/src/i18n/translations/ja.json | 1 + apps/web/src/i18n/translations/ko.json | 1 + apps/web/src/i18n/translations/pt-BR.json | 1 + apps/web/src/i18n/translations/ru.json | 1 + apps/web/src/i18n/translations/sv.json | 1 + apps/web/src/i18n/translations/zh.json | 1 + 11 files changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx index 3fb5b64c0c8fe..4f934fd3c1e1c 100644 --- a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx +++ b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx @@ -726,7 +726,7 @@ export function PullRequestSummaryTab({ const result = await replyToThread({ environmentId, input: { ...reference, threadId, body } }); setThreadReplyPending(false); if (result._tag === "Failure") { - toastManager.add({ type: "error", title: "Reply could not be posted" }); + toastManager.add({ type: "error", title: m(msg("Reply could not be posted")) }); return false; } onRefresh(); @@ -874,7 +874,9 @@ export function PullRequestSummaryTab({ > - Quote reply + + Quote reply + ) : null} diff --git a/apps/web/src/i18n/translations/de.json b/apps/web/src/i18n/translations/de.json index 648fd58859dbe..31b474e00526f 100644 --- a/apps/web/src/i18n/translations/de.json +++ b/apps/web/src/i18n/translations/de.json @@ -6849,6 +6849,7 @@ "8bde6f21a85c083e": "Der einzige Kommentar wird vom Filter ausgeblendet.", "ed059bae884ace42": "{count, plural, one {Der Kommentar ist durch den Filter ausgeblendet.} other {Alle {count} Kommentare sind durch den Filter ausgeblendet.}}", "2bc15e77eb0c700f": "Veraltet", + "409b0ee20e27c6f1": "Antwort mit Zitat", "eba79691ca074ef8": "Keine", "774b2047d6fe4a53": "Die Check-Details sind veraltet.", "fa7305d81d40046f": "Aktualisieren", diff --git a/apps/web/src/i18n/translations/en.json b/apps/web/src/i18n/translations/en.json index 599944358b5bb..cf27e05948d44 100644 --- a/apps/web/src/i18n/translations/en.json +++ b/apps/web/src/i18n/translations/en.json @@ -6855,6 +6855,7 @@ "8bde6f21a85c083e": "The only comment is hidden by the filter.", "ed059bae884ace42": "{count, plural, one {All {count} comments are hidden by the filter.} other {All {count} comments are hidden by the filter.}}", "2bc15e77eb0c700f": "Outdated", + "409b0ee20e27c6f1": "Quote reply", "eba79691ca074ef8": "None", "774b2047d6fe4a53": "Check details are out of date.", "fa7305d81d40046f": "Refresh", diff --git a/apps/web/src/i18n/translations/es.json b/apps/web/src/i18n/translations/es.json index 956f4e17a9617..2789caf16b4e9 100644 --- a/apps/web/src/i18n/translations/es.json +++ b/apps/web/src/i18n/translations/es.json @@ -6848,6 +6848,7 @@ "8bde6f21a85c083e": "El único comentario está oculto por el filtro.", "ed059bae884ace42": "{count, plural, one {El filtro oculta el único comentario ({count}).} other {El filtro oculta los {count} comentarios.}}", "2bc15e77eb0c700f": "Desactualizada", + "409b0ee20e27c6f1": "Responder citando", "eba79691ca074ef8": "Ninguno", "774b2047d6fe4a53": "Los detalles de las comprobaciones están desactualizados.", "fa7305d81d40046f": "Actualizar", diff --git a/apps/web/src/i18n/translations/fr.json b/apps/web/src/i18n/translations/fr.json index 1c982cc6d6f58..d669bbc4efb11 100644 --- a/apps/web/src/i18n/translations/fr.json +++ b/apps/web/src/i18n/translations/fr.json @@ -6849,6 +6849,7 @@ "8bde6f21a85c083e": "Le seul commentaire est masqué par le filtre.", "ed059bae884ace42": "{count, plural, one {Le commentaire est masqué par le filtre.} other {Les {count} commentaires sont tous masqués par le filtre.}}", "2bc15e77eb0c700f": "Obsolète", + "409b0ee20e27c6f1": "Répondre en citant", "eba79691ca074ef8": "Aucun", "774b2047d6fe4a53": "Les détails des checks ne sont plus à jour.", "fa7305d81d40046f": "Actualiser", diff --git a/apps/web/src/i18n/translations/ja.json b/apps/web/src/i18n/translations/ja.json index 879531a396d2a..ed4596c55e349 100644 --- a/apps/web/src/i18n/translations/ja.json +++ b/apps/web/src/i18n/translations/ja.json @@ -6818,6 +6818,7 @@ "8bde6f21a85c083e": "唯一のコメントはフィルターで非表示になっています。", "ed059bae884ace42": "{count, plural, other {{count} 件のコメントはすべてフィルターで非表示になっています。}}", "2bc15e77eb0c700f": "古い", + "409b0ee20e27c6f1": "引用して返信", "eba79691ca074ef8": "なし", "774b2047d6fe4a53": "チェックの詳細が古くなっています。", "fa7305d81d40046f": "更新", diff --git a/apps/web/src/i18n/translations/ko.json b/apps/web/src/i18n/translations/ko.json index fae8ce2ec6fc4..ccaf79b4ad233 100644 --- a/apps/web/src/i18n/translations/ko.json +++ b/apps/web/src/i18n/translations/ko.json @@ -6820,6 +6820,7 @@ "8bde6f21a85c083e": "유일한 댓글이 필터로 숨겨졌습니다.", "ed059bae884ace42": "{count, plural, other {필터 때문에 댓글 {count}개가 모두 숨겨져 있습니다.}}", "2bc15e77eb0c700f": "오래됨", + "409b0ee20e27c6f1": "인용하여 답글", "eba79691ca074ef8": "없음", "774b2047d6fe4a53": "검사 세부 정보가 오래되었습니다.", "fa7305d81d40046f": "새로 고침", diff --git a/apps/web/src/i18n/translations/pt-BR.json b/apps/web/src/i18n/translations/pt-BR.json index 7010bef288b16..16d8eddc5fb9e 100644 --- a/apps/web/src/i18n/translations/pt-BR.json +++ b/apps/web/src/i18n/translations/pt-BR.json @@ -6848,6 +6848,7 @@ "8bde6f21a85c083e": "O único comentário está oculto pelo filtro.", "ed059bae884ace42": "{count, plural, one {O comentário está oculto pelo filtro.} other {Todos os {count} comentários estão ocultos pelo filtro.}}", "2bc15e77eb0c700f": "Desatualizada", + "409b0ee20e27c6f1": "Responder com citação", "eba79691ca074ef8": "Nenhum", "774b2047d6fe4a53": "Os detalhes das verificações estão desatualizados.", "fa7305d81d40046f": "Atualizar", diff --git a/apps/web/src/i18n/translations/ru.json b/apps/web/src/i18n/translations/ru.json index 0766d953dd02d..864b12ce4803d 100644 --- a/apps/web/src/i18n/translations/ru.json +++ b/apps/web/src/i18n/translations/ru.json @@ -6848,6 +6848,7 @@ "8bde6f21a85c083e": "Единственный комментарий скрыт фильтром.", "ed059bae884ace42": "{count, plural, one {Фильтр скрывает {count} комментарий.} few {Фильтр скрывает все {count} комментария.} many {Фильтр скрывает все {count} комментариев.} other {Фильтр скрывает все {count} комментария.}}", "2bc15e77eb0c700f": "Устарело", + "409b0ee20e27c6f1": "Ответить с цитатой", "eba79691ca074ef8": "Нет", "774b2047d6fe4a53": "Подробности проверок устарели.", "fa7305d81d40046f": "Обновить", diff --git a/apps/web/src/i18n/translations/sv.json b/apps/web/src/i18n/translations/sv.json index 5e6d1607edf31..3464ce9859ab9 100644 --- a/apps/web/src/i18n/translations/sv.json +++ b/apps/web/src/i18n/translations/sv.json @@ -6854,6 +6854,7 @@ "8bde6f21a85c083e": "Den enda kommentaren döljs av filtret.", "ed059bae884ace42": "{count, plural, one {Kommentaren döljs av filtret.} other {Alla {count} kommentarer döljs av filtret.}}", "2bc15e77eb0c700f": "Inaktuell", + "409b0ee20e27c6f1": "Svara med citat", "eba79691ca074ef8": "Inga", "774b2047d6fe4a53": "Kontrolldetaljerna är inaktuella.", "fa7305d81d40046f": "Uppdatera", diff --git a/apps/web/src/i18n/translations/zh.json b/apps/web/src/i18n/translations/zh.json index c86b9e6c55e41..e5369f33c58a5 100644 --- a/apps/web/src/i18n/translations/zh.json +++ b/apps/web/src/i18n/translations/zh.json @@ -6863,6 +6863,7 @@ "8bde6f21a85c083e": "唯一的评论被筛选条件隐藏了。", "ed059bae884ace42": "{count, plural, other {全部 {count} 条评论均被筛选条件隐藏。}}", "2bc15e77eb0c700f": "已过时", + "409b0ee20e27c6f1": "引用回复", "eba79691ca074ef8": "无", "774b2047d6fe4a53": "检查详情已过期。", "fa7305d81d40046f": "刷新", From 258fc79c571d82627aadfe0aa71de42a16831787 Mon Sep 17 00:00:00 2001 From: Tony <97451137+TonybynMp4@users.noreply.github.com> Date: Wed, 11 Nov 2026 22:27:14 +0100 Subject: [PATCH 13/17] feat(web): nest review threads under their review in the PR Summary tab Each GitHub review thread now sits under the review whose URL matches its first comment's review link. A review with no text gets a small "reviewed" header. Threads without a link stay top-level. Pending and hidden reviews give their comments no review link, a hidden bot summary gives way to the bare header, a dismissed review collapses with its threads, and paging counts each nested thread. Co-Authored-By: Claude Opus 5.5 --- .../pullRequest/PullRequestSummaryTab.tsx | 145 +++++++++---- .../pullRequestDetail.logic.test.ts | 119 +++++++++++ .../pullRequest/pullRequestDetail.logic.ts | 200 +++++++++++++----- .../src/server/gitHubPullRequestJson.test.ts | 27 ++- .../src/server/gitHubPullRequestJson.ts | 4 +- .../src/server/pullRequestReviews.graphql | 3 + .../src/server/pullRequestReviews.graphql.ts | 12 +- 7 files changed, 409 insertions(+), 101 deletions(-) diff --git a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx index 4f934fd3c1e1c..728dfbde435b2 100644 --- a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx +++ b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx @@ -114,9 +114,11 @@ function reviewerKey(login: string): string { function CommentIdentity({ comment, detail, + action, }: { - comment: PullRequestComment; + comment: Pick; detail: PullRequestDetailView; + action?: string; }) { const gt = useGT(); const timestampFormat = useClientSettings((settings) => settings.timestampFormat); @@ -127,6 +129,7 @@ function CommentIdentity({ return (
+ {action ? {action} : null}
- {replyCount > 0 ? ( - - {gt("{count, plural, one {{count} reply} other {{count} replies}}", { - count: replyCount, - })} - + {count ? ( + {count} ) : null} { - const comment = item.kind === "comment" ? item.comment : item.root; - const thread = item.kind === "thread" ? item.thread : undefined; - const replies = - item.kind === "thread" && item.replies.length > 0 ? ( -
- {item.replies.map((reply) => renderCommentCard(reply, undefined, { reply: true }))} + const countOf = (count: number, kind: "thread" | "reply"): string | null => { + if (count === 0) return null; + return kind === "thread" + ? gt("{count, plural, one {{count} thread} other {{count} threads}}", { count }) + : gt("{count, plural, one {{count} reply} other {{count} replies}}", { count }); + }; + + const renderItem = (item: PullRequestConversationItem): ReactNode => { + if (item.kind === "review") { + const threads = ( +
+ {item.threads.map(renderItem)}
- ) : null; - const moreReplies = - item.kind === "thread" && item.hasMoreReplies ? : null; - if (isPullRequestCommentFinished(comment, thread)) { - const chat = chatSubject(comment, thread); + ); + const review = item.review; + // A dismissed review collapses together with the threads it posted. + if (review !== null && isPullRequestCommentFinished(review)) { + return renderCollapsed( + { kind: "comment", id: review.id, createdAt: review.createdAt, comment: review }, + threads, + countOf(item.threads.length, "thread"), + ); + } return ( - onAddToChat(chat) : undefined} - reactionBar={reactionBarFor(comment)} - resolveButton={resolveButtonFor(thread)} - /> +
+ {review === null ? ( +
+ +
+ ) : ( + renderCommentCard(review, undefined) + )} + {threads} +
+ ); + } + const thread = item.kind === "thread" ? item.thread : undefined; + if (isPullRequestCommentFinished(item.kind === "comment" ? item.comment : item.root, thread)) { + return renderCollapsed( + item, + threadReplies(item), + item.kind === "thread" + ? countOf(item.replies.length + item.moreReplies, "reply") + : null, ); } - if (item.kind === "comment") return renderCommentCard(comment, undefined); + if (item.kind === "comment") return renderCommentCard(item.comment, undefined); return (
- {renderCommentCard(comment, thread)} - {replies} - {moreReplies} - {thread ? threadReplyForm(thread, "mt-0") : null} + {renderCommentCard(item.root, item.thread)} + {threadReplies(item)} + {item.hasMoreReplies ? : null} + {threadReplyForm(item.thread, "mt-0")} +
+ ); + }; + + const threadReplies = (item: PullRequestConversationItem) => + item.kind === "thread" && item.replies.length > 0 ? ( +
+ {item.replies.map((reply) => renderCommentCard(reply, undefined, { reply: true }))}
+ ) : null; + + const renderCollapsed = ( + item: Exclude, + replies: ReactNode, + count: string | null, + ) => { + const comment = item.kind === "comment" ? item.comment : item.root; + const thread = item.kind === "thread" ? item.thread : undefined; + const chat = chatSubject(comment, thread); + return ( + + ) : null + } + replyForm={thread ? threadReplyForm(thread, "mt-0") : null} + onAddToChat={onAddToChat && chat !== null ? () => onAddToChat(chat) : undefined} + reactionBar={reactionBarFor(comment)} + resolveButton={resolveButtonFor(thread)} + /> ); }; diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts index 7ef84745db607..43b6a51b75a22 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts @@ -644,6 +644,125 @@ describe("review thread conversations", () => { ); }); + it("nests each thread under the review its first comment was posted in", () => { + const reviewUrl = (id: string) => `https://example.test/pull/1#pullrequestreview-${id}`; + const review = (id: string, day: number, body: string, reviewState: string) => ({ + ...comment(`review-${id}`, day), + kind: "review" as const, + body, + path: null, + reviewState, + url: reviewUrl(id), + }); + const posted = (id: string, day: number, inReview: string | null) => ({ + ...comment(id, day), + ...(inReview === null ? {} : { reviewUrl: reviewUrl(inReview) }), + }); + const threadOf = (id: string, ...members: ReturnType[]) => ({ + ...thread, + id, + comments: members, + }); + const summarized = review("1", 3, "Two notes", "COMMENTED"); + const verdict = review("2", 5, "", "CHANGES_REQUESTED"); + const first = posted("first", 2, "1"); + // The comment's copy of the link can carry another path; the anchor names the review. + const second = { + ...posted("second", 2, null), + reviewUrl: `https://example.test/pull/1/files#pullrequestreview-1`, + }; + // A reply posts as its own small review; the thread stays with its root's. + const laterReply = posted("later-reply", 4, "2"); + const blocker = posted("blocker", 5, "2"); + const bodiless = posted("bodiless", 7, "3"); + const unlinked = posted("unlinked", 8, null); + const items = pullRequestConversationItems( + [summarized, verdict], + [ + threadOf("t-second", second), + threadOf("t-first", first, laterReply), + threadOf("t-blocker", blocker), + threadOf("t-bodiless", bodiless), + threadOf("t-unlinked", unlinked), + ], + ); + expect( + items.map((item) => + item.kind === "review" + ? { id: item.id, review: item.review, threads: item.threads.map((entry) => entry.id) } + : item.id, + ), + ).toEqual([ + { id: "review-1", review: summarized, threads: ["t-second", "t-first"] }, + { id: "review-2", review: verdict, threads: ["t-blocker"] }, + { id: `review:${reviewUrl("3")}`, review: null, threads: ["t-bodiless"] }, + "t-unlinked", + ]); + expect(items[2]).toMatchObject({ createdAt: bodiless.createdAt, author: bodiless.author }); + expect(pullRequestConversationItemComments(items[0]!)).toEqual([ + summarized, + { ...second, kind: "review-comment", reviewState: null }, + { ...first, kind: "review-comment", reviewState: null }, + { ...laterReply, kind: "review-comment", reviewState: null }, + ]); + const resolvedFirst = pullRequestConversationItems( + [summarized], + [threadOf("t-second", second), { ...threadOf("t-first", first), isResolved: true }], + ); + expect( + filterPullRequestConversationItems(resolvedFirst, { bots: true, resolved: false }).map( + (item) => (item.kind === "review" ? item.threads.map((entry) => entry.id) : item.id), + ), + ).toEqual([["t-second"]]); + const allResolved = pullRequestConversationItems( + [], + [{ ...threadOf("t-bodiless", bodiless), isResolved: true }], + ); + expect( + filterPullRequestConversationItems(allResolved, { bots: true, resolved: false }), + ).toEqual([]); + // With every thread filtered out, a summary that still shows stands as a plain comment. + const summaryOnly = pullRequestConversationItems( + [summarized], + [{ ...threadOf("t-first", first), isResolved: true }], + ); + expect( + filterPullRequestConversationItems(summaryOnly, { bots: true, resolved: false }), + ).toEqual([ + { kind: "comment", id: summarized.id, createdAt: summarized.createdAt, comment: summarized }, + ]); + // A human reply keeps a bot's thread, but the bot's summary gives way to a bare header. + const botReview = { ...summarized, author: bot }; + const botThread = threadOf("t-first", { ...first, author: bot }, laterReply); + expect( + filterPullRequestConversationItems(pullRequestConversationItems([botReview], [botThread]), { + bots: false, + resolved: true, + }), + ).toMatchObject([ + { kind: "review", id: botReview.id, review: null, threads: [{ id: "t-first" }] }, + ]); + // A review counts each of its threads toward a page, and the page edge cuts its earliest. + const page = pagePullRequestConversationItems(items, 3); + expect(page.hidden).toBe(2); + expect( + page.shown.map((item) => + item.kind === "review" ? item.threads.map((entry) => entry.id) : item.id, + ), + ).toEqual([["t-blocker"], ["t-bodiless"], "t-unlinked"]); + expect(pagePullRequestConversationItems(items, 4).shown[0]).toMatchObject({ + id: "review-1", + threads: [{ id: "t-first" }], + }); + expect( + buildPullRequestTimeline({ + ...TIMELINE_SOURCE, + comments: [summarized], + reviewThreads: [threadOf("t-first", first)], + }).map((event) => event.id), + ).toEqual(["review-1", "first", "1baf7bdcafe", "created"]); + }); + it("filters whole conversations when any member matches, including resolved and dismissed reviews", () => { const botOnly = { ...comment("bot-only", 7), author: bot }; const dismissed = { diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts index 10af724bb8736..e1d1dae480c2f 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -593,6 +593,15 @@ function commentTimelineEvent(comment: PullRequestComment): PullRequestTimelineE }; } +export type PullRequestConversationThreadItem = { + readonly kind: "thread"; + readonly id: string; + readonly createdAt: string; + readonly root: PullRequestComment; + readonly replies: ReadonlyArray; + readonly thread: PullRequestConversationThread; +} & PullRequestReplyAvailability; + export type PullRequestConversationItem = | { readonly kind: "comment"; @@ -600,14 +609,17 @@ export type PullRequestConversationItem = readonly createdAt: string; readonly comment: PullRequestComment; } - | ({ - readonly kind: "thread"; + | PullRequestConversationThreadItem + | { + readonly kind: "review"; readonly id: string; readonly createdAt: string; - readonly root: PullRequestComment; - readonly replies: ReadonlyArray; - readonly thread: PullRequestConversationThread; - } & PullRequestReplyAvailability); + /** Null for a review the host leaves out of the conversation, such as GitHub's with no text. */ + readonly review: PullRequestComment | null; + readonly author: PullRequestActor | null; + readonly url: string; + readonly threads: ReadonlyArray; + }; export function pullRequestConversationItems( comments: ReadonlyArray, @@ -615,7 +627,16 @@ export function pullRequestConversationItems( ): ReadonlyArray { const byId = new Map(comments.map((comment) => [comment.id, comment])); const claimed = new Set(); - const threads: PullRequestConversationItem[] = []; + const reviewKeys = new Set( + comments.flatMap((comment) => + comment.kind === "review" && comment.url !== null ? [reviewKey(comment.url)] : [], + ), + ); + const loose: PullRequestConversationItem[] = []; + const byReview = new Map< + string, + { readonly url: string; readonly threads: PullRequestConversationThreadItem[] } + >(); for (const thread of reviewThreads) { // Keep the conversation's objects for editing/reactions; some hosts only include a // comment in the thread, so normalize that copy when the flat conversation lacks it. @@ -634,7 +655,7 @@ export function pullRequestConversationItems( if (root === undefined) continue; for (const comment of ordered) claimed.add(comment.id); const moreReplies = Math.max(0, (thread.commentCount ?? ordered.length) - ordered.length); - threads.push({ + const item: PullRequestConversationThreadItem = { kind: "thread", id: thread.id, createdAt: root.createdAt, @@ -644,30 +665,75 @@ export function pullRequestConversationItems( moreReplies, hasMoreReplies: moreReplies > 0 || thread.nextCommentsCursor !== undefined, url: ordered.find((comment) => comment.url !== null)?.url ?? null, + }; + // Only the root places a thread: each later reply posts as a review of its own. + const reviewUrl = thread.comments.find((comment) => comment.id === root.id)?.reviewUrl; + if (!reviewUrl) { + loose.push(item); + continue; + } + const key = reviewKey(reviewUrl); + const review = byReview.get(key); + if (review) review.threads.push(item); + else byReview.set(key, { url: reviewUrl, threads: [item] }); + } + for (const [key, { url, threads }] of byReview) { + threads.sort((left, right) => instant(left.createdAt) - instant(right.createdAt)); + if (reviewKeys.has(key)) continue; + const first = threads[0]!; + loose.push({ + kind: "review", + id: `review:${url}`, + createdAt: first.createdAt, + review: null, + author: first.root.author, + url, + threads, }); } - threads.sort((left, right) => instant(left.createdAt) - instant(right.createdAt)); + loose.sort((left, right) => instant(left.createdAt) - instant(right.createdAt)); const items: PullRequestConversationItem[] = []; let next = 0; // Preserve loose comments' existing order, inserting each thread at its finding's time. for (const comment of comments) { if (claimed.has(comment.id)) continue; - while ( - next < threads.length && - instant(threads[next]!.createdAt) < instant(comment.createdAt) - ) { - items.push(threads[next++]!); + while (next < loose.length && instant(loose[next]!.createdAt) < instant(comment.createdAt)) { + items.push(loose[next++]!); } - items.push({ kind: "comment", id: comment.id, createdAt: comment.createdAt, comment }); + const url = comment.url; + const threads = url === null ? undefined : byReview.get(reviewKey(url))?.threads; + items.push( + comment.kind === "review" && url !== null && threads !== undefined + ? { + kind: "review", + id: comment.id, + createdAt: comment.createdAt, + review: comment, + author: comment.author, + url, + threads, + } + : { kind: "comment", id: comment.id, createdAt: comment.createdAt, comment }, + ); } - items.push(...threads.slice(next)); + items.push(...loose.slice(next)); return items; } +/** GitHub review links differ only in their anchor between the review and its comments' copies. */ +function reviewKey(url: string): string { + return /#pullrequestreview-\d+$/i.exec(url)?.[0].toLowerCase() ?? url; +} + export function pullRequestConversationItemComments( item: PullRequestConversationItem, ): ReadonlyArray { - return item.kind === "comment" ? [item.comment] : [item.root, ...item.replies]; + if (item.kind === "comment") return [item.comment]; + if (item.kind === "thread") return [item.root, ...item.replies]; + return [ + ...(item.review === null ? [] : [item.review]), + ...item.threads.flatMap(pullRequestConversationItemComments), + ]; } export function isPullRequestCommentFinished( @@ -688,26 +754,55 @@ export function filterPullRequestConversationItems( items: ReadonlyArray, filter: { readonly bots: boolean; readonly resolved: boolean }, ): ReadonlyArray { - return items.filter((item) => - // Matching any member keeps the finding beside a human reply to a bot. - pullRequestConversationItemComments(item).some( - (comment) => - // A bot's approval or change request is a verdict, not chatter. - (filter.bots || - comment.author?.isBot !== true || - isPullRequestVerdict(comment.reviewState)) && - (filter.resolved || - !isPullRequestCommentFinished(comment, item.kind === "thread" ? item.thread : undefined)), - ), - ); + const keeps = (comment: PullRequestComment, thread?: PullRequestConversationThread) => + // A bot's approval or change request is a verdict, not chatter. + (filter.bots || comment.author?.isBot !== true || isPullRequestVerdict(comment.reviewState)) && + (filter.resolved || !isPullRequestCommentFinished(comment, thread)); + // Matching any member keeps the finding beside a human reply to a bot. + const matches = (item: PullRequestConversationItem) => + pullRequestConversationItemComments(item).some((comment) => + keeps(comment, item.kind === "thread" ? item.thread : undefined), + ); + return items.flatMap((item): ReadonlyArray => { + if (item.kind !== "review") return matches(item) ? [item] : []; + const threads = item.threads.filter(matches); + // A summary the filter hides gives way to a bare header over the threads it kept. + const review = item.review !== null && keeps(item.review) ? item.review : null; + if (threads.length === 0) { + return review === null + ? [] + : [{ kind: "comment", id: review.id, createdAt: review.createdAt, comment: review }]; + } + return [ + threads.length === item.threads.length && review === item.review + ? item + : { ...item, review, threads }, + ]; + }); } export function pagePullRequestConversationItems( items: ReadonlyArray, count: number, ): { readonly shown: ReadonlyArray; readonly hidden: number } { - const shown = items.slice(Math.max(0, items.length - count)); - return { shown, hidden: items.length - shown.length }; + // A review counts each of its threads, so one with dozens of findings does not fill a page. + const weight = (item: PullRequestConversationItem) => + item.kind === "review" ? item.threads.length : 1; + const shown: PullRequestConversationItem[] = []; + let left = count; + for (let index = items.length - 1; index >= 0 && left > 0; index--) { + const item = items[index]!; + if (item.kind === "review" && item.threads.length > left) { + // The page edge cuts the review's earliest threads; the next page brings them back. + shown.push({ ...item, threads: item.threads.slice(-left) }); + left = 0; + break; + } + shown.push(item); + left -= weight(item); + } + const hidden = items.reduce((total, item) => total + weight(item), 0) - (count - left); + return { shown: shown.reverse(), hidden }; } /** @@ -879,24 +974,31 @@ export function buildPullRequestTimeline( ...pullRequestConversationItems(detail.comments, [ ...(detail.reviewThreads ?? []), ...(detail.overviewThreads ?? []), - ]).map((item) => { - if (item.kind === "comment") return commentTimelineEvent(item.comment); - return { - ...commentTimelineEvent(item.root), - thread: { - id: item.thread.id, - ...(item.thread.canResolve === undefined ? {} : { canResolve: item.thread.canResolve }), - path: item.thread.path, - line: item.thread.line, - isResolved: item.thread.isResolved, - isOutdated: item.thread.isOutdated, - replies: item.replies.map(commentTimelineEvent), - moreReplies: item.moreReplies, - hasMoreReplies: item.hasMoreReplies, - url: item.url, - }, - }; - }), + ]) + // The Timeline tab keeps a review's threads as rows of their own. + .flatMap((item) => + item.kind === "review" + ? [...(item.review === null ? [] : [item.review]), ...item.threads] + : [item.kind === "comment" ? item.comment : item], + ) + .map((item) => { + if (item.kind !== "thread") return commentTimelineEvent(item); + return { + ...commentTimelineEvent(item.root), + thread: { + id: item.thread.id, + ...(item.thread.canResolve === undefined ? {} : { canResolve: item.thread.canResolve }), + path: item.thread.path, + line: item.thread.line, + isResolved: item.thread.isResolved, + isOutdated: item.thread.isOutdated, + replies: item.replies.map(commentTimelineEvent), + moreReplies: item.moreReplies, + hasMoreReplies: item.hasMoreReplies, + url: item.url, + }, + }; + }), ...(detail.mergedAt ? [ { diff --git a/packages/source-control-github/src/server/gitHubPullRequestJson.test.ts b/packages/source-control-github/src/server/gitHubPullRequestJson.test.ts index 5f084ac203fb6..5cea4ce90d01e 100644 --- a/packages/source-control-github/src/server/gitHubPullRequestJson.test.ts +++ b/packages/source-control-github/src/server/gitHubPullRequestJson.test.ts @@ -916,6 +916,28 @@ describe("review thread decoding", () => { createdAt: "2026-07-01T01:00:00Z", pullRequestReview: { url: "https://github.com/acme/web/pull/1#pullrequestreview-9", + state: "COMMENTED", + isMinimized: false, + }, + }, + { + id: "t3", + body: "draft", + createdAt: "2026-07-01T02:00:00Z", + pullRequestReview: { + url: "https://github.com/acme/web/pull/1#pullrequestreview-10", + state: "PENDING", + isMinimized: false, + }, + }, + { + id: "t4", + body: "hidden", + createdAt: "2026-07-01T03:00:00Z", + pullRequestReview: { + url: "https://github.com/acme/web/pull/1#pullrequestreview-11", + state: "COMMENTED", + isMinimized: true, }, }, ], @@ -925,11 +947,14 @@ describe("review thread decoding", () => { ), ); const comments = reviewThreadConversation(result.threads.map((entry) => entry.thread)); - expect(comments.map((comment) => comment.id)).toEqual(["t1", "t2"]); + expect(comments.map((comment) => comment.id)).toEqual(["t1", "t2", "t3", "t4"]); // A reply-only review has no text of its own; its link finds it through the reply it posted. + // A pending or hidden review is not in the conversation, so nothing links to it. expect(result.threads[0]?.thread.comments.map((comment) => comment.reviewUrl)).toEqual([ undefined, "https://github.com/acme/web/pull/1#pullrequestreview-9", + undefined, + undefined, ]); }); diff --git a/packages/source-control-github/src/server/gitHubPullRequestJson.ts b/packages/source-control-github/src/server/gitHubPullRequestJson.ts index 4f3deaea4d08a..f09912fb96352 100644 --- a/packages/source-control-github/src/server/gitHubPullRequestJson.ts +++ b/packages/source-control-github/src/server/gitHubPullRequestJson.ts @@ -1357,7 +1357,9 @@ export function toReviewDismissalsPage(result: ReviewDismissals.Result): { } function toThreadComment(comment: ThreadComment, viewer: string | null): PullRequestThreadComment { - const reviewUrl = trimmed(comment.pullRequestReview?.url); + const review = comment.pullRequestReview; + const reviewUrl = + review == null || review.isMinimized || review.state === "PENDING" ? null : trimmed(review.url); return { id: comment.id, author: toActor(comment.author), diff --git a/packages/source-control-github/src/server/pullRequestReviews.graphql b/packages/source-control-github/src/server/pullRequestReviews.graphql index d497615c24693..4c63bf736b2d2 100644 --- a/packages/source-control-github/src/server/pullRequestReviews.graphql +++ b/packages/source-control-github/src/server/pullRequestReviews.graphql @@ -39,8 +39,11 @@ fragment ThreadComment on PullRequestReviewComment { url isMinimized # A review link names the review, not its comments; this lets it find the comments it posted. + # A pending or hidden review is not in the conversation, so it gets no link. pullRequestReview { url + state + isMinimized } ...Reactions } diff --git a/packages/source-control-github/src/server/pullRequestReviews.graphql.ts b/packages/source-control-github/src/server/pullRequestReviews.graphql.ts index bce1451b8c296..b1c3aa051c088 100644 --- a/packages/source-control-github/src/server/pullRequestReviews.graphql.ts +++ b/packages/source-control-github/src/server/pullRequestReviews.graphql.ts @@ -92,7 +92,11 @@ export interface Actor extends Schema.Struct.Type {} /** A review object for a given pull request. */ export const PullRequestReviewPullRequestReview = Schema.Struct({ /** The HTTP URL permalink for this PullRequestReview. */ - url: Shared.URI + url: Shared.URI, + /** Identifies the current state of the pull request review. */ + state: GraphQL.enumLiterals(Shared.PullRequestReviewState.literals), + /** Returns whether or not a comment has been minimized. */ + isMinimized: Schema.Boolean }) export interface PullRequestReviewPullRequestReview extends Schema.Struct.Type {} @@ -434,7 +438,7 @@ export const ReviewThreads = GraphQL.query("ReviewThreads", { fragments: [ { name: "ReviewThreadPage", body: ["on PullRequestReviewThreadConnection{totalCount pageInfo{hasNextPage endCursor}nodes{id isResolved isOutdated path line diffSide comments(first:10){totalCount pageInfo{hasNextPage endCursor}nodes{...ThreadComment}}}}"] }, { name: "Reactions", body: ["on Reactable{__typename reactionGroups{content viewerHasReacted reactors(first:10){totalCount nodes{__typename...on User{login}...on Bot{login}...on Organization{login}...on Mannequin{login}}}}}"] }, - { name: "ThreadComment", body: ["on PullRequestReviewComment{id author{__typename login avatarUrl}body createdAt lastEditedAt url isMinimized pullRequestReview{url}...Reactions}"] } + { name: "ThreadComment", body: ["on PullRequestReviewComment{id author{__typename login avatarUrl}body createdAt lastEditedAt url isMinimized pullRequestReview{url state isMinimized}...Reactions}"] } ] }, variables: { @@ -484,7 +488,7 @@ export const ReviewThreadPages = GraphQL.query("ReviewThreadPages", { ], fragments: [ { name: "ReviewThreadPage", body: ["on PullRequestReviewThreadConnection{totalCount pageInfo{hasNextPage endCursor}nodes{id isResolved isOutdated path line diffSide comments(first:10){totalCount pageInfo{hasNextPage endCursor}nodes{...ThreadComment}}}}"] }, - { name: "ThreadComment", body: ["on PullRequestReviewComment{id author{__typename login avatarUrl}body createdAt lastEditedAt url isMinimized pullRequestReview{url}...Reactions}"] }, + { name: "ThreadComment", body: ["on PullRequestReviewComment{id author{__typename login avatarUrl}body createdAt lastEditedAt url isMinimized pullRequestReview{url state isMinimized}...Reactions}"] }, { name: "Reactions", body: ["on Reactable{__typename reactionGroups{content viewerHasReacted reactors(first:10){totalCount nodes{__typename...on User{login}...on Bot{login}...on Organization{login}...on Mannequin{login}}}}}"] } ] }, @@ -561,7 +565,7 @@ export const ReviewThreadComments = GraphQL.query("ReviewThreadComments", { { name: "node", body: ["(id:$", "threadId", "){__typename...on PullRequestReviewThread{pullRequest{id}comments(first:100 after:$", "after", "){pageInfo{hasNextPage endCursor}nodes{...ThreadComment}}}}"] } ], fragments: [ - { name: "ThreadComment", body: ["on PullRequestReviewComment{id author{__typename login avatarUrl}body createdAt lastEditedAt url isMinimized pullRequestReview{url}...Reactions}"] }, + { name: "ThreadComment", body: ["on PullRequestReviewComment{id author{__typename login avatarUrl}body createdAt lastEditedAt url isMinimized pullRequestReview{url state isMinimized}...Reactions}"] }, { name: "Reactions", body: ["on Reactable{__typename reactionGroups{content viewerHasReacted reactors(first:10){totalCount nodes{__typename...on User{login}...on Bot{login}...on Organization{login}...on Mannequin{login}}}}}"] } ] }, From bc62b057395de0089bb84dfba48b6acffd291c05 Mon Sep 17 00:00:00 2001 From: Tony <97451137+TonybynMp4@users.noreply.github.com> Date: Thu, 12 Nov 2026 09:47:06 +0100 Subject: [PATCH 14/17] fix(web): stop reply dictation when its review thread collapses Co-Authored-By: Claude Opus 5.5 --- .../components/pullRequest/PullRequestReviewAnnotation.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx b/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx index 629b681c7bf72..04f1740281570 100644 --- a/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx +++ b/apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx @@ -434,6 +434,7 @@ export function ReviewThreadCard({ threadId={thread.id} completionScope={completionScope} pending={pending} + collapsed={!expanded} onReply={onReply} onSent={keepLoadedPage} /> @@ -449,6 +450,7 @@ export function PullRequestThreadReplyForm({ threadId, completionScope, pending, + collapsed = false, className, onReply, onSent, @@ -458,6 +460,8 @@ export function PullRequestThreadReplyForm({ threadId: string; completionScope: PullRequestCompletionScope | null; pending: boolean; + /** Stops dictation, which would keep recording behind hidden controls. */ + collapsed?: boolean; className?: string; onReply: (body: string) => Promise; onSent?: () => void; @@ -503,7 +507,7 @@ export function PullRequestThreadReplyForm({ text={reply} textareaRef={replyRef} onTextChange={setReply} - disabled={pending} + disabled={pending || collapsed} > {(speech) => (
From 85649bde3761439562726801040ffb711cac0783 Mon Sep 17 00:00:00 2001 From: Tony <97451137+TonybynMp4@users.noreply.github.com> Date: Thu, 12 Nov 2026 09:58:38 +0100 Subject: [PATCH 15/17] fix(web): stop summary reply dictation when its conversation closes Co-Authored-By: Claude Sonnet 5.5 --- .../pullRequest/PullRequestSummaryTab.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx index 728dfbde435b2..a1dc0fec5c791 100644 --- a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx +++ b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx @@ -311,7 +311,7 @@ function CollapsedComment({ count?: string | null; replies?: ReactNode; moreReplies?: ReactNode; - replyForm?: ReactNode; + replyForm?: ((collapsed: boolean) => ReactNode) | null; onAddToChat?: (() => void) | undefined; }) { const gt = useGT(); @@ -364,7 +364,7 @@ function CollapsedComment({ {/* Stays mounted while collapsed so an unsent reply survives. */} {replyForm ? ( ) : null} {moreReplies ?
{moreReplies}
: null} @@ -732,7 +732,11 @@ export function PullRequestSummaryTab({ onRefresh(); return true; }; - const threadReplyForm = (thread: PullRequestConversationThread, className?: string) => + const threadReplyForm = ( + thread: PullRequestConversationThread, + className?: string, + collapsed = false, + ) => canReplyToThreads ? ( sendThreadReply(thread.id, body)} /> @@ -986,7 +991,7 @@ export function PullRequestSummaryTab({ ) : null } - replyForm={thread ? threadReplyForm(thread, "mt-0") : null} + replyForm={thread ? (collapsed) => threadReplyForm(thread, "mt-0", collapsed) : null} onAddToChat={onAddToChat && chat !== null ? () => onAddToChat(chat) : undefined} reactionBar={reactionBarFor(comment)} resolveButton={resolveButtonFor(thread)} From 9df4d16a0c3c62d302aa7b36c51729ab151bfc1f Mon Sep 17 00:00:00 2001 From: Tony <97451137+TonybynMp4@users.noreply.github.com> Date: Wed, 18 Nov 2026 11:38:10 +0100 Subject: [PATCH 16/17] fix(web): translate the review thread count and reviewed label Co-Authored-By: Claude Opus 5.5 --- .../components/pullRequest/PullRequestSummaryTab.tsx | 11 ++++++----- apps/web/src/i18n/translations/de.json | 4 +++- apps/web/src/i18n/translations/en.json | 4 +++- apps/web/src/i18n/translations/es.json | 4 +++- apps/web/src/i18n/translations/fr.json | 4 +++- apps/web/src/i18n/translations/ja.json | 4 +++- apps/web/src/i18n/translations/ko.json | 4 +++- apps/web/src/i18n/translations/pt-BR.json | 4 +++- apps/web/src/i18n/translations/ru.json | 4 +++- apps/web/src/i18n/translations/sv.json | 4 +++- apps/web/src/i18n/translations/zh.json | 4 +++- 11 files changed, 36 insertions(+), 15 deletions(-) diff --git a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx index a1dc0fec5c791..f9ad1d536c87b 100644 --- a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx +++ b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx @@ -314,7 +314,6 @@ function CollapsedComment({ replyForm?: ((collapsed: boolean) => ReactNode) | null; onAddToChat?: (() => void) | undefined; }) { - const gt = useGT(); const [open, setOpen] = useState(false); const statusTriggerRef = useRef(null); return ( @@ -926,7 +925,11 @@ export function PullRequestSummaryTab({
{review === null ? (
- +
) : ( renderCommentCard(review, undefined) @@ -940,9 +943,7 @@ export function PullRequestSummaryTab({ return renderCollapsed( item, threadReplies(item), - item.kind === "thread" - ? countOf(item.replies.length + item.moreReplies, "reply") - : null, + item.kind === "thread" ? countOf(item.replies.length + item.moreReplies, "reply") : null, ); } if (item.kind === "comment") return renderCommentCard(item.comment, undefined); diff --git a/apps/web/src/i18n/translations/de.json b/apps/web/src/i18n/translations/de.json index 31b474e00526f..ff754de5b027b 100644 --- a/apps/web/src/i18n/translations/de.json +++ b/apps/web/src/i18n/translations/de.json @@ -6832,9 +6832,11 @@ "e3e1ec05d1224d36": "Die Beschreibung konnte nicht gespeichert werden", "faef5657f28d1c69": "Der Kommentar konnte nicht gespeichert werden", "58af69b2314359ae": "Kommentar auf dem Host öffnen", - "eb60367cf891f1fa": "{count, plural, one {{count} Antwort} other {{count} Antworten}}", "69a6f3659c32ab5f": "Beheben", "02cc6cf89660f28b": "{count, plural, one {{shown} ältere Unterhaltung anzeigen ({count} ausgeblendet)} other {{shown} ältere Unterhaltungen anzeigen ({count} ausgeblendet)}}", + "070e8d2523890f69": "{count, plural, one {{count} Thread} other {{count} Threads}}", + "eb60367cf891f1fa": "{count, plural, one {{count} Antwort} other {{count} Antworten}}", + "e41e9d26c16569a8": "hat geprüft", "201519ca26d70f12": "Review verworfen", "9b3ae5edeae058a1": "Reviewer", "693b49ee48118ad8": "{term, select, mr {Beschreibung des Merge Requests} cr {Beschreibung der Änderungsanfrage} other {Beschreibung des Pull Requests}}", diff --git a/apps/web/src/i18n/translations/en.json b/apps/web/src/i18n/translations/en.json index cf27e05948d44..e106fcd4224aa 100644 --- a/apps/web/src/i18n/translations/en.json +++ b/apps/web/src/i18n/translations/en.json @@ -6838,9 +6838,11 @@ "e3e1ec05d1224d36": "Could not save the description", "faef5657f28d1c69": "Could not save the comment", "58af69b2314359ae": "Open comment on host", - "eb60367cf891f1fa": "{count, plural, one {{count} reply} other {{count} replies}}", "69a6f3659c32ab5f": "Fix", "02cc6cf89660f28b": "{count, plural, one {Show {shown} older conversation ({count} hidden)} other {Show {shown} older conversations ({count} hidden)}}", + "070e8d2523890f69": "{count, plural, one {{count} thread} other {{count} threads}}", + "eb60367cf891f1fa": "{count, plural, one {{count} reply} other {{count} replies}}", + "e41e9d26c16569a8": "reviewed", "201519ca26d70f12": "Review dismissed", "9b3ae5edeae058a1": "Reviewers", "693b49ee48118ad8": "{term, select, mr {Merge request} cr {Change request} other {Pull request}} description", diff --git a/apps/web/src/i18n/translations/es.json b/apps/web/src/i18n/translations/es.json index 2789caf16b4e9..2e382da6c0685 100644 --- a/apps/web/src/i18n/translations/es.json +++ b/apps/web/src/i18n/translations/es.json @@ -6831,9 +6831,11 @@ "e3e1ec05d1224d36": "No se pudo guardar la descripción", "faef5657f28d1c69": "No se pudo guardar el comentario", "58af69b2314359ae": "Abrir el comentario en el host", - "eb60367cf891f1fa": "{count, plural, one {{count} respuesta} other {{count} respuestas}}", "69a6f3659c32ab5f": "Corregir", "02cc6cf89660f28b": "{count, plural, one {Mostrar {shown} conversación anterior ({count} oculta)} other {Mostrar {shown} conversaciones anteriores ({count} ocultas)}}", + "070e8d2523890f69": "{count, plural, one {{count} hilo} other {{count} hilos}}", + "eb60367cf891f1fa": "{count, plural, one {{count} respuesta} other {{count} respuestas}}", + "e41e9d26c16569a8": "revisó", "201519ca26d70f12": "Revisión descartada", "9b3ae5edeae058a1": "Revisores", "693b49ee48118ad8": "Descripción de la {term, select, mr {merge request} cr {solicitud de cambios} other {pull request}}", diff --git a/apps/web/src/i18n/translations/fr.json b/apps/web/src/i18n/translations/fr.json index d669bbc4efb11..b6afcf3c6349f 100644 --- a/apps/web/src/i18n/translations/fr.json +++ b/apps/web/src/i18n/translations/fr.json @@ -6832,9 +6832,11 @@ "e3e1ec05d1224d36": "Impossible d’enregistrer la description", "faef5657f28d1c69": "Impossible d’enregistrer le commentaire", "58af69b2314359ae": "Ouvrir le commentaire sur l’hôte", - "eb60367cf891f1fa": "{count, plural, one {{count} réponse} other {{count} réponses}}", "69a6f3659c32ab5f": "Corriger", "02cc6cf89660f28b": "{count, plural, one {Afficher {shown} conversation plus ancienne ({count} masquée)} other {Afficher {shown} conversations plus anciennes ({count} masquées)}}", + "070e8d2523890f69": "{count, plural, one {{count} fil} other {{count} fils}}", + "eb60367cf891f1fa": "{count, plural, one {{count} réponse} other {{count} réponses}}", + "e41e9d26c16569a8": "a relu", "201519ca26d70f12": "Revue rejetée", "9b3ae5edeae058a1": "Relecteurs", "693b49ee48118ad8": "Description de la {term, select, mr {merge request} cr {demande de modification} other {pull request}}", diff --git a/apps/web/src/i18n/translations/ja.json b/apps/web/src/i18n/translations/ja.json index ed4596c55e349..3786b8847c38b 100644 --- a/apps/web/src/i18n/translations/ja.json +++ b/apps/web/src/i18n/translations/ja.json @@ -6801,9 +6801,11 @@ "e3e1ec05d1224d36": "説明を保存できませんでした", "faef5657f28d1c69": "コメントを保存できませんでした", "58af69b2314359ae": "ホストでコメントを開く", - "eb60367cf891f1fa": "{count, plural, other {{count} 件の返信}}", "69a6f3659c32ab5f": "修正", "02cc6cf89660f28b": "{count, plural, other {以前の会話 {shown} 件を表示 ({count} 件非表示)}}", + "070e8d2523890f69": "{count, plural, other {{count}件のスレッド}}", + "eb60367cf891f1fa": "{count, plural, other {{count} 件の返信}}", + "e41e9d26c16569a8": "がレビューしました", "201519ca26d70f12": "レビューが却下されました", "9b3ae5edeae058a1": "レビュー担当者", "693b49ee48118ad8": "{term, select, mr {マージリクエストの説明} cr {変更リクエストの説明} other {プルリクエストの説明}}", diff --git a/apps/web/src/i18n/translations/ko.json b/apps/web/src/i18n/translations/ko.json index ccaf79b4ad233..165c8634a76c4 100644 --- a/apps/web/src/i18n/translations/ko.json +++ b/apps/web/src/i18n/translations/ko.json @@ -6803,9 +6803,11 @@ "e3e1ec05d1224d36": "설명을 저장할 수 없습니다", "faef5657f28d1c69": "댓글을 저장할 수 없습니다", "58af69b2314359ae": "호스트에서 댓글 열기", - "eb60367cf891f1fa": "{count, plural, other {답글 {count}개}}", "69a6f3659c32ab5f": "수정", "02cc6cf89660f28b": "{count, plural, other {이전 대화 {shown}개 보기({count}개 숨겨짐)}}", + "070e8d2523890f69": "{count, plural, other {스레드 {count}개}}", + "eb60367cf891f1fa": "{count, plural, other {답글 {count}개}}", + "e41e9d26c16569a8": "리뷰함", "201519ca26d70f12": "검토 무시됨", "9b3ae5edeae058a1": "검토자", "693b49ee48118ad8": "{term, select, mr {병합 요청} cr {변경 요청} other {풀 리퀘스트}} 설명", diff --git a/apps/web/src/i18n/translations/pt-BR.json b/apps/web/src/i18n/translations/pt-BR.json index 16d8eddc5fb9e..04f3441648068 100644 --- a/apps/web/src/i18n/translations/pt-BR.json +++ b/apps/web/src/i18n/translations/pt-BR.json @@ -6831,9 +6831,11 @@ "e3e1ec05d1224d36": "Não foi possível salvar a descrição", "faef5657f28d1c69": "Não foi possível salvar o comentário", "58af69b2314359ae": "Abrir o comentário no host", - "eb60367cf891f1fa": "{count, plural, one {{count} resposta} other {{count} respostas}}", "69a6f3659c32ab5f": "Corrigir", "02cc6cf89660f28b": "{count, plural, one {Mostrar {shown} discussão mais antiga ({count} oculta)} other {Mostrar {shown} discussões mais antigas ({count} ocultas)}}", + "070e8d2523890f69": "{count, plural, one {{count} thread} other {{count} threads}}", + "eb60367cf891f1fa": "{count, plural, one {{count} resposta} other {{count} respostas}}", + "e41e9d26c16569a8": "revisou", "201519ca26d70f12": "Revisão dispensada", "9b3ae5edeae058a1": "Revisores", "693b49ee48118ad8": "Descrição {term, select, mr {do merge request} cr {da solicitação de alteração} other {do pull request}}", diff --git a/apps/web/src/i18n/translations/ru.json b/apps/web/src/i18n/translations/ru.json index 864b12ce4803d..75fe688d00eab 100644 --- a/apps/web/src/i18n/translations/ru.json +++ b/apps/web/src/i18n/translations/ru.json @@ -6831,9 +6831,11 @@ "e3e1ec05d1224d36": "Не удалось сохранить описание", "faef5657f28d1c69": "Не удалось сохранить комментарий", "58af69b2314359ae": "Открыть комментарий на хосте", - "eb60367cf891f1fa": "{count, plural, one {{count} ответ} few {{count} ответа} many {{count} ответов} other {{count} ответа}}", "69a6f3659c32ab5f": "Исправить", "02cc6cf89660f28b": "{count, plural, one {Показать {shown} более старых обсуждений (скрыто {count})} few {Показать {shown} более старых обсуждений (скрыто {count})} many {Показать {shown} более старых обсуждений (скрыто {count})} other {Показать {shown} более старых обсуждений (скрыто {count})}}", + "070e8d2523890f69": "{count, plural, one {{count} тред} few {{count} треда} many {{count} тредов} other {{count} треда}}", + "eb60367cf891f1fa": "{count, plural, one {{count} ответ} few {{count} ответа} many {{count} ответов} other {{count} ответа}}", + "e41e9d26c16569a8": "проверил(а)", "201519ca26d70f12": "Ревью отклонено", "9b3ae5edeae058a1": "Ревьюеры", "693b49ee48118ad8": "{term, select, mr {Описание мерж-реквеста} cr {Описание запроса на изменение} other {Описание пул-реквеста}}", diff --git a/apps/web/src/i18n/translations/sv.json b/apps/web/src/i18n/translations/sv.json index 3464ce9859ab9..0d00396cea434 100644 --- a/apps/web/src/i18n/translations/sv.json +++ b/apps/web/src/i18n/translations/sv.json @@ -6837,9 +6837,11 @@ "e3e1ec05d1224d36": "Kunde inte spara beskrivningen", "faef5657f28d1c69": "Kunde inte spara kommentaren", "58af69b2314359ae": "Öppna kommentaren på värden", - "eb60367cf891f1fa": "{count, plural, one {{count} svar} other {{count} svar}}", "69a6f3659c32ab5f": "Åtgärda", "02cc6cf89660f28b": "{count, plural, one {Visa {shown} äldre konversation ({count} dold)} other {Visa {shown} äldre konversationer ({count} dolda)}}", + "070e8d2523890f69": "{count, plural, one {{count} tråd} other {{count} trådar}}", + "eb60367cf891f1fa": "{count, plural, one {{count} svar} other {{count} svar}}", + "e41e9d26c16569a8": "granskade", "201519ca26d70f12": "Granskningen avfärdades", "9b3ae5edeae058a1": "Granskare", "693b49ee48118ad8": "Beskrivning av {term, select, mr {merge request} cr {ändringsbegäran} other {pull request}}", diff --git a/apps/web/src/i18n/translations/zh.json b/apps/web/src/i18n/translations/zh.json index e5369f33c58a5..bd9ec2a3a840d 100644 --- a/apps/web/src/i18n/translations/zh.json +++ b/apps/web/src/i18n/translations/zh.json @@ -6846,9 +6846,11 @@ "e3e1ec05d1224d36": "无法保存描述", "faef5657f28d1c69": "无法保存评论", "58af69b2314359ae": "在托管平台上打开评论", - "eb60367cf891f1fa": "{count, plural, other {{count} 条回复}}", "69a6f3659c32ab5f": "修复", "02cc6cf89660f28b": "{count, plural, other {显示 {shown} 个较早的对话(已隐藏 {count} 个)}}", + "070e8d2523890f69": "{count, plural, other {{count} 个讨论串}}", + "eb60367cf891f1fa": "{count, plural, other {{count} 条回复}}", + "e41e9d26c16569a8": "已审查", "201519ca26d70f12": "审查已撤销", "9b3ae5edeae058a1": "审查者", "693b49ee48118ad8": "{term, select, mr {MR} cr {change request} other {PR}} 描述", From 71efabc0997f7360b3748567f5d42b4fa1afbc9b Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Wed, 18 Nov 2026 13:43:32 +0000 Subject: [PATCH 17/17] fix(web): guard review replies across tabs --- .../pullRequest/PullRequestDetailPanel.tsx | 1 + .../PullRequestReviewAnnotation.tsx | 12 +++++---- .../PullRequestSummaryTab.browser.test.tsx | 27 +++++++++++++++++++ .../pullRequest/PullRequestSummaryTab.tsx | 4 ++- .../pullRequest/pullRequestReviewStore.ts | 9 +++++++ 5 files changed, 47 insertions(+), 6 deletions(-) diff --git a/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx b/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx index 250d9a9a178ef..761afbe0ca3ec 100644 --- a/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx +++ b/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx @@ -2083,6 +2083,7 @@ export function PullRequestDetailPanel({ {mountedTabs.has("summary") ? (
store.replies[replyKey] ?? ""); + const sending = usePullRequestReviewStore((store) => store.pendingReplies[replyKey] === true); + const pending = actionPending || sending; const storeReply = usePullRequestReviewStore((store) => store.setReply); const clearReply = usePullRequestReviewStore((store) => store.clearReply); const setReply = (next: string) => storeReply(replyKey, next); const [replying, setReplying] = useState(reply.length > 0); - const sendingRef = useRef(false); const replyRef = useRef(null); const gt = useGT(); const send = async (text: string) => { const trimmed = text.trim(); - if (trimmed.length === 0 || pending || sendingRef.current) return; - sendingRef.current = true; + const store = usePullRequestReviewStore.getState(); + if (trimmed.length === 0 || pending || store.pendingReplies[replyKey]) return; + store.setReplyPending(replyKey, true); const result = await settlePromise(() => onReply(trimmed)); - sendingRef.current = false; + store.setReplyPending(replyKey, false); if (result._tag === "Failure") throw squashAtomCommandFailure(result); if (!result.value) return; onSent?.(); diff --git a/apps/web/src/components/pullRequest/PullRequestSummaryTab.browser.test.tsx b/apps/web/src/components/pullRequest/PullRequestSummaryTab.browser.test.tsx index 22d7b3dfa2805..00439901d14eb 100644 --- a/apps/web/src/components/pullRequest/PullRequestSummaryTab.browser.test.tsx +++ b/apps/web/src/components/pullRequest/PullRequestSummaryTab.browser.test.tsx @@ -341,3 +341,30 @@ it("adds a quote that arrives as posting settles along with the ones queued befo await screen.rerender(form(false, { text: "> third" })); await expect.element(screen.getByRole("textbox")).toHaveValue("> second\n\n> third"); }); + +it("blocks another reply form for the same thread while a reply is posting", async () => { + setup(); + const { PullRequestThreadReplyForm } = await import("./PullRequestReviewAnnotation"); + const sent = Promise.withResolvers(); + const onReply = vi.fn(() => sent.promise); + const form = (key: string) => ( + + ); + await using screen = await renderUi(form("summary")); + await userEvent.click(screen.getByRole("button", { name: "Reply" })); + await userEvent.type(screen.getByLabelText("Reply to this conversation"), "A reply"); + await userEvent.click(screen.getByRole("button", { name: "Reply", exact: true })); + await screen.rerender(form("code")); + await expect.element(screen.getByRole("button", { name: "Reply", exact: true })).toBeDisabled(); + await act(async () => sent.resolve(true)); + expect(onReply).toHaveBeenCalledTimes(1); + await expect.element(screen.getByLabelText("Reply to this conversation")).toHaveValue(""); +}); diff --git a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx index f9ad1d536c87b..2881149fdea38 100644 --- a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx +++ b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx @@ -476,6 +476,7 @@ const CommentFilterSchema = Schema.Struct({ bots: Schema.Boolean, resolved: Sche const DEFAULT_COMMENT_FILTER: typeof CommentFilterSchema.Type = { bots: false, resolved: false }; export function PullRequestSummaryTab({ + active = true, revealUrl, onRevealSettled, scrollerRef, @@ -495,6 +496,7 @@ export function PullRequestSummaryTab({ onRefresh, onRefreshChecks = onRefresh, }: { + active?: boolean; /** A clicked link to scroll to, until onRevealSettled reports it shown. */ revealUrl?: string | undefined; onRevealSettled?: ((revealUrl: string) => void) | undefined; @@ -745,7 +747,7 @@ export function PullRequestSummaryTab({ threadId={thread.id} completionScope={completionScope} pending={threadReplyPending} - collapsed={collapsed} + collapsed={collapsed || !active} {...(className === undefined ? {} : { className })} onReply={(body) => sendThreadReply(thread.id, body)} /> diff --git a/apps/web/src/components/pullRequest/pullRequestReviewStore.ts b/apps/web/src/components/pullRequest/pullRequestReviewStore.ts index 03e0dc4ede877..c021d859031d1 100644 --- a/apps/web/src/components/pullRequest/pullRequestReviewStore.ts +++ b/apps/web/src/components/pullRequest/pullRequestReviewStore.ts @@ -25,6 +25,8 @@ interface PullRequestReviewStoreState { readonly summaries: Readonly>; /** Unsent thread replies, so a reply form that remounts elsewhere reads the live draft. */ readonly replies: Readonly>; + readonly pendingReplies: Readonly>; + readonly setReplyPending: (key: string, pending: boolean) => void; readonly addComment: (key: string, comment: PendingReviewComment) => void; readonly removeComment: (key: string, commentId: string) => void; readonly removeComments: (key: string, commentIds: ReadonlyArray) => void; @@ -41,6 +43,13 @@ export const usePullRequestReviewStore = create()(( drafts: {}, summaries: {}, replies: {}, + pendingReplies: {}, + setReplyPending: (key, pending) => + set((state) => { + if (pending) return { pendingReplies: { ...state.pendingReplies, [key]: true } }; + const { [key]: _removed, ...rest } = state.pendingReplies; + return { pendingReplies: rest }; + }), addComment: (key, comment) => set((state) => ({ drafts: { ...state.drafts, [key]: [...(state.drafts[key] ?? EMPTY), comment] },