Skip to content

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

Go

fix(issues): scroll to the newly posted comment in both timeline modes (MUL-6140)

Homyee King ホミイ8d9766d4b090
diff --git a/packages/views/issues/components/comment-card.tsx b/packages/views/issues/components/comment-card.tsx
index 8fa1f5fd38..3c5f9f06eb 100644
--- a/packages/views/issues/components/comment-card.tsx
+++ b/packages/views/issues/components/comment-card.tsx
@@ -106,7 +106,8 @@ interface CommentCardProps {
* `CommentRow` has to rerun the rule per row.
*/
canModerate?: boolean;
- onReply: (parentId: string, content: string, attachmentIds?: string[], suppressAgentIds?: string[]) => Promise<boolean>;
+ onReply: (parentId: string, content: string, attachmentIds?: string[], suppressAgentIds?: string[]) => Promise<string | boolean>;
+ onReplyAccepted?: (commentId: string) => void;
onEdit: (commentId: string, content: string, attachmentIds: string[], suppressAgentIds?: string[]) => Promise<void>;
onDelete: (commentId: string) => void;
onToggleReaction: (commentId: string, emoji: string) => void;
@@ -751,6 +752,7 @@ function CommentCardImpl({
currentUserId,
canModerate = false,
onReply,
+ onReplyAccepted,
onEdit,
onDelete,
onToggleReaction,
@@ -1138,6 +1140,7 @@ function CommentCardImpl({
avatarId={currentUserId ?? ""}
draftKey={`reply:${issueId}:${entry.id}`}
onSubmit={(content, attachmentIds, suppressAgentIds) => onReply(entry.id, content, attachmentIds, suppressAgentIds)}
+ onAccepted={onReplyAccepted}
/>
</div>
</>
diff --git a/packages/views/issues/components/comment-composers.test.tsx b/packages/views/issues/components/comment-composers.test.tsx
index 339ffb5677..5f835b5cc9 100644
--- a/packages/views/issues/components/comment-composers.test.tsx
+++ b/packages/views/issues/components/comment-composers.test.tsx
@@ -217,11 +217,13 @@ function renderCommentInput(onSubmit = vi.fn().mockResolvedValue(true)) {
}
function renderReplyInput({
- onSubmit = vi.fn().mockResolvedValue(true),
+ onSubmit = vi.fn().mockResolvedValue("reply-new"),
+ onAccepted,
size = "sm",
draftKey,
}: {
- onSubmit?: (content: string, attachmentIds?: string[], suppressAgentIds?: string[]) => Promise<boolean>;
+ onSubmit?: (content: string, attachmentIds?: string[], suppressAgentIds?: string[]) => Promise<string | boolean>;
+ onAccepted?: (commentId: string) => void;
size?: "sm" | "default";
draftKey?: `reply:${string}:${string}`;
} = {}) {
@@ -232,6 +234,7 @@ function renderReplyInput({
avatarType="member"
avatarId="user-1"
onSubmit={onSubmit}
+ onAccepted={onAccepted}
size={size}
draftKey={draftKey}
/>,
@@ -510,6 +513,18 @@ describe("comment composers", () => {
expect(focusCalls.blurred).toBe(0);
});
+ it("reports the new reply id as the accepted scroll target", async () => {
+ const onAccepted = vi.fn();
+ const { container } = renderReplyInput({ onAccepted });
+
+ activateComposer("reply-composer-shell");
+ fireEvent.change(screen.getByTestId("editor"), { target: { value: "replied" } });
+ fireEvent.click(getSubmitButton(container));
+
+ await waitFor(() => expect(onAccepted).toHaveBeenCalledTimes(1));
+ expect(onAccepted).toHaveBeenCalledWith("reply-new");
+ });
+
it("does not refocus the reply box when the send fails", async () => {
const onSubmit = vi.fn().mockResolvedValue(false);
const { container } = renderReplyInput({ onSubmit });
diff --git a/packages/views/issues/components/comment-input.tsx b/packages/views/issues/components/comment-input.tsx
index e22ef0ab64..5df8dca227 100644
--- a/packages/views/issues/components/comment-input.tsx
+++ b/packages/views/issues/components/comment-input.tsx
@@ -20,10 +20,12 @@ interface CommentInputProps {
/** Resolves true on success, false on failure. The composer keeps the text
* (editor locked + button spinning) until this settles, then clears only on
* success — a failed send must not silently discard the user's draft. */
- onSubmit: (content: string, attachmentIds?: string[], suppressAgentIds?: string[]) => Promise<boolean>;
+ onSubmit: (content: string, attachmentIds?: string[], suppressAgentIds?: string[]) => Promise<string | boolean>;
+ /** Called after the server accepts the comment and the composer is cleared. */
+ onAccepted?: (commentId: string) => void;
}
-function CommentInput({ issueId, onSubmit }: CommentInputProps) {
+function CommentInput({ issueId, onSubmit, onAccepted }: CommentInputProps) {
const { t } = useT("issues");
const { t: tEditor } = useT("editor");
const sendShortcut = useShortcut("send");
@@ -135,6 +137,7 @@ function CommentInput({ issueId, onSubmit }: CommentInputProps) {
// leave a mid-flight draft in place: dropping the caret then would yank it
// out of the sentence the user is still typing.
const editorScrubbedRef = useRef(false);
+ const acceptedCommentIdRef = useRef<string | null>(null);
const { submitting, submit } = useComposerSubmit({
editorRef,
@@ -164,7 +167,10 @@ function CommentInput({ issueId, onSubmit }: CommentInputProps) {
content,
activeIds.length > 0 ? activeIds : undefined,
suppressAgentIds.length > 0 ? suppressAgentIds : undefined,
- );
+ ).then((commentId) => {
+ acceptedCommentIdRef.current = typeof commentId === "string" ? commentId : null;
+ return !!commentId;
+ });
},
onAccepted: () => {
// Success may only consume the entry it submitted (MUL-5181 P0): edits
@@ -184,6 +190,7 @@ function CommentInput({ issueId, onSubmit }: CommentInputProps) {
setIsEmpty(true);
setSuppressedAgentIds(new Set());
editorScrubbedRef.current = true;
+ if (acceptedCommentIdRef.current) onAccepted?.(acceptedCommentIdRef.current);
},
});
diff --git a/packages/views/issues/components/issue-detail.test.tsx b/packages/views/issues/components/issue-detail.test.tsx
index dca4351721..909fd48b5c 100644
--- a/packages/views/issues/components/issue-detail.test.tsx
+++ b/packages/views/issues/components/issue-detail.test.tsx
@@ -1,6 +1,6 @@
import { forwardRef, useEffect, useRef, useState, useImperativeHandle } from "react";
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
-import { fireEvent, render, screen, waitFor } from "@testing-library/react";
+import { fireEvent, render, screen, waitFor, within } from "@testing-library/react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import type { Issue, Label, TimelineEntry } from "@multica/core/types";
import { I18nProvider } from "@multica/core/i18n/react";
@@ -434,6 +434,7 @@ vi.mock("@multica/core/issues/stores", async () => ({
// background instead, which is mechanism-independent and observable without
// layout.
const scrollIntoViewSpy = vi.hoisted(() => vi.fn());
+const scrollToIndexSpy = vi.hoisted(() => vi.fn());
vi.mock("react-virtuoso", () => ({
Virtuoso: forwardRef(function MockVirtuoso(
@@ -445,7 +446,7 @@ vi.mock("react-virtuoso", () => ({
// since the deep-link cold-path drives the container's scrollTop on the
// real DOM node, not Virtuoso's imperative API.
scrollIntoView: vi.fn(),
- scrollToIndex: vi.fn(),
+ scrollToIndex: scrollToIndexSpy,
}));
return (
<div data-testid="virtuoso-mock">
@@ -461,6 +462,7 @@ vi.mock("react-virtuoso", () => ({
// with a spy so the deep-link effect's call can be observed.
beforeEach(() => {
scrollIntoViewSpy.mockClear();
+ scrollToIndexSpy.mockClear();
Object.defineProperty(HTMLElement.prototype, "scrollIntoView", {
configurable: true,
writable: true,
@@ -919,6 +921,36 @@ describe("IssueDetail (shared)", () => {
expect(container.querySelector(".sticky.bottom-0")).toBeNull();
});
+ it("realigns after Virtuoso measures the newly posted row", async () => {
+ mockApiObj.createComment.mockResolvedValue({
+ id: "comment-new",
+ issue_id: "issue-1",
+ content: "A new update",
+ author_type: "member",
+ author_id: "user-1",
+ parent_id: null,
+ type: "comment",
+ created_at: "2026-08-13T00:00:00Z",
+ updated_at: "2026-08-13T00:00:00Z",
+ });
+ renderIssueDetail();
+
+ await screen.findByText("Implement authentication");
+ fireEvent.click(screen.getByTestId("comment-composer-shell"));
+ const editor = await screen.findByPlaceholderText("Leave a comment...");
+ fireEvent.change(editor, { target: { value: "A new update" } });
+ const composer = editor.closest<HTMLElement>("[aria-busy], .relative.flex.flex-col.rounded-lg")!;
+ fireEvent.click(within(composer).getByRole("button", { name: "Send" }));
+
+ expect(scrollToIndexSpy).not.toHaveBeenCalled();
+ await waitFor(() => {
+ expect(scrollToIndexSpy).toHaveBeenCalledTimes(2);
+ });
+ expect(scrollToIndexSpy).toHaveBeenNthCalledWith(1, { index: 2, align: "end", offset: 0 });
+ expect(scrollToIndexSpy).toHaveBeenNthCalledWith(2, { index: 2, align: "end", offset: 0 });
+ expect(scrollIntoViewSpy).not.toHaveBeenCalled();
+ });
+
it("reserves the chat launcher's corner at the end of the mobile scroll", async () => {
mockViewport.isMobile = true;
diff --git a/packages/views/issues/components/issue-detail.tsx b/packages/views/issues/components/issue-detail.tsx
index 8ea3be2736..d4ad548ba3 100644
--- a/packages/views/issues/components/issue-detail.tsx
+++ b/packages/views/issues/components/issue-detail.tsx
@@ -1191,6 +1191,9 @@ export function IssueDetail({ issueId, onDelete, onDone, defaultSidebarOpen = tr
// Virtuoso prop would never receive the element. Callback ref + state fixes
// that: setState triggers the re-render that hands Virtuoso the element.
const [scrollContainerEl, setScrollContainerEl] = useState<HTMLDivElement | null>(null);
+ // Bottom comment composer. Measured when scrolling a freshly posted comment
+ // into view so its bottom lands above the composer rather than behind it.
+ const composerRef = useRef<HTMLDivElement | null>(null);
// Pull-based scroll restoration (MUL-4741): the platform serves the offset
// captured when this route was last left. The ref-attach assignment covers
// the flat render modes (real heights at commit); the virtualized browsing
@@ -1228,6 +1231,10 @@ export function IssueDetail({ issueId, onDelete, onDone, defaultSidebarOpen = tr
},
[restoreScrollRef],
);
+ const [pendingPostedCommentId, setPendingPostedCommentId] = useState<string | null>(null);
+ const scrollToTimelineBottom = useCallback((commentId: string) => {
+ setPendingPostedCommentId(commentId);
+ }, []);
const [highlightedId, setHighlightedId] = useState<string | null>(null);
// User preference: pin the bottom comment bar to the scroll viewport. Off
// below `md` regardless of the preference — see the hook.
@@ -1577,6 +1584,73 @@ export function IssueDetail({ issueId, onDelete, onDone, defaultSidebarOpen = tr
// Virtuoso instance — minimap jumps drive the scroll container directly.
const isFlatTimeline = !!highlightCommentId || find.open;
const virtuosoRef = useRef<VirtuosoHandle>(null);
+ // Scroll a freshly posted comment into view, aligned so its bottom sits just
+ // above the sticky composer (never behind it). A reply lives inside its root
+ // CommentCard, so the containing top-level row is the scroll target. Flat and
+ // virtualized timelines need separate scroll drivers, so they split into two
+ // effects below — kept apart because only the flat one depends on
+ // `scrollContainerEl`, and adding that dep to the virtualized effect would
+ // let a container re-measure cancel its in-flight scroll mid-flight.
+
+ // Virtualized mode: Virtuoso owns the scroll. The first jump materializes the
+ // row at its estimated height; once measured, the repeat aligns using the
+ // real height. The extra `offset` lifts the row's bottom clear of the sticky
+ // composer.
+ useEffect(() => {
+ if (!pendingPostedCommentId || isFlatTimeline) return;
+ const rootId = replyToRoot.get(pendingPostedCommentId) ?? pendingPostedCommentId;
+ const index = items.findIndex((item) => item.id === rootId);
+ if (index < 0) return;
+ let timer: number | undefined;
+ const scrollEnd = () => {
+ const composerHeight = composerRef.current?.getBoundingClientRect().height ?? 0;
+ virtuosoRef.current?.scrollToIndex({ index, align: "end", offset: composerHeight });
+ };
+ const frame = requestAnimationFrame(() => {
+ scrollEnd();
+ timer = window.setTimeout(() => {
+ scrollEnd();
+ setPendingPostedCommentId(null);
+ }, 100);
+ });
+ return () => {
+ cancelAnimationFrame(frame);
+ if (timer !== undefined) window.clearTimeout(timer);
+ };
+ }, [pendingPostedCommentId, items, replyToRoot, isFlatTimeline]);
+
+ // Flat mode (find bar / deep link) has no Virtuoso, so drive scrollTop by
+ // hand: align the row's bottom to the composer's top edge. The comment's
+ // async layout (markdown, code highlight, images) keeps shifting its height,
+ // so re-align each frame until it settles (within 1px) or ~0.5s elapses — the
+ // same rAF stabilization the deep-link landing uses.
+ useEffect(() => {
+ if (!pendingPostedCommentId || !isFlatTimeline) return;
+ const rootId = replyToRoot.get(pendingPostedCommentId) ?? pendingPostedCommentId;
+ if (items.findIndex((item) => item.id === rootId) < 0) return;
+ let rafId = 0;
+ let frames = 0;
+ let last = -1;
+ const alignBottom = () => {
+ const el = document.getElementById(`comment-${rootId}`);
+ const container = scrollContainerEl;
+ if (el && container) {
+ const c = container.getBoundingClientRect();
+ const e = el.getBoundingClientRect();
+ const composerHeight = composerRef.current?.getBoundingClientRect().height ?? 0;
+ const target = Math.max(0, container.scrollTop + (e.bottom - c.bottom) + composerHeight);
+ container.scrollTop = target;
+ if (Math.abs(target - last) > 1 && ++frames < 30) {
+ last = target;
+ rafId = requestAnimationFrame(alignBottom);
+ return;
+ }
+ }
+ setPendingPostedCommentId(null);
+ };
+ rafId = requestAnimationFrame(alignBottom);
+ return () => cancelAnimationFrame(rafId);
+ }, [pendingPostedCommentId, items, replyToRoot, isFlatTimeline, scrollContainerEl]);
const jumpFlashTimerRef = useRef<number | null>(null);
useEffect(
() => () => {
@@ -2472,6 +2546,7 @@ export function IssueDetail({ issueId, onDelete, onDone, defaultSidebarOpen = tr
currentUserId={user?.id}
canModerate={canModerateComments}
onReply={submitReply}
+ onReplyAccepted={scrollToTimelineBottom}
onEdit={editComment}
onDelete={deleteComment}
onToggleReaction={handleToggleReaction}
@@ -3146,6 +3221,7 @@ export function IssueDetail({ issueId, onDelete, onDone, defaultSidebarOpen = tr
off the viewport edge — with -mb-4 giving the padding back to
the column's py-8 so the at-rest layout doesn't shift. */}
<div
+ ref={composerRef}
className={cn(
"mt-4",
stickyComposer &&
@@ -3157,7 +3233,12 @@ export function IssueDetail({ issueId, onDelete, onDone, defaultSidebarOpen = tr
keeps the previous issue's in-memory content and the
next keystroke would flush it into the new issue's
draft key. */}
- <CommentInput key={id} issueId={id} onSubmit={submitComment} />
+ <CommentInput
+ key={id}
+ issueId={id}
+ onSubmit={submitComment}
+ onAccepted={scrollToTimelineBottom}
+ />
</div>
</div>
</div>
diff --git a/packages/views/issues/components/reply-input.tsx b/packages/views/issues/components/reply-input.tsx
index d672c089eb..91642aa764 100644
--- a/packages/views/issues/components/reply-input.tsx
+++ b/packages/views/issues/components/reply-input.tsx
@@ -28,7 +28,9 @@ interface ReplyInputProps {
avatarId: string;
/** Resolves true on success, false on failure — the reply box keeps its text
* (locked + spinning) until then, clearing only on success. */
- onSubmit: (content: string, attachmentIds?: string[], suppressAgentIds?: string[]) => Promise<boolean>;
+ onSubmit: (content: string, attachmentIds?: string[], suppressAgentIds?: string[]) => Promise<string | boolean>;
+ /** Called after the server accepts the reply and the composer is cleared. */
+ onAccepted?: (commentId: string) => void;
size?: "sm" | "default";
/** When set, hydrates/persists the in-progress reply via the draft store.
* Required for replies inside virtualized timeline threads, where the
@@ -47,6 +49,7 @@ function ReplyInput({
avatarType,
avatarId,
onSubmit,
+ onAccepted,
size = "default",
draftKey,
}: ReplyInputProps) {
@@ -147,6 +150,7 @@ function ReplyInput({
// See CommentInput: bound to the branch that actually wiped the editor, so a
// draft the stale-submit guard kept is never disturbed.
const editorScrubbedRef = useRef(false);
+ const acceptedCommentIdRef = useRef<string | null>(null);
const { submitting, submit } = useComposerSubmit({
editorRef,
@@ -179,7 +183,10 @@ function ReplyInput({
content,
activeIds.length > 0 ? activeIds : undefined,
suppressAgentIds.length > 0 ? suppressAgentIds : undefined,
- );
+ ).then((commentId) => {
+ acceptedCommentIdRef.current = typeof commentId === "string" ? commentId : null;
+ return !!commentId;
+ });
},
onAccepted: () => {
// Success may only consume the entry it submitted — see CommentInput.
@@ -200,6 +207,7 @@ function ReplyInput({
setIsEmpty(true);
setSuppressedAgentIds(new Set());
editorScrubbedRef.current = true;
+ if (acceptedCommentIdRef.current) onAccepted?.(acceptedCommentIdRef.current);
},
});
diff --git a/packages/views/issues/hooks/use-issue-timeline.ts b/packages/views/issues/hooks/use-issue-timeline.ts
index d874ddec56..0704986bab 100644
--- a/packages/views/issues/hooks/use-issue-timeline.ts
+++ b/packages/views/issues/hooks/use-issue-timeline.ts
@@ -302,12 +302,12 @@ export function useIssueTimeline(issueId: string, userId?: string) {
// on success — so a slow send no longer leaves the box full next to an
// already-posted comment, and a failed send keeps the draft.
const submitComment = useCallback(
- async (content: string, attachmentIds?: string[], suppressAgentIds?: string[]): Promise<boolean> => {
+ async (content: string, attachmentIds?: string[], suppressAgentIds?: string[]): Promise<string | false> => {
if (!content.trim() || !userId) return false;
try {
const comment = await createComment({ content, attachmentIds, suppressAgentIds });
warnUnhandledTriggers(comment?.trigger_outcomes, comment?.content);
- return true;
+ return comment.id;
} catch (err) {
toast.error(
err instanceof Error && err.message
@@ -321,7 +321,7 @@ export function useIssueTimeline(issueId: string, userId?: string) {
);
const submitReply = useCallback(
- async (parentId: string, content: string, attachmentIds?: string[], suppressAgentIds?: string[]): Promise<boolean> => {
+ async (parentId: string, content: string, attachmentIds?: string[], suppressAgentIds?: string[]): Promise<string | false> => {
if (!content.trim() || !userId) return false;
try {
const comment = await createComment({
@@ -332,7 +332,7 @@ export function useIssueTimeline(issueId: string, userId?: string) {
suppressAgentIds,
});
warnUnhandledTriggers(comment?.trigger_outcomes, comment?.content);
- return true;
+ return comment.id;
} catch (err) {
toast.error(
err instanceof Error && err.message