Skip to content

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

Go

perf(issues): stop sidebar toggles from re-rendering the issue timeline (MUL-9426) (#10767)

Bohan Jiang6073d1e39cd0
diff --git a/packages/views/issues/components/agent-run-comment-memo.test.tsx b/packages/views/issues/components/agent-run-comment-memo.test.tsx
new file mode 100644
index 0000000000..425eb0af5f
--- /dev/null
+++ b/packages/views/issues/components/agent-run-comment-memo.test.tsx
@@ -0,0 +1,142 @@
+import { describe, expect, it, vi } from "vitest";
+import { forwardRef, type ReactNode } from "react";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import type { AgentTask, TimelineEntry } from "@multica/core/types";
+import { renderWithI18n } from "../../test/i18n";
+
+// MUL-9426: the timeline rebuilds an agent reply's `commentProps` on every
+// render. A sidebar toggle re-renders the visible rows each animation frame,
+// and every agent reply on screen used to re-render with them.
+
+const runStateCalls = vi.hoisted(() => ({ count: 0 }));
+
+vi.mock("./inline-comment-run", async () => {
+ const actual = await vi.importActual<typeof import("./inline-comment-run")>("./inline-comment-run");
+ return {
+ ...actual,
+ // The run's own activity block is not under test and needs a workspace.
+ InlineCommentRun: () => null,
+ PlacedInlineCommentRun: () => null,
+ useInlineCommentRunState: () => {
+ runStateCalls.count += 1;
+ return actual.useInlineCommentRunState();
+ },
+ };
+});
+
+vi.mock("@multica/core/api", () => ({
+ api: { uploadFile: vi.fn() },
+ dispatchReasonCode: () => undefined,
+ errorCode: () => undefined,
+}));
+
+vi.mock("../../navigation", () => ({
+ useNavigation: () => ({
+ push: vi.fn(),
+ pathname: "/acme/issues",
+ getShareableUrl: (p: string) => `https://app.example${p}`,
+ }),
+}));
+
+vi.mock("@multica/core/workspace/hooks", () => ({
+ useActorName: () => ({ getActorName: () => "Ada" }),
+}));
+
+vi.mock("../../common/actor-avatar", () => ({
+ ActorAvatar: () => null,
+}));
+
+vi.mock("../hooks/use-comment-trigger-preview", () => ({
+ useCommentTriggerPreview: () => ({ agents: [], blocked: [] }),
+}));
+
+vi.mock("../../editor", async () => ({
+ ...(await vi.importActual<typeof import("../../editor/use-upload-gate")>("../../editor/use-upload-gate")),
+ ...(await vi.importActual<typeof import("../../editor/use-lazy-editor")>("../../editor/use-lazy-editor")),
+ ...(await vi.importActual<typeof import("../../editor/use-composer-submit")>("../../editor/use-composer-submit")),
+ useEditorUpload: () => ({ uploadWithToast: vi.fn(), upload: vi.fn(), uploading: false }),
+ useFileDropZone: () => ({ isDragOver: false, dropZoneProps: {} }),
+ FileDropOverlay: () => null,
+ ReadonlyContent: ({ content }: { content: string }) => <div>{content}</div>,
+ Attachment: () => null,
+ AttachmentDownloadProvider: ({ children }: { children: ReactNode }) => <>{children}</>,
+ ContentEditor: forwardRef(function MockContentEditor() {
+ return <textarea data-testid="editor" />;
+ }),
+}));
+
+import { AgentRunComment } from "./comment-card";
+
+const reply: TimelineEntry = {
+ type: "comment",
+ id: "reply-1",
+ actor_type: "agent",
+ actor_id: "agent-1",
+ content: "Agent report",
+ parent_id: null,
+ comment_type: "comment",
+ reactions: [],
+ attachments: [],
+ created_at: "2026-09-11T07:00:00Z",
+ updated_at: "2026-09-11T07:00:00Z",
+ revision: 1,
+};
+
+const run = {
+ task: {
+ id: "task-1",
+ agent_id: "agent-1",
+ issue_id: "issue-1",
+ status: "completed",
+ created_at: "2026-09-11T06:59:00Z",
+ started_at: "2026-09-11T06:59:00Z",
+ completed_at: "2026-09-11T07:00:00Z",
+ } as AgentTask,
+ commentId: reply.id,
+ hasReply: true,
+};
+
+const handlers = {
+ onReply: vi.fn().mockResolvedValue(true),
+ onEdit: vi.fn().mockResolvedValue(undefined),
+ onDelete: vi.fn(),
+ onToggleReaction: vi.fn(),
+ onCopyLink: vi.fn(),
+ onCreateSubIssue: vi.fn(),
+};
+const replies: TimelineEntry[] = [];
+
+function renderRun() {
+ const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } });
+ // A fresh `commentProps` object every time, as the timeline's renderItem builds it.
+ const view = (entry: TimelineEntry) => (
+ <QueryClientProvider client={qc}>
+ <AgentRunComment run={run} standalone commentProps={{
+ issueId: "issue-1", entry, replies, currentUserId: "user-1", ...handlers,
+ }} />
+ </QueryClientProvider>
+ );
+ const result = renderWithI18n(view(reply));
+ return { ...result, update: (entry: TimelineEntry) => result.rerender(view(entry)) };
+}
+
+describe("AgentRunComment memoization", () => {
+ it("skips re-rendering when the rebuilt commentProps carry the same values", () => {
+ const { update, getByText } = renderRun();
+ expect(getByText("Agent report")).toBeInTheDocument();
+ const rendered = runStateCalls.count;
+
+ update(reply);
+ update(reply);
+ expect(runStateCalls.count).toBe(rendered);
+ });
+
+ it("re-renders when a commentProps value changes", () => {
+ const { update, getByText } = renderRun();
+ const rendered = runStateCalls.count;
+
+ update({ ...reply, content: "Edited report" });
+ expect(runStateCalls.count).toBe(rendered + 1);
+ expect(getByText("Edited report")).toBeInTheDocument();
+ });
+});
diff --git a/packages/views/issues/components/comment-card.tsx b/packages/views/issues/components/comment-card.tsx
index 80c5db3a25..30ba716605 100644
--- a/packages/views/issues/components/comment-card.tsx
+++ b/packages/views/issues/components/comment-card.tsx
@@ -1065,8 +1065,7 @@ function ReplyToQuote({ entry, onJump }: { entry: TimelineEntry; onJump?: (comme
);
}
-/** A run without a persisted reply still belongs to the agent, never its trigger author. */
-export function AgentRunComment({ run, standalone = false, commentProps, entering = false, replyTo, highlightedId, managedAnchor = false }: {
+type AgentRunCommentProps = {
run: CommentRun;
managedAnchor?: boolean;
standalone?: boolean;
@@ -1076,7 +1075,33 @@ export function AgentRunComment({ run, standalone = false, commentProps, enterin
replyTo?: ReactNode;
/** The flashed jump target: the slot's comment id, or the run's task id until it has one. */
highlightedId?: string | null;
-}) {
+};
+
+function shallowEqual<T extends object>(a: T | undefined, b: T | undefined): boolean {
+ if (a === b) return true;
+ if (!a || !b) return false;
+ const keys = Object.keys(a) as (keyof T)[];
+ if (keys.length !== Object.keys(b).length) return false;
+ return keys.every((key) => Object.is(a[key], b[key]));
+}
+
+/**
+ * The timeline rebuilds `commentProps` on every render, so a plain shallow
+ * compare would never match. Its fields are the same stable values
+ * `CommentCard` already memoizes on; compare them one level down. Without
+ * this every agent reply on screen re-rendered on each Virtuoso range or
+ * height update — every frame of a sidebar toggle (MUL-9426).
+ */
+function agentRunCommentPropsEqual(prev: AgentRunCommentProps, next: AgentRunCommentProps): boolean {
+ const { commentProps: prevComment, ...prevRest } = prev;
+ const { commentProps: nextComment, ...nextRest } = next;
+ return shallowEqual(prevRest, nextRest) && shallowEqual(prevComment, nextComment);
+}
+
+/** A run without a persisted reply still belongs to the agent, never its trigger author. */
+export const AgentRunComment = memo(AgentRunCommentImpl, agentRunCommentPropsEqual);
+
+function AgentRunCommentImpl({ run, standalone = false, commentProps, entering = false, replyTo, highlightedId, managedAnchor = false }: AgentRunCommentProps) {
const viewState = useInlineCommentRunState();
const replyEntry = commentProps?.entry;
// A deleted reply renders nothing in a run slot either (see CommentRow), so
diff --git a/packages/views/issues/components/issue-detail.tsx b/packages/views/issues/components/issue-detail.tsx
index 4d6d1bf904..15467a63da 100644
--- a/packages/views/issues/components/issue-detail.tsx
+++ b/packages/views/issues/components/issue-detail.tsx
@@ -11,7 +11,7 @@ import { IssueAppRequests } from "../../common/app-requests";
import { useStatusLabel } from "../utils/status-label";
import { priorityLabel } from "../utils/priority-label";
import { useIssueStatuses } from "@multica/core/issue-statuses/hooks";
-import { useState, useEffect, useCallback, useMemo, useRef, useId, Fragment, type ReactNode } from "react";
+import { useState, useEffect, useCallback, useMemo, useRef, useId, Fragment, type ComponentProps, type ReactNode } from "react";
import { Virtuoso, type ListRange, type VirtuosoHandle } from "react-virtuoso";
import { useDefaultLayout, usePanelRef } from "react-resizable-panels";
import { AppLink, useBackOrReplace } from "../../navigation";
@@ -2847,7 +2847,6 @@ export function IssueDetail({ issueId, onDelete, onDone, onUnsubscribeArchive, d
// Called before the `if (!issue)` early return so hook order stays stable.
const actions = useIssueActions(issue);
const handleUpdateField = actions.updateField;
- const showInSidebar = useShowInSidebar(issue);
// The inbox passes `onDone` and owns archive and restore there.
const archivedInboxItemId = useArchivedInboxItemId(id, !onDone);
const pageMenu = useIssuePageMenu();
@@ -3630,15 +3629,15 @@ export function IssueDetail({ issueId, onDelete, onDone, onUnsubscribeArchive, d
>
{actions.isPinned ? <PinOff /> : <Pin />}
</IconButton>
- <IssueActionsDropdown
+ <IssueDetailActionsDropdown
issue={issue}
+ locateInSidebar={!isPeek}
align="end"
// When a parent passes `onDelete`, we detect deletion via effect
// above and skip navigation. Otherwise the modal takes us back
// to the list we came from, falling back to all issues.
onDeletedFallbackPath={onDelete ? undefined : paths.issues()}
archivedInboxItemId={archivedInboxItemId}
- onShowInSidebar={isPeek ? undefined : (showInSidebar ?? undefined)}
rowMenu={pageMenu.rowMenu}
trigger={
<IconButton
@@ -4465,6 +4464,20 @@ export function IssueDetail({ issueId, onDelete, onDone, onUnsubscribeArchive, d
);
}
+/**
+ * The ⋯ menu with "Show in sidebar". `useShowInSidebar` reads the shell and
+ * sidebar contexts, which change on every nav toggle; reading them here
+ * instead of in `IssueDetail` keeps a toggle from re-rendering the whole
+ * page (MUL-9426).
+ */
+function IssueDetailActionsDropdown({
+ locateInSidebar,
+ ...props
+}: Omit<ComponentProps<typeof IssueActionsDropdown>, "onShowInSidebar"> & { locateInSidebar: boolean }) {
+ const showInSidebar = useShowInSidebar(props.issue);
+ return <IssueActionsDropdown {...props} onShowInSidebar={locateInSidebar ? (showInSidebar ?? undefined) : undefined} />;
+}
+
/** The workflow the issue follows through its project (MUL-7420). */
function IssueWorkflowPropRow({
projectId,