Skip to content

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

Go

MUL-9409: perf(issues): virtualize long-content threads and remember reply heights (#10744)

Bohan Jiang9b3982711d25
diff --git a/packages/views/issues/components/comment-card-virtual-rows.test.tsx b/packages/views/issues/components/comment-card-virtual-rows.test.tsx
new file mode 100644
index 0000000000..8f5260b566
--- /dev/null
+++ b/packages/views/issues/components/comment-card-virtual-rows.test.tsx
@@ -0,0 +1,168 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { act, fireEvent, screen } from "@testing-library/react";
+import { forwardRef, type ReactNode } from "react";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import type { TimelineEntry } from "@multica/core/types";
+import { renderWithI18n } from "../../test/i18n";
+
+// Which threads mount their replies on demand (MUL-9409). The timeline's
+// Virtuoso sees a thread as one item, so a thread of a few very long replies
+// used to mount all of them at once; it now virtualizes by content as well as
+// by row count.
+
+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 { CommentCard } from "./comment-card";
+import { resetRememberedThreadRowHeights } from "./virtual-thread-row";
+
+// Nothing intersects until a test says so: virtualized rows start as
+// placeholders, and `intersectAll` reports every observed row in view.
+let observers: { callback: IntersectionObserverCallback; node?: Element }[] = [];
+beforeEach(() => {
+ observers = [];
+ vi.stubGlobal("IntersectionObserver", class {
+ entry: { callback: IntersectionObserverCallback; node?: Element };
+ constructor(callback: IntersectionObserverCallback) { this.entry = { callback }; observers.push(this.entry); }
+ observe(node: Element) { this.entry.node = node; }
+ disconnect() {}
+ });
+});
+const intersectAll = () => act(() => {
+ for (const { callback, node } of observers) {
+ if (node) callback([{ target: node, isIntersecting: true } as IntersectionObserverEntry], {} as IntersectionObserver);
+ }
+});
+afterEach(() => { vi.unstubAllGlobals(); resetRememberedThreadRowHeights(); });
+
+function comment(
+ id: string,
+ parentId: string | null,
+ content: string,
+ author: Pick<TimelineEntry, "actor_type" | "actor_id"> = { actor_type: "agent", actor_id: "agent-1" },
+): TimelineEntry {
+ return {
+ type: "comment",
+ id,
+ ...author,
+ content,
+ parent_id: parentId,
+ comment_type: "comment",
+ reactions: [],
+ attachments: [],
+ created_at: "2026-09-11T07:00:00Z",
+ updated_at: "2026-09-11T07:00:00Z",
+ revision: 1,
+ };
+}
+
+function renderThread(replies: TimelineEntry[], replyScrollParent: HTMLElement | null) {
+ const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } });
+ const view = (rows: TimelineEntry[]) => (
+ <QueryClientProvider client={qc}>
+ <CommentCard
+ issueId="issue-1"
+ replyScrollParent={replyScrollParent}
+ entry={comment("root", null, "root body")}
+ replies={rows}
+ currentUserId="user-1"
+ onReply={vi.fn().mockResolvedValue(true)}
+ onEdit={vi.fn().mockResolvedValue(undefined)}
+ onDelete={vi.fn()}
+ onToggleReaction={vi.fn()}
+ onCopyLink={vi.fn()}
+ onCreateSubIssue={vi.fn()}
+ />
+ </QueryClientProvider>
+ );
+ const result = renderWithI18n(view(replies));
+ return { ...result, update: (rows: TimelineEntry[]) => result.rerender(view(rows)) };
+}
+
+const longReplies = () => [1, 2, 3].map((n) => comment(`reply-${n}`, "root", `report ${n} ${"x".repeat(5_000)}`));
+
+describe("CommentCard — reply virtualization", () => {
+ it("mounts a short thread of long replies on demand", () => {
+ const { container } = renderThread(longReplies(), document.body);
+ const rows = container.querySelectorAll("[data-virtual-thread-row]");
+ expect(rows).toHaveLength(3);
+ expect([...rows].every((row) => row.getAttribute("data-virtual-thread-mounted") === "false")).toBe(true);
+ expect(container.querySelector("#comment-reply-2")).not.toBeNull();
+ expect(screen.queryByText(/^report 2/)).toBeNull();
+ });
+
+ it("keeps a short thread of short replies inline", () => {
+ const { container } = renderThread([1, 2, 3].map((n) => comment(`reply-${n}`, "root", `short ${n}`)), document.body);
+ expect(container.querySelector("[data-virtual-thread-row]")).toBeNull();
+ expect(screen.getByText("short 2")).toBeInTheDocument();
+ expect(container.querySelector("#comment-reply-2")?.getAttribute("data-mc")).toBe("comment-reply");
+ });
+
+ it("keeps an open reply editor when a new report pushes the thread past the threshold", async () => {
+ // Found in review of #10744: switching inline rows to virtual rows swapped
+ // the component, unmounting the editor and dropping focus.
+ const initial = [
+ comment("own", "root", "My reply", { actor_type: "member", actor_id: "user-1" }),
+ comment("report", "root", "x".repeat(11_000)),
+ ];
+ const result = renderThread(initial, document.body);
+ expect(result.container.querySelector("[data-virtual-thread-row]")).toBeNull();
+ fireEvent.click(result.container.querySelector('#comment-own button[aria-haspopup="menu"]')!);
+ fireEvent.click(await screen.findByText("Edit"));
+ const editor = await screen.findByTestId("editor");
+ editor.focus();
+
+ result.update([...initial, comment("new-report", "root", "y".repeat(2_000))]);
+ expect(result.container.querySelectorAll("[data-virtual-thread-row]")).toHaveLength(3);
+ // Existing rows stay mounted through the switch; the new one is a placeholder.
+ expect(result.container.querySelector("#comment-own")?.getAttribute("data-virtual-thread-mounted")).toBe("true");
+ expect(result.container.querySelector("#comment-new-report")?.getAttribute("data-virtual-thread-mounted")).toBe("false");
+ intersectAll();
+ expect(screen.queryByTestId("editor")).toBe(editor);
+ expect(document.activeElement).toBe(editor);
+ });
+
+ it("renders every reply without a scroll parent, for in-page find", () => {
+ const { container } = renderThread(longReplies(), null);
+ expect(container.querySelector("[data-virtual-thread-row]")).toBeNull();
+ expect(screen.getByText(/^report 2/)).toBeInTheDocument();
+ });
+});
diff --git a/packages/views/issues/components/comment-card.tsx b/packages/views/issues/components/comment-card.tsx
index 5cc5c6be71..80c5db3a25 100644
--- a/packages/views/issues/components/comment-card.tsx
+++ b/packages/views/issues/components/comment-card.tsx
@@ -38,7 +38,7 @@ import { useCommentUploads } from "./use-comment-uploads";
import { FileUploadButton } from "@multica/ui/components/common/file-upload-button";
import { api, dispatchReasonCode, errorCode } from "@multica/core/api";
import { ReplyInput, type ReplyInputHandle } from "./reply-input";
-import { VirtualThreadRow } from "./virtual-thread-row";
+import { VirtualThreadRow, shouldVirtualizeThreadRows } from "./virtual-thread-row";
import { CommentTriggerChips } from "./comment-trigger-chips";
import { AppCallChips } from "./app-call-chips";
import { useCommentTriggerPreview } from "../hooks/use-comment-trigger-preview";
@@ -1327,15 +1327,24 @@ function CommentCardImpl({
&& (run.anchorCommentId === entry.id || run.anchorCommentId === replyResolutionId)))
: orderThreadWithRuns(entry, allNestedReplies, runs);
+ // Long threads mount replies on demand: many rows, or few rows carrying a
+ // lot of Markdown (MUL-9409). Short threads render inline, but through the
+ // same wrapper, so crossing the threshold never remounts a row (an open
+ // reply editor survives a new long report arriving).
+ const virtualizeRows = !!replyScrollParent && shouldVirtualizeThreadRows(
+ threadRows.map((row) => ("run" in row ? row.reply?.content : row.content)?.length ?? 0),
+ );
const renderRows = () => threadRows.map((row) => {
- if (!replyScrollParent || threadRows.length < 30) return renderThreadRow(row);
+ if (!replyScrollParent) return renderThreadRow(row);
if (!("run" in row) && isDeletedComment(row)) return null;
const anchorId = "run" in row
? (row.reply && !isDeletedComment(row.reply) ? row.reply.id : row.run.task.id)
: row.id;
- return <VirtualThreadRow key={anchorId} id={`comment-${anchorId}`}
+ // Keyed like the inline rows: a run slot keeps its task key when its reply
+ // arrives, so the slot (and its open activity panel) stays mounted.
+ return <VirtualThreadRow key={"run" in row ? row.run.task.id : row.id} id={`comment-${anchorId}`} virtualize={virtualizeRows}
taskId={"run" in row ? row.run.task.id : undefined} scrollParent={replyScrollParent}>
- {() => renderThreadRow(row, true)}
+ {() => renderThreadRow(row, virtualizeRows)}
</VirtualThreadRow>;
});
diff --git a/packages/views/issues/components/issue-detail.test.tsx b/packages/views/issues/components/issue-detail.test.tsx
index 3af23af2c7..93086a730b 100644
--- a/packages/views/issues/components/issue-detail.test.tsx
+++ b/packages/views/issues/components/issue-detail.test.tsx
@@ -807,6 +807,12 @@ function hasHighlightedCommentBackground(root: ParentNode | null): boolean {
// Tests
// ---------------------------------------------------------------------------
+
+// Timeline thread rows render inside a stable wrapper (MUL-9409), so row order
+// and adjacency are compared at the wrapper level.
+function threadRow(el: Element): Element {
+ return el.closest("[data-thread-row]") ?? el;
+}
describe("IssueDetail (shared)", () => {
beforeEach(() => {
vi.clearAllMocks();
@@ -1718,7 +1724,7 @@ describe("IssueDetail (shared)", () => {
const agentBlock = container.querySelector(`[data-run-comment-id="${taskId}"]`)!;
expect(agentBlock).not.toBeNull();
expect(userBlock.contains(agentBlock)).toBe(false);
- expect(agentBlock.parentElement).toBe(userBlock.parentElement);
+ expect(threadRow(agentBlock).parentElement).toBe(userBlock.parentElement);
expect(agentBlock.querySelector(`[data-run-id="${taskId}"]`)).not.toBeNull();
const running: AgentTask = { ...task, status: "running", started_at: task.created_at, delivered_comment_ids: [root.id] };
act(() => client.setQueryData(issueKeys.tasks("issue-1"), [running]));
@@ -1786,8 +1792,8 @@ describe("IssueDetail (shared)", () => {
const firstComment = container.querySelector(`#comment-${first.id}`);
expect(latestComment).not.toBeNull();
expect(firstComment).not.toBeNull();
- expect(latestComment!.nextElementSibling).toBe(run);
- expect(firstComment!.nextElementSibling).not.toBe(run);
+ expect(threadRow(latestComment!).nextElementSibling).toBe(threadRow(run));
+ expect(threadRow(firstComment!).nextElementSibling).not.toBe(threadRow(run));
});
it("keeps the running block after its delivered comment and one queued block after later replies", async () => {
@@ -1829,7 +1835,7 @@ describe("IssueDetail (shared)", () => {
expect(rootContent!.compareDocumentPosition(runningBlock!) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
expect(runningBlock!.compareDocumentPosition(firstComment!) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
expect(firstComment!.compareDocumentPosition(latestComment!) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
- expect(latestComment!.nextElementSibling).toBe(queuedBlock);
+ expect(threadRow(latestComment!).nextElementSibling).toBe(threadRow(queuedBlock!));
expect(container.querySelectorAll(`[data-run-comment-id="${queued.id}"]`)).toHaveLength(1);
});
@@ -1913,9 +1919,9 @@ describe("IssueDetail (shared)", () => {
await waitFor(() => expect(container.querySelectorAll('[data-run-slot-id]')).toHaveLength(3));
const slots = tasks.map((task) => container.querySelector(`[data-run-slot-id="${task.id}"]`)!);
const [secondRow, thirdRow] = [second, third].map((request) => container.querySelector(`#comment-${request.id}`)!);
- expect(secondRow!.previousElementSibling).toBe(slots[0]);
- expect(secondRow!.nextElementSibling).toBe(slots[1]);
- expect(thirdRow!.nextElementSibling).toBe(slots[2]);
+ expect(threadRow(secondRow!).previousElementSibling).toBe(threadRow(slots[0]!));
+ expect(threadRow(secondRow!).nextElementSibling).toBe(threadRow(slots[1]!));
+ expect(threadRow(thirdRow!).nextElementSibling).toBe(threadRow(slots[2]!));
fireEvent.click(within(slots[0] as HTMLElement).getByRole("button", { name: /View activity/ }));
await within(slots[0] as HTMLElement).findByText("No activity recorded yet.");
for (const index of [0, 1]) {
@@ -1939,9 +1945,9 @@ describe("IssueDetail (shared)", () => {
expect(within(slots[0] as HTMLElement).queryByRole("button", { name: /View activity/ })).not.toBeInTheDocument();
// Answers land at their own time, after the requests; the queued run
// stays with its request.
- expect(thirdRow!.nextElementSibling).toBe(slots[2]);
- expect(slots[2]!.nextElementSibling).toBe(slots[0]);
- expect(slots[0]!.nextElementSibling).toBe(slots[1]);
+ expect(threadRow(thirdRow!).nextElementSibling).toBe(threadRow(slots[2]!));
+ expect(threadRow(slots[2]!).nextElementSibling).toBe(threadRow(slots[0]!));
+ expect(threadRow(slots[0]!).nextElementSibling).toBe(threadRow(slots[1]!));
expect(container.querySelector(`[data-run-slot-id="${tasks[2]!.id}"]`)).toBe(slots[2]);
expect(within(slots[2] as HTMLElement).getByText("Waiting for an available agent.")).toBeInTheDocument();
});
@@ -2015,7 +2021,7 @@ describe("IssueDetail (shared)", () => {
const userReply = container.querySelector("#comment-user-reply")!;
const agentBlock = container.querySelector(`[data-run-comment-id="${task.id}"]`)!;
expect(userReply.contains(agentBlock)).toBe(false);
- expect(userReply.nextElementSibling).toBe(agentBlock);
+ expect(threadRow(userReply).nextElementSibling).toBe(threadRow(agentBlock));
expect(within(agentBlock as HTMLElement).getByRole("button", { name: "Retry run" })).toBeInTheDocument();
expect(container.querySelectorAll(`[data-run-id="${task.id}"]`)).toHaveLength(1);
});
diff --git a/packages/views/issues/components/virtual-thread-row.test.tsx b/packages/views/issues/components/virtual-thread-row.test.tsx
index 940f618686..7db08d8a61 100644
--- a/packages/views/issues/components/virtual-thread-row.test.tsx
+++ b/packages/views/issues/components/virtual-thread-row.test.tsx
@@ -1,6 +1,6 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { act, cleanup, render, screen } from "@testing-library/react";
-import { VirtualThreadRow } from "./virtual-thread-row";
+import { VirtualThreadRow, resetRememberedThreadRowHeights, shouldVirtualizeThreadRows } from "./virtual-thread-row";
let notify: IntersectionObserverCallback;
let observed: Element;
@@ -11,7 +11,7 @@ beforeEach(() => {
disconnect() {}
});
});
-afterEach(() => { cleanup(); vi.restoreAllMocks(); vi.unstubAllGlobals(); });
+afterEach(() => { cleanup(); vi.restoreAllMocks(); vi.unstubAllGlobals(); resetRememberedThreadRowHeights(); });
const intersect = (visible: boolean) => act(() => notify([
{ target: observed, isIntersecting: visible } as IntersectionObserverEntry,
], {} as IntersectionObserver));
@@ -45,4 +45,32 @@ describe("VirtualThreadRow", () => {
render(<VirtualThreadRow id="comment-find">{() => <p>Findable history</p>}</VirtualThreadRow>);
expect(screen.getByText("Findable history")).toBeInTheDocument();
});
+
+ it("reserves a remounted row's last measured height instead of the default", () => {
+ vi.spyOn(HTMLElement.prototype, "getBoundingClientRect").mockReturnValue(new DOMRect(0, 0, 400, 2400));
+ const first = render(<VirtualThreadRow id="comment-long" scrollParent={document.body}>{() => <p>Long reply</p>}</VirtualThreadRow>);
+ intersect(true);
+ first.unmount();
+ const { container } = render(<VirtualThreadRow id="comment-long" scrollParent={document.body}>{() => <p>Long reply</p>}</VirtualThreadRow>);
+ expect(screen.queryByText("Long reply")).toBeNull();
+ expect(container.querySelector("#comment-long")).toHaveStyle({ height: "2400px" });
+ });
+});
+
+describe("shouldVirtualizeThreadRows", () => {
+ it("virtualizes threads with many rows regardless of length", () => {
+ expect(shouldVirtualizeThreadRows(Array.from({ length: 30 }, () => 10))).toBe(true);
+ expect(shouldVirtualizeThreadRows(Array.from({ length: 29 }, () => 10))).toBe(false);
+ });
+
+ it("virtualizes a short thread once its replies carry a lot of Markdown", () => {
+ // MUL-9409: 28 replies, mostly 3-7k-character agent reports with tables.
+ expect(shouldVirtualizeThreadRows([2545, 390, 6672, 124, 6445])).toBe(true);
+ expect(shouldVirtualizeThreadRows([400, 120, 900, 300])).toBe(false);
+ });
+
+ it("leaves a single reply inline, since there is nothing to split", () => {
+ expect(shouldVirtualizeThreadRows([50_000])).toBe(false);
+ expect(shouldVirtualizeThreadRows([])).toBe(false);
+ });
});
diff --git a/packages/views/issues/components/virtual-thread-row.tsx b/packages/views/issues/components/virtual-thread-row.tsx
index 8b1a9c0224..4414e11f31 100644
--- a/packages/views/issues/components/virtual-thread-row.tsx
+++ b/packages/views/issues/components/virtual-thread-row.tsx
@@ -3,21 +3,98 @@
import { useEffect, useLayoutEffect, useRef, useState, type ReactNode } from "react";
import { keepThreadRowAnchored } from "../utils/keep-thread-rows-anchored";
-/** Keep anchors addressable without parsing every offscreen Markdown reply. */
-export function VirtualThreadRow({ id, taskId, scrollParent, children }: {
+/**
+ * Placeholder height for a reply that has never been measured. Kept modest so
+ * an unmeasured row neither hides the viewport nor inflates the thread far
+ * past its real size.
+ */
+const UNMEASURED_ROW_HEIGHT = 320;
+
+/** Thread rows past this count always render behind {@link VirtualThreadRow}. */
+const VIRTUALIZE_MIN_ROWS = 30;
+
+/**
+ * Thread Markdown, in characters, past which a shorter thread virtualizes too.
+ * The timeline's Virtuoso treats a whole thread as one item, so a few dozen
+ * long agent replies mount in one synchronous commit as soon as the thread
+ * nears the viewport. MUL-9409: 28 rows / ~59k characters / ~48k px stayed
+ * blank for ~0.7s on scroll-up. Rendered replies run roughly 0.8px per
+ * character, so 12k characters is ~10k px — several viewports of content.
+ */
+const VIRTUALIZE_MIN_CONTENT_CHARS = 12_000;
+
+/**
+ * Whether a thread's replies should mount on demand. Row count alone missed
+ * threads with few but very long replies, which cost the most to mount.
+ */
+export function shouldVirtualizeThreadRows(contentLengths: readonly number[]): boolean {
+ if (contentLengths.length >= VIRTUALIZE_MIN_ROWS) return true;
+ if (contentLengths.length < 2) return false;
+ let total = 0;
+ for (const length of contentLengths) {
+ total += length;
+ if (total >= VIRTUALIZE_MIN_CONTENT_CHARS) return true;
+ }
+ return false;
+}
+
+/**
+ * Last measured height per row anchor. A row that scrolls away keeps its
+ * height on the row, but the whole thread unmounts once Virtuoso drops it;
+ * this lets the remounted thread reserve real heights instead of resetting
+ * every reply to {@link UNMEASURED_ROW_HEIGHT}. Anchors are comment / task
+ * UUIDs, so one map serves every issue; insertion order bounds it.
+ */
+const MAX_REMEMBERED_HEIGHTS = 2_000;
+const rememberedHeights = new Map<string, number>();
+
+function rememberHeight(id: string, height: number) {
+ rememberedHeights.delete(id);
+ rememberedHeights.set(id, height);
+ if (rememberedHeights.size > MAX_REMEMBERED_HEIGHTS) {
+ const oldest = rememberedHeights.keys().next().value;
+ if (oldest !== undefined) rememberedHeights.delete(oldest);
+ }
+}
+
+/** Test-only: forget every remembered height. */
+export function resetRememberedThreadRowHeights() {
+ rememberedHeights.clear();
+}
+
+/**
+ * Keep anchors addressable without parsing every offscreen Markdown reply.
+ *
+ * Every timeline thread row renders through this wrapper, virtualized or not,
+ * so a thread that crosses the virtualization threshold (a new long report
+ * arrives) keeps the same component tree: its rows stay mounted until they are
+ * observed offscreen, and an open editor is never torn down by the switch.
+ * The anchor `id` lives on the wrapper only while virtualized; otherwise the
+ * row content carries it as before.
+ */
+export function VirtualThreadRow({ id, taskId, scrollParent, virtualize = true, children }: {
id: string;
taskId?: string;
scrollParent?: HTMLElement | null;
+ /** False renders the row inline; switching it never remounts the row. */
+ virtualize?: boolean;
children: () => ReactNode;
}) {
const ref = useRef<HTMLDivElement>(null);
- const height = useRef(320);
- const [visible, setVisible] = useState(false);
- const mounted = !scrollParent || visible;
+ const height = useRef(rememberedHeights.get(id) ?? UNMEASURED_ROW_HEIGHT);
+ const active = !!scrollParent && virtualize;
+ // A row that starts inline counts as visible, so turning virtualization on
+ // later keeps it mounted until the observer reports it offscreen.
+ const [visible, setVisible] = useState(!active);
+ const mounted = !active || visible;
useEffect(() => {
const node = ref.current;
- if (!node || !scrollParent) return;
+ if (!node) return;
+ if (!active) {
+ setVisible(true);
+ return;
+ }
if (typeof IntersectionObserver !== "function") {
setVisible(true);
return;
@@ -31,32 +108,39 @@ export function VirtualThreadRow({ id, taskId, scrollParent, children }: {
}, { root: scrollParent, rootMargin: "800px 0px" });
observer.observe(node);
return () => observer.disconnect();
- }, [scrollParent]);
+ }, [active, scrollParent]);
// The placeholder's height becomes the real one in this commit. Keep the
// content below a row above the viewport from moving (see the helper).
+ // Only a placeholder → content transition shifts layout.
+ const wasMounted = useRef(mounted);
useLayoutEffect(() => {
+ const was = wasMounted.current;
+ wasMounted.current = mounted;
const node = ref.current;
- if (!node || !visible || !scrollParent) return;
+ if (was || !mounted || !node || !scrollParent) return;
keepThreadRowAnchored(scrollParent, node, height.current);
- }, [visible, scrollParent]);
+ }, [mounted, scrollParent]);
useEffect(() => {
const node = ref.current;
if (!node || !mounted) return;
const measure = () => {
const next = node.getBoundingClientRect().height;
- if (next > 0) height.current = next;
+ if (next > 0) {
+ height.current = next;
+ rememberHeight(id, next);
+ }
};
measure();
if (typeof ResizeObserver !== "function") return;
const observer = new ResizeObserver(measure);
observer.observe(node);
return () => observer.disconnect();
- }, [mounted]);
+ }, [mounted, id]);
- return <div ref={ref} id={id} data-run-slot-id={taskId}
- data-virtual-thread-row data-virtual-thread-mounted={mounted}
+ return <div ref={ref} id={active ? id : undefined} data-run-slot-id={active ? taskId : undefined} data-thread-row=""
+ data-virtual-thread-row={active ? "" : undefined} data-virtual-thread-mounted={active ? mounted : undefined}
style={mounted ? undefined : { height: height.current }}>
{mounted ? children() : null}
</div>;