Skip to content

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

Go

MUL-9575: perf(inbox): mount only the visible rows once the Work panel shows the whole Inbox (#10902)

Multica Eveffc02aaf2d66
diff --git a/e2e/perf/core-paths.spec.ts b/e2e/perf/core-paths.spec.ts
index f7cbaddc30..acce283abe 100644
--- a/e2e/perf/core-paths.spec.ts
+++ b/e2e/perf/core-paths.spec.ts
@@ -261,8 +261,13 @@ test("switch between Inbox rows in the Work panel", async ({ browser }) => {
const firstTitle = manifest.issues[manifest.inbox[0]!.key]!.title;
await expect(rows.filter({ hasText: firstTitle })).toHaveCount(1);
if (INBOX_ROWS === "all") {
- await page.getByRole("button", { name: /^Show \d+ more/ }).first().click();
- await expect.poll(() => rows.count()).toBeGreaterThan(500);
+ const showMore = page.getByRole("button", { name: /^Show \d+ more/ }).first();
+ const hidden = Number((await showMore.textContent())?.match(/\d+/)?.[0] ?? 0);
+ expect(hidden, "the Inbox section hides hundreds of rows").toBeGreaterThan(500);
+ await showMore.click();
+ // A virtualized list mounts only the rows near the viewport, so the
+ // expansion is read from the toggle rather than from the row count.
+ await expect(page.getByRole("button", { name: "Show fewer" }).first()).toHaveAttribute("aria-expanded", "true");
}
await expect.poll(() => rows.count(), "the Inbox section shows the twenty measured rows").toBeGreaterThanOrEqual(20);
await settle(page, 2000);
diff --git a/packages/views/issues/components/issue-detail.test.tsx b/packages/views/issues/components/issue-detail.test.tsx
index 24db9f0b51..d775c53163 100644
--- a/packages/views/issues/components/issue-detail.test.tsx
+++ b/packages/views/issues/components/issue-detail.test.tsx
@@ -3008,26 +3008,39 @@ describe("IssueDetail (shared)", () => {
driftStart ||= performance.now();
return Math.min(performance.now() - driftStart, 300);
};
+ // The update lands between two frames of the alignment loop, after its
+ // second measurement of the mounted anchor. Timing it from the test
+ // instead raced the loop on slow CI runners.
+ let interrupt: (() => void) | null = null;
+ let alignedReads = 0;
+ let interrupted = false;
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) {
+ if (this.dataset.virtualThreadMounted !== "false" && ++alignedReads === 2 && interrupt) {
+ const update = interrupt;
+ setTimeout(() => {
+ update();
+ interrupted = true;
+ }, 0);
+ }
return new DOMRect(0, 250 + drift() - container.scrollTop, 400, 100);
}
return new DOMRect(0, 0, 0, 0);
});
try {
const { queryClient } = renderIssueDetailWithHighlight("comment-2");
+ interrupt = () =>
+ 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" },
+ ]);
+ });
await waitFor(() => expect(hasHighlightedCommentBackground(document.getElementById("comment-comment-2"))).toBe(true));
+ await waitFor(() => expect(interrupted).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 {
diff --git a/packages/views/layout/panel-nav.tsx b/packages/views/layout/panel-nav.tsx
index df409426b6..aa1a7df6a7 100644
--- a/packages/views/layout/panel-nav.tsx
+++ b/packages/views/layout/panel-nav.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useId, useRef } from "react";
+import { createContext, useContext, useId, useRef, type RefObject } from "react";
import { ChevronDown } from "@multica/ui/icons";
import { cn } from "@multica/ui/lib/utils";
import { useScrollFade } from "@multica/ui/hooks/use-scroll-fade";
@@ -62,6 +62,13 @@ export function PanelHeader({
);
}
+const PanelScrollContext = createContext<RefObject<HTMLDivElement | null> | null>(null);
+
+/** The scroll container of the enclosing `PanelBody`, for lists that virtualize inside it. */
+export function usePanelScrollRef() {
+ return useContext(PanelScrollContext);
+}
+
export function PanelBody({
children,
onClickCapture,
@@ -81,7 +88,7 @@ export function PanelBody({
onAuxClickCapture={onAuxClickCapture}
className="scrollbar-slim min-h-0 flex-1 overflow-y-auto overscroll-contain px-2 pb-4 [&>section:first-child]:mt-0"
>
- {children}
+ <PanelScrollContext.Provider value={ref}>{children}</PanelScrollContext.Provider>
</div>
);
}
diff --git a/packages/views/layout/panels/inbox-section.test.tsx b/packages/views/layout/panels/inbox-section.test.tsx
index 0cb4f67760..3525aa56d3 100644
--- a/packages/views/layout/panels/inbox-section.test.tsx
+++ b/packages/views/layout/panels/inbox-section.test.tsx
@@ -14,6 +14,7 @@ import { agentListOptions } from "@multica/core/workspace/queries";
import { snoozedInboxOptions } from "@multica/core/inbox/queries";
import { renderWithI18n } from "../../test/i18n";
import { NavigationProvider, type NavigationAdapter } from "../../navigation";
+import { PanelBody } from "../panel-nav";
import { InboxSection, useInboxSectionRows } from "./inbox-section";
const state = vi.hoisted(() => ({
@@ -621,3 +622,93 @@ describe("InboxSection", () => {
expect(nav.push).toHaveBeenCalledWith("/acme/inbox?view=archived");
});
});
+
+describe("InboxSection with every row shown", () => {
+ const ROW_HEIGHT = 50;
+ const VIEWPORT_HEIGHT = 600;
+
+ /**
+ * jsdom has no layout: the virtualizer reads the panel's and each row's
+ * height from `offsetHeight`, and the list's offset from `getBoundingClientRect`.
+ */
+ function installLayout() {
+ const offsetHeight = Object.getOwnPropertyDescriptor(HTMLElement.prototype, "offsetHeight")!;
+ const offsetWidth = Object.getOwnPropertyDescriptor(HTMLElement.prototype, "offsetWidth")!;
+ const rect = Element.prototype.getBoundingClientRect;
+ Object.defineProperty(HTMLElement.prototype, "offsetHeight", {
+ configurable: true,
+ get(this: HTMLElement) {
+ return this.matches("[data-inbox-row]") ? ROW_HEIGHT : VIEWPORT_HEIGHT;
+ },
+ });
+ Object.defineProperty(HTMLElement.prototype, "offsetWidth", { configurable: true, get: () => 280 });
+ Element.prototype.getBoundingClientRect = () =>
+ ({ width: 280, height: ROW_HEIGHT, top: 0, left: 0, right: 280, bottom: ROW_HEIGHT, x: 0, y: 0, toJSON: () => ({}) }) as DOMRect;
+ return () => {
+ Object.defineProperty(HTMLElement.prototype, "offsetHeight", offsetHeight);
+ Object.defineProperty(HTMLElement.prototype, "offsetWidth", offsetWidth);
+ Element.prototype.getBoundingClientRect = rect;
+ };
+ }
+
+ function renderInPanel(count: number, activeIssueId: string | null = null) {
+ const items = Array.from({ length: count }, (_, i) =>
+ item({
+ id: `n${i}`,
+ issue_id: `issue-${i}`,
+ title: `Issue ${i}`,
+ created_at: new Date(Date.UTC(2026, 10, 10) - i * 60_000).toISOString(),
+ }),
+ );
+ const client = new QueryClient({ defaultOptions: { queries: { retry: false, staleTime: Infinity } } });
+ client.setQueryData(["inbox", "ws-1", "list"], items);
+ client.setQueryData(snoozedInboxOptions("ws-1").queryKey, []);
+ client.setQueryData(agentListOptions("ws-1").queryKey, []);
+ client.setQueryData(agentTaskSnapshotOptions("ws-1").queryKey, []);
+ return renderWithI18n(
+ <QueryClientProvider client={client}>
+ <NavigationProvider value={adapter("/acme/issues")}>
+ <PanelBody>
+ <Harness activeIssueId={activeIssueId} pathname="/acme/issues" openKey={activeIssueId} />
+ </PanelBody>
+ </NavigationProvider>
+ </QueryClientProvider>,
+ );
+ }
+
+ it("mounts only the rows near the panel's viewport, and the rest as the panel scrolls", async () => {
+ const restore = installLayout();
+ try {
+ const { container } = renderInPanel(300, "issue-3");
+ fireEvent.click(screen.getByRole("button", { name: /^Show \d+ more/ }));
+
+ await waitFor(() => expect(rows().length).toBeGreaterThan(0));
+ expect(rows().length).toBeLessThan(40);
+ expect(screen.getByRole("link", { name: /^Issue 0/ })).toBeInTheDocument();
+ expect(screen.getByRole("link", { name: /^Issue 3/ })).toHaveAttribute("aria-current", "page");
+ expect(screen.queryByRole("link", { name: /^Issue 299/ })).toBeNull();
+ // The rows not mounted still take their room, so the panel scrolls as far.
+ const list = container.querySelector<HTMLElement>("[data-sidebar-list]")!;
+ expect(parseFloat(list.style.paddingBottom)).toBeGreaterThan((300 - 40) * ROW_HEIGHT);
+
+ const scroller = container.firstElementChild as HTMLElement;
+ act(() => {
+ // jsdom keeps scrollTop at 0 unless it is defined.
+ Object.defineProperty(scroller, "scrollTop", { configurable: true, value: 300 * (ROW_HEIGHT + 2) });
+ fireEvent.scroll(scroller);
+ });
+ await waitFor(() => expect(screen.getByRole("link", { name: /^Issue 299/ })).toBeInTheDocument());
+ expect(screen.queryByRole("link", { name: /^Issue 0/ })).toBeNull();
+ expect(rows().length).toBeLessThan(40);
+ } finally {
+ restore();
+ }
+ });
+
+ it("keeps a short list fully mounted", () => {
+ useSidebarTreeStore.setState({ inboxSettings: { ...DEFAULT_SIDEBAR_INBOX_SETTINGS, limit: 5 } });
+ renderInPanel(30);
+ fireEvent.click(screen.getByRole("button", { name: "Show 25 more…" }));
+ expect(rows()).toHaveLength(30);
+ });
+});
diff --git a/packages/views/layout/panels/inbox-section.tsx b/packages/views/layout/panels/inbox-section.tsx
index 80e630c54a..14efa835ee 100644
--- a/packages/views/layout/panels/inbox-section.tsx
+++ b/packages/views/layout/panels/inbox-section.tsx
@@ -1,6 +1,7 @@
"use client";
-import { type ReactNode, useMemo, useState } from "react";
+import { type ReactNode, type Ref, useLayoutEffect, useMemo, useState } from "react";
+import { useVirtualizer } from "@tanstack/react-virtual";
import { useQuery } from "@tanstack/react-query";
import { toast } from "sonner";
import { AlarmClock, Archive, BellOff, BookCheck, CheckCheck, History, ListChecks, MoreHorizontal } from "@multica/ui/icons";
@@ -67,6 +68,7 @@ import {
PanelSection,
panelRowAnchor,
panelRowStateClass,
+ usePanelScrollRef,
} from "../panel-nav";
import { InboxSectionSettings, SECTION_SETTINGS_REVEAL_CLASS } from "./sidebar-settings";
import {
@@ -177,6 +179,40 @@ export function InboxSection({
return counts;
}, [list.notifications]);
+ const scrollRef = usePanelScrollRef();
+ const renderRow = (item: InboxItem, measure?: RowMeasure) => (
+ <InboxRow
+ key={item.id}
+ item={item}
+ measure={measure}
+ href={inboxRowHref(p, item)}
+ active={
+ (!!item.issue_id && item.issue_id === activeIssueId) ||
+ (!!openKey && (item.issue_id ?? item.id) === openKey)
+ }
+ compact={compact}
+ kept={list.kept?.item.id === item.id ? keptText.line(list.kept) : null}
+ settled={list.kept?.item.id === item.id && list.kept.reason !== "filtered"}
+ updatesWhileSnoozed={item.issue_id ? (updatesWhileSnoozed.get(item.issue_id) ?? 0) : 0}
+ onArchive={() => {
+ archive(item.id, inboxRowKey(item));
+ leaveIfOpen(item);
+ }}
+ onUnsubscribe={
+ item.issue_id && unsubscribable(item)
+ ? () => {
+ unsubscribeArchive({ id: item.id, issueId: item.issue_id! });
+ leaveIfOpen(item);
+ }
+ : undefined
+ }
+ onSnooze={(until) => {
+ snooze(item, until);
+ leaveIfOpen(item);
+ }}
+ />
+ );
+
return (
<PanelSection
label={t(($) => $.nav.inbox)}
@@ -208,39 +244,13 @@ export function InboxSection({
}
>
{displayed.length > 0 ? (
- <PanelList data-sidebar-list={INBOX_LIST} className={compact ? undefined : "space-y-0.5"}>
- {displayed.map((item) => (
- <InboxRow
- key={item.id}
- item={item}
- href={inboxRowHref(p, item)}
- active={
- (!!item.issue_id && item.issue_id === activeIssueId) ||
- (!!openKey && (item.issue_id ?? item.id) === openKey)
- }
- compact={compact}
- kept={list.kept?.item.id === item.id ? keptText.line(list.kept) : null}
- settled={list.kept?.item.id === item.id && list.kept.reason !== "filtered"}
- updatesWhileSnoozed={item.issue_id ? (updatesWhileSnoozed.get(item.issue_id) ?? 0) : 0}
- onArchive={() => {
- archive(item.id, inboxRowKey(item));
- leaveIfOpen(item);
- }}
- onUnsubscribe={
- item.issue_id && unsubscribable(item)
- ? () => {
- unsubscribeArchive({ id: item.id, issueId: item.issue_id! });
- leaveIfOpen(item);
- }
- : undefined
- }
- onSnooze={(until) => {
- snooze(item, until);
- leaveIfOpen(item);
- }}
- />
- ))}
- </PanelList>
+ displayed.length > VIRTUALIZE_AFTER && scrollRef ? (
+ <VirtualInboxList items={displayed} compact={compact} renderRow={renderRow} />
+ ) : (
+ <PanelList data-sidebar-list={INBOX_LIST} className={compact ? undefined : "space-y-0.5"}>
+ {displayed.map((item) => renderRow(item))}
+ </PanelList>
+ )
) : list.filtered ? (
<div className={cn(PANEL_ROW_CLASS, "pl-[2.375rem] text-caption text-faint-foreground")}>
<span className="min-w-0 flex-1 truncate">{tInbox(($) => $.filters.empty)}</span>
@@ -287,6 +297,81 @@ export function InboxSection({
);
}
+/**
+ * Past this many rows (only reachable through "Show N more") the section
+ * mounts just the rows near the panel's viewport. Every mounted row
+ * re-renders whenever the open issue changes, so a fully mounted list of
+ * ~1,000 notifications made each switch cost seconds.
+ */
+const VIRTUALIZE_AFTER = 50;
+
+/** Estimated row heights and the gaps `space-y-px` / `space-y-0.5` put between rows. */
+const ROW_ESTIMATE = { compact: 32, full: 50 } as const;
+const ROW_GAP = { compact: 1, full: 2 } as const;
+
+/** What a virtualized row hands its `<li>` so the list can measure it. */
+interface RowMeasure {
+ index: number;
+ ref: Ref<HTMLLIElement>;
+}
+
+/**
+ * The Inbox rows, windowed inside the Work panel's own scroll container. The
+ * list stays in normal flow: padding stands in for the rows above and below
+ * the window, so the sections after it keep their place.
+ */
+function VirtualInboxList({
+ items,
+ compact,
+ renderRow,
+}: {
+ items: readonly InboxItem[];
+ compact: boolean;
+ renderRow: (item: InboxItem, measure: RowMeasure) => ReactNode;
+}) {
+ const scrollRef = usePanelScrollRef()!;
+ const [list, setList] = useState<HTMLUListElement | null>(null);
+ // Where the list starts within the scroll container's content.
+ const [scrollMargin, setScrollMargin] = useState(0);
+ useLayoutEffect(() => {
+ const scroller = scrollRef.current;
+ if (!list || !scroller) return;
+ const measure = () =>
+ setScrollMargin(list.getBoundingClientRect().top - scroller.getBoundingClientRect().top + scroller.scrollTop);
+ measure();
+ const observer = new ResizeObserver(measure);
+ observer.observe(scroller);
+ return () => observer.disconnect();
+ }, [list, scrollRef]);
+
+ const virtualizer = useVirtualizer({
+ count: items.length,
+ getScrollElement: () => scrollRef.current,
+ estimateSize: () => (compact ? ROW_ESTIMATE.compact : ROW_ESTIMATE.full),
+ gap: compact ? ROW_GAP.compact : ROW_GAP.full,
+ getItemKey: (index) => items[index]!.id,
+ scrollMargin,
+ // Rows past the viewport stay mounted, so Tab can always reach the next one.
+ overscan: 10,
+ });
+ const virtualRows = virtualizer.getVirtualItems();
+ const first = virtualRows[0];
+ const last = virtualRows[virtualRows.length - 1];
+ const paddingTop = first ? first.start - scrollMargin : 0;
+ const paddingBottom = last ? virtualizer.getTotalSize() - (last.end - scrollMargin) : 0;
+
+ return (
+ <PanelList
+ ref={setList}
+ data-sidebar-list={INBOX_LIST}
+ className={compact ? undefined : "space-y-0.5"}
+ style={{ paddingTop, paddingBottom }}
+ >
+ {virtualRows.map((row) => renderRow(items[row.index]!, { index: row.index, ref: virtualizer.measureElement }))}
+ </PanelList>
+ );
+}
+
function InboxSectionActions({
wsId,
rows,
@@ -421,6 +506,7 @@ function InboxSectionActions({
function InboxRow({
item,
+ measure,
href,
active,
compact,
@@ -432,6 +518,8 @@ function InboxRow({
onSnooze,
}: {
item: InboxItem;
+ /** Set when the row is one of a virtualized list's window. */
+ measure?: RowMeasure;
href: string;
active: boolean;
/** One line (status, title, agents, dot or time) instead of the actor line under the title. */
@@ -524,7 +612,13 @@ function InboxRow({
);
return (
- <li data-inbox-row data-read={unread ? "false" : "true"} className="group/inbox relative">
+ <li
+ ref={measure?.ref}
+ data-index={measure?.index}
+ data-inbox-row
+ data-read={unread ? "false" : "true"}
+ className="group/inbox relative"
+ >
<HoverCard
open={cardOpen && !snoozeOpen}
onOpenChange={(open) => {