From 5f452a8e368cd5729cf1ea791a38d71f3d92ac33 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Fri, 4 Dec 2026 10:48:43 +0800 Subject: [PATCH] Revert "fix(agents): keep following the chat end when a row grows after its render (#7811)" This reverts commit 437008c517ebd567dd2b5b844c4e9678db5c4134. --- src/features/agents/session/Stream.tsx | 22 ++- .../agents/session/followEnd.test.tsx | 126 ------------------ 2 files changed, 9 insertions(+), 139 deletions(-) delete mode 100644 src/features/agents/session/followEnd.test.tsx diff --git a/src/features/agents/session/Stream.tsx b/src/features/agents/session/Stream.tsx index b0d323df75..dce9df4073 100644 --- a/src/features/agents/session/Stream.tsx +++ b/src/features/agents/session/Stream.tsx @@ -544,8 +544,8 @@ export function Stream({ shownRow.current = null; holdShownRow(); }, [holdShownRow]); - /** Content that grew outside a render (a diagram drawn, a row laid out late): keep following. */ - const followEnd = useCallback(() => { + /** A diagram that drew after the last streamed chunk grows the conversation: keep following. */ + const onDiagramDrawn = useCallback(() => { const el = ref.current; if (!el) return; if (position.current.stick && !dragging.current && slack.current === 0) { @@ -617,14 +617,10 @@ export function Stream({ }); useEffect(() => { // A row also changes height on its own (a reasoning folding when its turn moves on, text - // revealed at a pace, an image loading, a just-sent message laid out after its render): - // before it paints. Following the end, the end stays in view. + // revealed at a pace, an image loading): before it paints. const el = ref.current; if (!el || typeof ResizeObserver === "undefined") return; - const resize = new ResizeObserver(() => { - holdShownRow(); - if (position.current.stick) followEnd(); - }); + const resize = new ResizeObserver(() => holdShownRow()); const watch = () => { for (const row of el.querySelectorAll(`:scope > .${styles.conversationRow}`)) resize.observe(row); }; @@ -635,7 +631,7 @@ export function Stream({ rows.disconnect(); resize.disconnect(); }; - }, [followEnd, holdShownRow]); + }, [holdShownRow]); useLayoutEffect(() => { const el = ref.current; if (!el) return; @@ -768,10 +764,10 @@ export function Stream({ working={row.index === lastIndex && busy} drafts={drafts} onOpenSubagent={onOpenSubagent} - onDiagramDrawn={followEnd} + onDiagramDrawn={onDiagramDrawn} /> ), - [rowTask, turns, replies, times, thinking, lastIndex, busy, drafts, onOpenSubagent, followEnd], + [rowTask, turns, replies, times, thinking, lastIndex, busy, drafts, onOpenSubagent, onDiagramDrawn], ); const renderConversationRow = useCallback( (row: ConversationRow): ReactNode => @@ -782,12 +778,12 @@ export function Stream({ lastIndex={lastIndex} busy={busy} thinking={thinking} - onDiagramDrawn={followEnd} + onDiagramDrawn={onDiagramDrawn} /> ) : ( renderRow(row) ), - [rowTask, lastIndex, busy, thinking, followEnd, renderRow], + [rowTask, lastIndex, busy, thinking, onDiagramDrawn, renderRow], ); const agentName = providerName(task.provider); // Switching tabs changes visibility without changing the conversation rows. diff --git a/src/features/agents/session/followEnd.test.tsx b/src/features/agents/session/followEnd.test.tsx deleted file mode 100644 index c83f9e1a51..0000000000 --- a/src/features/agents/session/followEnd.test.tsx +++ /dev/null @@ -1,126 +0,0 @@ -import { act, render, waitFor } from "@testing-library/react"; -import { afterEach, beforeEach, expect, it, vi } from "vitest"; -import type { AgentEntry, AgentTask } from "@/bindings"; - -const ipc = vi.hoisted(() => ({ entries: vi.fn() })); -vi.mock("@/platform/ipc", async (original) => ({ - ...(await original()), - commands: { - agentEntries: ipc.entries, - agentChanges: async () => ({ status: "ok", data: [] }), - agentGroupedChanges: async () => ({ - status: "ok", - data: { uncommitted: [], commits: [] }, - }), - vcsBranchInfo: async () => ({ status: "ok", data: { head: "main" } }), - }, -})); -vi.mock("@tauri-apps/api/webview", () => ({ - getCurrentWebview: () => ({ - onDragDropEvent: () => Promise.resolve(() => {}), - }), -})); - -import styles from "../Session.module.css"; -import { SessionEditor } from "../SessionEditor"; -import { useAgents } from "../store"; - -const entries: AgentEntry[] = [ - { type: "agent", text: "one" }, - { type: "agent", text: "two" }, -]; - -const task: AgentTask = { - id: "follow", - title: "Test task", - provider: "codex", - status: "running", - isolation: "local", - model: null, - cwd: "/project", - branch: null, - base: null, - baseCommit: null, - error: null, - createdMs: 0, - updatedMs: 0, - config: [], - commands: [], - usage: null, - queue: [], - capabilities: { fork: true, rollback: true, steer: true, images: true }, -}; - -/** Row resize callbacks, so a test can report a row laid out after its render. */ -const observers: { callback: ResizeObserverCallback; targets: Set }[] = []; -const OriginalResizeObserver = globalThis.ResizeObserver; - -beforeEach(() => { - observers.length = 0; - globalThis.ResizeObserver = class { - private entry: { callback: ResizeObserverCallback; targets: Set }; - constructor(callback: ResizeObserverCallback) { - this.entry = { callback, targets: new Set() }; - observers.push(this.entry); - } - observe(target: Element) { - this.entry.targets.add(target); - } - unobserve(target: Element) { - this.entry.targets.delete(target); - } - disconnect() { - this.entry.targets.clear(); - } - } as unknown as typeof ResizeObserver; - ipc.entries.mockReset().mockResolvedValue({ status: "ok", data: entries }); - useAgents.setState({ - loaded: true, - tasks: new Map([[task.id, task]]), - entries: new Map(), - composers: new Map(), - scrollPositions: new Map(), - focus: null, - }); -}); - -afterEach(() => { - globalThis.ResizeObserver = OriginalResizeObserver; -}); - -it("keeps following the end when a row grows without a render", async () => { - const { container } = render( - , - ); - const row = await waitFor(() => { - const found = container.querySelectorAll(`.${styles.conversationRow}`); - expect(found.length).toBeGreaterThan(1); - return found[found.length - 1]!; - }); - const scroller = row.parentElement as HTMLElement; - let content = 1000; - let top = 0; - Object.defineProperty(scroller, "clientHeight", { - value: 400, - configurable: true, - }); - Object.defineProperty(scroller, "scrollHeight", { - get: () => content, - configurable: true, - }); - Object.defineProperty(scroller, "scrollTop", { - get: () => top, - set: (next: number) => { - top = Math.max(0, Math.min(next, content - 400)); - }, - configurable: true, - }); - scroller.scrollTop = 600; - - // The last row lays out taller after the render that added it. - content = 1080; - const rowObserver = observers.find((o) => o.targets.has(row)); - expect(rowObserver).toBeTruthy(); - act(() => rowObserver!.callback([], {} as ResizeObserver)); - expect(scroller.scrollTop).toBe(680); -});