Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(issues): keep Inbox comment landings alive through mid-landing updates (MUL-9068) (#10391)
Bohan Jiang957e7568e2c5
diff --git a/e2e/issue-timeline-scroll.spec.ts b/e2e/issue-timeline-scroll.spec.tsindex 712f37445d..00a4d9d4a9 100644--- a/e2e/issue-timeline-scroll.spec.ts+++ b/e2e/issue-timeline-scroll.spec.ts@@ -182,3 +182,50 @@ test("scrolling up a virtualized long thread keeps the reading position steady",await api.cleanup();}});++test("Inbox landing survives a comment that arrives while it is still aligning", async ({ page }) => {+ test.setTimeout(180_000);+ await page.setViewportSize({ width: 1440, height: 900 });+ const api = await createTestApi();+ try {+ const slug = await loginAsDefault(page);+ const title = "Inbox landing during realtime updates";+ const body = (lines: number) => Array.from({ length: lines }, (_, j) => `Line ${j}. ${"Agent reply text that wraps. ".repeat(4)}`).join("\n\n");+ const issue = await api.createIssue(title, { description: body(8) });+ // The shape of a busy agent issue: two threads of nested member/agent+ // exchanges, the notification on the newest agent reply.+ const first = await api.createComment(issue.id, "First thread root");+ let parent = first;+ for (let i = 0; i < 4; i++) parent = await api.createComment(issue.id, i % 2 ? "Follow-up" : body(20), parent.id);+ const second = await api.createComment(issue.id, "Second thread root");+ let targetId = "";+ for (let i = 0; i < 7; i++) {+ const ask = await api.createComment(issue.id, `Member ask ${i}`, second.id);+ targetId = (await api.createComment(issue.id, body(5 + (i % 4) * 5), ask.id)).id;+ }+ const other = await api.createIssue("Another notification", { description: "Short." });+ await api.seedCommentNotification(other.id, (await api.createComment(other.id, "Other comment")).id, "Another notification");+ await api.seedCommentNotification(issue.id, targetId, title);++ await page.goto(`/${slug}/inbox`);+ // A realtime comment re-renders the timeline mid-landing. Before MUL-9068+ // that cancelled the alignment for good, or aligned a replaced row that+ // measured as zero and scrolled the detail back to the top.+ for (const delay of [0, 120, 240, 360]) {+ await page.getByText(title, { exact: true }).first().click();+ await page.locator(`[data-tab-scroll-root="main:${issue.id}"]`).waitFor();+ await page.waitForTimeout(delay);+ await api.createComment(issue.id, `Arrived after ${delay}ms`, first.id);+ let stable = 0;+ await expect.poll(async () => {+ const p = await readingPosition(page, targetId);+ stable = p?.mounted && p.visible ? stable + 1 : 0;+ return stable;+ }, { message: `landing after a ${delay}ms update`, timeout: 10_000, intervals: [200] }).toBeGreaterThanOrEqual(5);+ await page.getByText("Another notification", { exact: true }).first().click();+ await expect(page.getByText("Other comment")).toBeVisible();+ }+ } finally {+ await api.cleanup();+ }+});diff --git a/packages/views/issues/components/issue-detail.test.tsx b/packages/views/issues/components/issue-detail.test.tsxindex 209282cff3..84a16ae8db 100644--- a/packages/views/issues/components/issue-detail.test.tsx+++ b/packages/views/issues/components/issue-detail.test.tsx@@ -2791,6 +2791,42 @@ describe("IssueDetail (shared)", () => {expect(landedBeforeGrouping).toBe(false);});+ it("restarts a comment landing that a timeline update cancels while it is still aligning", async () => {+ mockApiObj.listTasksByIssue.mockResolvedValue([]);+ // The anchor keeps moving for 300ms, like reply heights settling, so the+ // alignment loop is still running when the update arrives.+ let driftStart = 0;+ const drift = () => {+ driftStart ||= performance.now();+ return Math.min(performance.now() - driftStart, 300);+ };+ const rect = vi.spyOn(HTMLElement.prototype, "getBoundingClientRect").mockImplementation(function (this: HTMLElement) {+ const container = this.closest<HTMLElement>("[data-tab-scroll-root]");+ if (this === container) return new DOMRect(0, 0, 400, 200);+ if (this.id === "comment-comment-2" && container) {+ return new DOMRect(0, 250 + drift() - container.scrollTop, 400, 100);+ }+ return new DOMRect(0, 0, 0, 0);+ });+ try {+ const { queryClient } = renderIssueDetailWithHighlight("comment-2");+ await waitFor(() => expect(hasHighlightedCommentBackground(document.getElementById("comment-comment-2"))).toBe(true));+ const container = document.querySelector<HTMLElement>("[data-tab-scroll-root]")!;+ act(() => {+ queryClient.setQueryData<TimelineEntry[]>(["issues", "timeline", "issue-1"], (old) => [+ ...(old ?? []),+ { ...mockTimeline[0]!, id: "comment-late", content: "Arrived mid-landing", created_at: "2026-01-18T00:00:00Z" },+ ]);+ });+ expect(driftStart).toBeGreaterThan(0);+ expect(performance.now() - driftStart).toBeLessThan(300);+ // 250 + 300 drift - 16 top gap: where the comment sits once settled.+ await waitFor(() => expect(container.scrollTop).toBe(534), { timeout: 2000 });+ } finally {+ rect.mockRestore();+ }+ });+it("folds an assignment reply with its resolved parent and unfolds that thread for a notification", async () => {const run: AgentTask = { id: "ba2e8d1c-7f9b-4e2a-9c1d-123456789abc", agent_id: "agent-1", runtime_id: "runtime-1", issue_id: "issue-1",kind: "direct", status: "completed", priority: 0, created_at: "2026-01-16T00:00:00Z", started_at: null, dispatched_at: null,diff --git a/packages/views/issues/components/issue-detail.tsx b/packages/views/issues/components/issue-detail.tsxindex c81a4413fe..c7a8d455b0 100644--- a/packages/views/issues/components/issue-detail.tsx+++ b/packages/views/issues/components/issue-detail.tsx@@ -1702,6 +1702,9 @@ export function IssueDetail({ issueId, onDelete, onDone, defaultSidebarOpen = tr});}, []);const didHighlightRef = useRef<string | null>(null);+ // Highlight whose landing was cancelled after its anchor mounted but before+ // it finished aligning; the landing effect resumes it.+ const interruptedLandingRef = useRef<string | null>(null);// Last seen highlightRequestToken; a bump re-arms didHighlightRef so the// landing effect below replays on an already-mounted detail.const lastHighlightRequestTokenRef = useRef(highlightRequestToken);@@ -2160,10 +2163,10 @@ export function IssueDetail({ issueId, onDelete, onDone, defaultSidebarOpen = tr// Flash the landed comment the same way inbox deep-links do, so the eye has// an anchor after the instant jump. (Folded resolved bars don't take the// highlight prop — the scroll itself is the feedback there.)- const flashJumpTarget = useCallback((commentId: string) => {+ const flashJumpTarget = useCallback((commentId: string, duration = 2000) => {setHighlightedId(commentId);if (jumpFlashTimerRef.current !== null) window.clearTimeout(jumpFlashTimerRef.current);- jumpFlashTimerRef.current = window.setTimeout(() => setHighlightedId(null), 2000);+ jumpFlashTimerRef.current = window.setTimeout(() => setHighlightedId(null), duration);}, []);// Jump to a mounted comment: any row in flat mode, or a reply inside a// rendered thread. Drive the container's scrollTop directly — never native@@ -2516,12 +2519,14 @@ export function IssueDetail({ issueId, onDelete, onDone, defaultSidebarOpen = trlastHighlightRequestTokenRef.current = highlightRequestToken;didHighlightRef.current = null;}- if (didHighlightRef.current === highlightCommentId) return;+ // A landing this effect's cleanup cut short resumes (see the cleanup).+ const resuming = interruptedLandingRef.current === highlightCommentId;+ if (!resuming && didHighlightRef.current === highlightCommentId) return;// The deep link already landed before this mount (memento entry — a tab// switch back or an in-tab return). The restored scroll offset is the// state the user left, and the jump must not fight it. A fresh selection// clears the entry, so this only ever suppresses a *repeat* landing.- if (!activeDeliverableJump && consumedHighlightRef.current === highlightCommentId) {+ if (!resuming && !activeDeliverableJump && consumedHighlightRef.current === highlightCommentId) {didHighlightRef.current = highlightCommentId;return;}@@ -2573,22 +2578,33 @@ export function IssueDetail({ issueId, onDelete, onDone, defaultSidebarOpen = tr}}- let fade: number | undefined;+ interruptedLandingRef.current = null;+ let completed = false;const cancel = scrollToTimelineComment({container, virtualizer: isFlatTimeline ? null : virtuosoRef.current,index: targetIdx, commentId: landingId,onMounted: () => {didHighlightRef.current = highlightCommentId;writeViewState(issueHighlightMementoKey(id), highlightCommentId);- setHighlightedId(landingId);- fade = window.setTimeout(() => setHighlightedId(null), 2500);+ // Timer owned outside this effect, so a re-run cannot leave the+ // highlight on.+ flashJumpTarget(landingId, 2500);},+ onComplete: () => { completed = true; },});return () => {cancel();- if (fade !== undefined) clearTimeout(fade);+ // A commit while the landing is still aligning (a realtime comment, a+ // run refresh, the refetch of a cached timeline) re-runs this effect and+ // cancels the loop here. Once the anchor has mounted, the guards above+ // count the landing as done, so mark it for the re-run to resume;+ // otherwise the viewport stays wherever the loop stopped, often the top+ // of the issue (MUL-9068).+ if (!completed && didHighlightRef.current === highlightCommentId) {+ interruptedLandingRef.current = highlightCommentId;+ }};- }, [highlightCommentId, highlightRequestToken, activeDeliverableJump, id, writeViewState, items, targetIdx, scrollContainerEl, highlightRootId, expandedResolved, timelineView, toggleResolvedExpand, isFlatTimeline, measuredTimelineId, timelineLoading, commentTasksLoading]);+ }, [highlightCommentId, highlightRequestToken, activeDeliverableJump, id, writeViewState, items, targetIdx, scrollContainerEl, highlightRootId, expandedResolved, timelineView, toggleResolvedExpand, isFlatTimeline, measuredTimelineId, timelineLoading, commentTasksLoading, flashJumpTarget]);const descEditorRef = useRef<ContentEditorRef>(null);const descriptionEditingRef = useRef(false);diff --git a/packages/views/issues/utils/scroll-to-timeline-comment.test.ts b/packages/views/issues/utils/scroll-to-timeline-comment.test.tsnew file mode 100644index 0000000000..d5ed57de1b--- /dev/null+++ b/packages/views/issues/utils/scroll-to-timeline-comment.test.ts@@ -0,0 +1,40 @@+import { afterEach, describe, expect, it, vi } from "vitest";+import { scrollToTimelineComment } from "./scroll-to-timeline-comment";++const frame = () => new Promise((resolve) => requestAnimationFrame(resolve));++function anchor(container: HTMLElement, top: number) {+ const el = document.createElement("div");+ el.id = "comment-target";+ // Positioned like a real row: its viewport top moves with the scroll.+ el.getBoundingClientRect = () => el.isConnected+ ? new DOMRect(0, top - container.scrollTop, 400, 100)+ : new DOMRect(0, 0, 0, 0);+ return el;+}++describe("scrollToTimelineComment", () => {+ afterEach(() => { document.body.innerHTML = ""; });++ it("follows an anchor that a commit replaces between frames instead of scrolling to the top", async () => {+ const container = document.createElement("div");+ container.getBoundingClientRect = () => new DOMRect(0, 0, 400, 600);+ Object.defineProperty(container, "clientHeight", { value: 600 });+ document.body.append(container);+ container.append(anchor(container, 5000));+ const onComplete = vi.fn();+ const onMounted = vi.fn(() => {+ // The same commit that mounted the row re-renders it before the+ // alignment frame: the node the landing found is gone.+ container.replaceChildren(anchor(container, 5000));+ });++ scrollToTimelineComment({ container, virtualizer: null, index: 0, commentId: "target", onMounted, onComplete });+ for (let i = 0; i < 10 && !onComplete.mock.calls.length; i++) await frame();++ expect(onMounted).toHaveBeenCalledTimes(1);+ expect(onComplete).toHaveBeenCalled();+ // 5000 - (600 - 100) / 2: the replacement row, centred.+ expect(container.scrollTop).toBe(4750);+ });+});diff --git a/packages/views/issues/utils/scroll-to-timeline-comment.ts b/packages/views/issues/utils/scroll-to-timeline-comment.tsindex 46ac656991..a7a9be7a00 100644--- a/packages/views/issues/utils/scroll-to-timeline-comment.ts+++ b/packages/views/issues/utils/scroll-to-timeline-comment.ts@@ -42,8 +42,9 @@ export function scrollToTimelineComment({container.scrollTop = target;return target;};+ const findAnchor = () => container.querySelector<HTMLElement>(`[id="comment-${commentId}"]`);const land = () => {- const el = container.querySelector<HTMLElement>(`[id="comment-${commentId}"]`);+ const el = findAnchor();if (!el || el.dataset.virtualThreadMounted === "false") {if (el) alignTarget(el, true);if (++mountFrames < 60) rafId = requestAnimationFrame(land);@@ -52,7 +53,18 @@ export function scrollToTimelineComment({}if (!mounted) { mounted = true; onMounted?.(); }const align = () => {- const target = alignTarget(el);+ // Look the anchor up again every frame. A commit between frames can+ // unmount or replace it (Virtuoso re-ranging rows while a realtime update+ // lands); a detached node measures as zero, which would scroll the+ // timeline to the top and pass for a settled landing (MUL-9068).+ const current = findAnchor();+ if (!current || current.dataset.virtualThreadMounted === "false") {+ if (++frames >= 30) { onComplete?.(); return; }+ if (!current) virtualizer?.scrollIntoView({ index, align: "start", done: queueLanding });+ queueLanding();+ return;+ }+ const target = alignTarget(current);if (Math.abs(target - last) > 1 && ++frames < 30) {last = target;rafId = requestAnimationFrame(align);