Skip to content

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

Go

feat(issues): MUL-8324 add Jump to latest button to issue timeline (#9627)

Multica Eve87647b8ff47d
diff --git a/packages/views/issues/components/issue-detail.tsx b/packages/views/issues/components/issue-detail.tsx
index 215ea69365..92aad4b070 100644
--- a/packages/views/issues/components/issue-detail.tsx
+++ b/packages/views/issues/components/issue-detail.tsx
@@ -33,6 +33,7 @@ import {
Tag,
Unlink,
Users,
+ ArrowDown,
} from "lucide-react";
import { BreadcrumbHeader, type BreadcrumbSegment } from "../../layout/breadcrumb-header";
import { Skeleton } from "@multica/ui/components/ui/skeleton";
@@ -180,6 +181,7 @@ import { MetadataSection } from "./metadata-section";
import { IssueSidebarSectionHeader, IssueSidebarStack, IssueSidebarPropertyGrid } from "./issue-sidebar-section";
import { useT } from "../../i18n";
import { useIssueDetailScrollRestore } from "../hooks/use-issue-detail-scroll-restore";
+import { useJumpToLatest } from "../hooks/use-jump-to-latest";
import { useInPageFind } from "../hooks/use-in-page-find";
import { useStickyComposer } from "../hooks/use-sticky-composer";
import { FindBar } from "./find-bar";
@@ -572,6 +574,21 @@ function shallowEqualEntries(a: TimelineEntry[], b: TimelineEntry[]): boolean {
return true;
}
+function JumpToLatestButton({ onClick, label }: { onClick: () => void; label: string }) {
+ return (
+ <Button
+ type="button"
+ variant="outline"
+ size="sm"
+ onClick={onClick}
+ className="absolute bottom-full left-1/2 mb-6 -translate-x-1/2 rounded-full bg-background shadow-md"
+ >
+ <ArrowDown />
+ {label}
+ </Button>
+ );
+}
+
// Flat per-item shape consumed by <Virtuoso>. Virtuoso needs a flat array
// where each entry is one rendered row; we keep the grouping logic from
// `timelineView.groups` (consecutive same-actor activities still collapse
@@ -1437,6 +1454,7 @@ export function IssueDetail({ issueId, onDelete, onDone, defaultSidebarOpen = tr
// User preference: pin the bottom comment bar to the scroll viewport. Off
// below `md` regardless of the preference — see the hook.
const stickyComposer = useStickyComposer();
+ const jumpToLatest = useJumpToLatest(scrollContainerEl);
// Per-session: which resolved threads the user has temporarily expanded.
// Not persisted (matches Linear) — reload collapses everything back to bars.
@@ -3904,6 +3922,15 @@ export function IssueDetail({ issueId, onDelete, onDone, defaultSidebarOpen = tr
page background and is invisible), and pb-4 so the card floats
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. */}
+ {/* "Jump to latest" (MUL-8324) floats centered just above the
+ composer's top edge. With the sticky composer it rides the
+ composer itself; without it, a zero-height sticky anchor pins
+ it to the viewport bottom until the composer scrolls in. */}
+ {!stickyComposer && jumpToLatest.visible && (
+ <div className="sticky bottom-0 z-10 h-0">
+ <JumpToLatestButton onClick={jumpToLatest.jump} label={t(($) => $.timeline.jump_to_latest)} />
+ </div>
+ )}
<div
ref={composerRef}
className={cn(
@@ -3917,6 +3944,9 @@ 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. */}
+ {stickyComposer && jumpToLatest.visible && (
+ <JumpToLatestButton onClick={jumpToLatest.jump} label={t(($) => $.timeline.jump_to_latest)} />
+ )}
<CommentInput
key={id}
issueId={id}
diff --git a/packages/views/issues/hooks/use-jump-to-latest.test.tsx b/packages/views/issues/hooks/use-jump-to-latest.test.tsx
new file mode 100644
index 0000000000..0ecd5b8709
--- /dev/null
+++ b/packages/views/issues/hooks/use-jump-to-latest.test.tsx
@@ -0,0 +1,177 @@
+import { useState } from "react";
+import { act, fireEvent, render, screen } from "@testing-library/react";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { JUMP_FOLLOW_MS, useJumpToLatest } from "./use-jump-to-latest";
+
+let rafCallbacks: FrameRequestCallback[] = [];
+let now = 0;
+
+function flushFrame(advanceMs = 16) {
+ now += advanceMs;
+ act(() => {
+ const callbacks = rafCallbacks;
+ rafCallbacks = [];
+ callbacks.forEach((cb) => cb(performance.now()));
+ });
+}
+
+// jsdom has no layout: give the scroller fixed metrics and clamp scrollTop
+// like a browser would. `scrollHeight` is mutable so a test can grow the
+// content mid-jump the way Virtuoso measuring real row heights does.
+function defineMetrics(el: HTMLElement, metrics: { scrollHeight: number; clientHeight: number }) {
+ let top = 0;
+ Object.defineProperty(el, "clientHeight", { configurable: true, get: () => metrics.clientHeight });
+ Object.defineProperty(el, "scrollHeight", { configurable: true, get: () => metrics.scrollHeight });
+ Object.defineProperty(el, "scrollTop", {
+ configurable: true,
+ get: () => top,
+ set: (v: number) => {
+ top = Math.max(0, Math.min(v, metrics.scrollHeight - metrics.clientHeight));
+ },
+ });
+}
+
+function Harness({ metrics }: { metrics: { scrollHeight: number; clientHeight: number } }) {
+ const [el, setEl] = useState<HTMLDivElement | null>(null);
+ const { visible, jump } = useJumpToLatest(el);
+ return (
+ <div
+ data-testid="scroller"
+ ref={(node) => {
+ if (node && node !== el) {
+ defineMetrics(node, metrics);
+ setEl(node);
+ }
+ }}
+ >
+ {visible && <button onClick={jump}>latest</button>}
+ </div>
+ );
+}
+
+beforeEach(() => {
+ rafCallbacks = [];
+ now = 0;
+ vi.spyOn(performance, "now").mockImplementation(() => now);
+ vi.stubGlobal("requestAnimationFrame", (cb: FrameRequestCallback) => {
+ rafCallbacks.push(cb);
+ return rafCallbacks.length;
+ });
+ vi.stubGlobal("cancelAnimationFrame", () => {});
+});
+
+afterEach(() => {
+ vi.unstubAllGlobals();
+ vi.restoreAllMocks();
+});
+
+describe("useJumpToLatest", () => {
+ it("shows only when the bottom is more than one viewport away", () => {
+ render(<Harness metrics={{ scrollHeight: 2000, clientHeight: 500 }} />);
+ const scroller = screen.getByTestId("scroller");
+ expect(screen.getByRole("button", { name: "latest" })).toBeTruthy();
+
+ scroller.scrollTop = 1100; // 400px from the bottom
+ fireEvent.scroll(scroller);
+ flushFrame();
+ expect(screen.queryByRole("button", { name: "latest" })).toBeNull();
+ });
+
+ it("hides once the reader is past the middle of a long page", () => {
+ render(<Harness metrics={{ scrollHeight: 4000, clientHeight: 500 }} />);
+ const scroller = screen.getByTestId("scroller");
+
+ scroller.scrollTop = 1400; // 2100px left below: more than half the page
+ fireEvent.scroll(scroller);
+ flushFrame();
+ expect(screen.getByRole("button", { name: "latest" })).toBeTruthy();
+
+ scroller.scrollTop = 1600; // 1900px left: still several screens, but past the middle
+ fireEvent.scroll(scroller);
+ flushFrame();
+ expect(screen.queryByRole("button", { name: "latest" })).toBeNull();
+ });
+
+ it("stays hidden for a timeline shorter than two viewports", () => {
+ render(<Harness metrics={{ scrollHeight: 900, clientHeight: 500 }} />);
+ expect(screen.queryByRole("button", { name: "latest" })).toBeNull();
+ });
+
+ it("chases the bottom while content keeps growing", () => {
+ const metrics = { scrollHeight: 2000, clientHeight: 500 };
+ render(<Harness metrics={metrics} />);
+ const scroller = screen.getByTestId("scroller");
+
+ fireEvent.click(screen.getByRole("button", { name: "latest" }));
+ expect(scroller.scrollTop).toBe(1500);
+
+ metrics.scrollHeight = 2600; // tail rows measured taller than estimated
+ flushFrame();
+ expect(scroller.scrollTop).toBe(2100);
+ });
+
+ it("stops chasing once the reader scrolls", () => {
+ const metrics = { scrollHeight: 2000, clientHeight: 500 };
+ render(<Harness metrics={metrics} />);
+ const scroller = screen.getByTestId("scroller");
+
+ fireEvent.click(screen.getByRole("button", { name: "latest" }));
+ fireEvent.wheel(scroller);
+ scroller.scrollTop = 300;
+ metrics.scrollHeight = 2600;
+ flushFrame();
+ flushFrame();
+ expect(scroller.scrollTop).toBe(300);
+ });
+
+ it("keeps following when content grows after the bottom held still", () => {
+ const metrics = { scrollHeight: 2000, clientHeight: 500 };
+ render(<Harness metrics={metrics} />);
+ const scroller = screen.getByTestId("scroller");
+
+ fireEvent.click(screen.getByRole("button", { name: "latest" }));
+ // Bottom holds for several frames, then a late tail image lands.
+ for (let i = 0; i < 5; i++) flushFrame();
+ expect(scroller.scrollTop).toBe(1500);
+ metrics.scrollHeight = 3800;
+ flushFrame(250);
+ expect(scroller.scrollTop).toBe(3300);
+ });
+
+ it("stops following once the follow window ends", () => {
+ const metrics = { scrollHeight: 2000, clientHeight: 500 };
+ render(<Harness metrics={metrics} />);
+ const scroller = screen.getByTestId("scroller");
+
+ fireEvent.click(screen.getByRole("button", { name: "latest" }));
+ flushFrame(JUMP_FOLLOW_MS);
+ metrics.scrollHeight = 2600;
+ flushFrame();
+ flushFrame();
+ expect(scroller.scrollTop).toBe(1500);
+ });
+
+ it("stops following on a key pressed outside the scroller", () => {
+ const metrics = { scrollHeight: 2000, clientHeight: 500 };
+ render(<Harness metrics={metrics} />);
+ const scroller = screen.getByTestId("scroller");
+
+ fireEvent.click(screen.getByRole("button", { name: "latest" }));
+ // The button unmounts and focus falls back to <body>.
+ fireEvent.keyDown(document.body, { key: "PageUp" });
+ scroller.scrollTop = 600;
+ metrics.scrollHeight = 2600;
+ flushFrame();
+ flushFrame();
+ expect(scroller.scrollTop).toBe(600);
+ });
+
+ it("releases the document key listener when the follow ends", () => {
+ const remove = vi.spyOn(document, "removeEventListener");
+ render(<Harness metrics={{ scrollHeight: 2000, clientHeight: 500 }} />);
+
+ fireEvent.click(screen.getByRole("button", { name: "latest" }));
+ flushFrame(JUMP_FOLLOW_MS);
+ expect(remove).toHaveBeenCalledWith("keydown", expect.any(Function), true);
+ });
+});
diff --git a/packages/views/issues/hooks/use-jump-to-latest.ts b/packages/views/issues/hooks/use-jump-to-latest.ts
new file mode 100644
index 0000000000..ddcfc68236
--- /dev/null
+++ b/packages/views/issues/hooks/use-jump-to-latest.ts
@@ -0,0 +1,116 @@
+import { useCallback, useEffect, useRef, useState } from "react";
+
+/**
+ * Drives the issue timeline's "Jump to latest" affordance (MUL-8324).
+ *
+ * `visible` is on while the reader is in the first half of the page and the
+ * newest entry is more than one screen away; see `shouldShow`.
+ *
+ * `jump` drives scrollTop to the bottom directly instead of asking Virtuoso
+ * for the last index: with `customScrollParent`, writing scrollTop is what
+ * makes Virtuoso materialize the tail rows, and those rows then grow as their
+ * real heights (markdown, code, images) land. The rAF loop keeps re-pinning
+ * the bottom for `JUMP_FOLLOW_MS`, or until the reader scrolls themselves.
+ */
+/** How long a jump keeps re-pinning the bottom while late content lands. */
+export const JUMP_FOLLOW_MS = 2000;
+
+export function useJumpToLatest(scrollContainerEl: HTMLElement | null) {
+ const [visible, setVisible] = useState(false);
+ const cancelJumpRef = useRef<(() => void) | null>(null);
+
+ useEffect(() => {
+ if (!scrollContainerEl) {
+ setVisible(false);
+ return;
+ }
+ let frame = 0;
+ const measure = () => {
+ frame = 0;
+ setVisible(shouldShow(scrollContainerEl));
+ };
+ const schedule = () => {
+ if (frame === 0) frame = requestAnimationFrame(measure);
+ };
+ measure();
+ scrollContainerEl.addEventListener("scroll", schedule, { passive: true });
+ // Content height changes without a scroll event (rows measured, comments
+ // streamed in, threads expanded), so observe the content too.
+ const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(schedule);
+ observer?.observe(scrollContainerEl);
+ for (const child of Array.from(scrollContainerEl.children)) observer?.observe(child);
+ return () => {
+ scrollContainerEl.removeEventListener("scroll", schedule);
+ observer?.disconnect();
+ if (frame !== 0) cancelAnimationFrame(frame);
+ };
+ }, [scrollContainerEl]);
+
+ useEffect(() => () => cancelJumpRef.current?.(), []);
+
+ const jump = useCallback(() => {
+ const el = scrollContainerEl;
+ if (!el) return;
+ cancelJumpRef.current?.();
+
+ // Follow the bottom for a fixed window rather than until it looks stable:
+ // a tail image or code block can resolve after the list has already held
+ // still for several frames, and quitting early lands the reader short of
+ // the newest entry (MUL-8324 review). The reader taking over ends it.
+ const deadline = performance.now() + JUMP_FOLLOW_MS;
+ let frame = 0;
+ let cancelled = false;
+ const toBottom = () => {
+ el.scrollTop = el.scrollHeight - el.clientHeight;
+ };
+ const tick = () => {
+ if (cancelled) return;
+ if (!el.isConnected || performance.now() >= deadline) {
+ stop();
+ return;
+ }
+ if (distanceFromBottom(el) > 1) toBottom();
+ frame = requestAnimationFrame(tick);
+ };
+
+ // Pointer input lands on the scroller itself. Keys do not: clicking the
+ // button unmounts it, focus falls back to <body>, and PageUp/arrows then
+ // never pass through the scroller — so listen for keys on the document,
+ // in the capture phase, for the duration of the follow.
+ const userInputs = ["wheel", "touchstart", "pointerdown"] as const;
+ const doc = el.ownerDocument;
+ const stop = () => {
+ cancelled = true;
+ cancelAnimationFrame(frame);
+ for (const type of userInputs) el.removeEventListener(type, stop);
+ doc.removeEventListener("keydown", stop, true);
+ if (cancelJumpRef.current === stop) cancelJumpRef.current = null;
+ };
+ for (const type of userInputs) el.addEventListener(type, stop, { passive: true });
+ doc.addEventListener("keydown", stop, { capture: true, passive: true });
+ cancelJumpRef.current = stop;
+
+ toBottom();
+ frame = requestAnimationFrame(tick);
+ }, [scrollContainerEl]);
+
+ return { visible, jump };
+}
+
+/**
+ * Show only while the reader is in the first half of the page: what is left
+ * below the viewport must be more than half of the page, and more than one
+ * screen. Past the midpoint the latest entry is close enough to scroll to by
+ * hand, and short pages never show the button at all.
+ */
+function shouldShow(el: HTMLElement) {
+ const remaining = distanceFromBottom(el);
+ return remaining > el.clientHeight && remaining > el.scrollHeight * SHOW_REMAINING_RATIO;
+}
+
+/** Share of the page that must still be below the viewport for the button to show. */
+const SHOW_REMAINING_RATIO = 0.5;
+
+function distanceFromBottom(el: HTMLElement) {
+ return el.scrollHeight - el.scrollTop - el.clientHeight;
+}
diff --git a/packages/views/locales/en/issues.json b/packages/views/locales/en/issues.json
index e6f1ead39a..3c81190ccf 100644
--- a/packages/views/locales/en/issues.json
+++ b/packages/views/locales/en/issues.json
@@ -502,7 +502,8 @@
"pull_requests_empty_title": "No linked pull requests."
},
"timeline": {
- "loading": "Loading..."
+ "loading": "Loading...",
+ "jump_to_latest": "Jump to latest"
},
"activity": {
"created": "created this issue",
diff --git a/packages/views/locales/fr/issues.json b/packages/views/locales/fr/issues.json
index 5736941adc..3dedb41903 100644
--- a/packages/views/locales/fr/issues.json
+++ b/packages/views/locales/fr/issues.json
@@ -501,7 +501,8 @@
"pull_requests_empty_title": "Aucune pull request associée."
},
"timeline": {
- "loading": "Chargement..."
+ "loading": "Chargement...",
+ "jump_to_latest": "Aller au plus récent"
},
"activity": {
"created": "a créé cette tâche",
diff --git a/packages/views/locales/ja/issues.json b/packages/views/locales/ja/issues.json
index c49521b003..d2107d75d0 100644
--- a/packages/views/locales/ja/issues.json
+++ b/packages/views/locales/ja/issues.json
@@ -496,7 +496,8 @@
"pull_requests_empty_title": "関連する PR はありません。"
},
"timeline": {
- "loading": "読み込み中..."
+ "loading": "読み込み中...",
+ "jump_to_latest": "最新に移動"
},
"activity": {
"created": "このタスクを作成しました",
diff --git a/packages/views/locales/ko/issues.json b/packages/views/locales/ko/issues.json
index 628c0a6a91..b8b98bcf65 100644
--- a/packages/views/locales/ko/issues.json
+++ b/packages/views/locales/ko/issues.json
@@ -496,7 +496,8 @@
"pull_requests_empty_title": "연결된 PR이 없습니다."
},
"timeline": {
- "loading": "불러오는 중..."
+ "loading": "불러오는 중...",
+ "jump_to_latest": "최신으로 이동"
},
"activity": {
"created": "이 태스크를 만들었습니다",
diff --git a/packages/views/locales/zh-Hans/issues.json b/packages/views/locales/zh-Hans/issues.json
index e077c849ed..6082c78939 100644
--- a/packages/views/locales/zh-Hans/issues.json
+++ b/packages/views/locales/zh-Hans/issues.json
@@ -496,7 +496,8 @@
"pull_requests_empty_title": "暂无关联 PR。"
},
"timeline": {
- "loading": "加载中…"
+ "loading": "加载中…",
+ "jump_to_latest": "跳到最新"
},
"activity": {
"created": "创建了这个任务",
diff --git a/packages/views/locales/zh-Hant/issues.json b/packages/views/locales/zh-Hant/issues.json
index 5cf7e696e7..e7fd45b59a 100644
--- a/packages/views/locales/zh-Hant/issues.json
+++ b/packages/views/locales/zh-Hant/issues.json
@@ -495,7 +495,8 @@
"pull_requests_empty_title": "暫無關聯 PR。"
},
"timeline": {
- "loading": "載入中…"
+ "loading": "載入中…",
+ "jump_to_latest": "跳到最新"
},
"activity": {
"created": "建立了這個任務",