Revert "fix(agents): keep following the chat end when a row grows after its render (#7811)"

This reverts commit 437008c517.
Цей коміт міститься в:
l0ng-ai committed 2026-12-04 10:49:02 +08:00
1 джерело 7992063ef2
коміт 5f452a8e36
2 files changed
+9 -139

No files matched your search

+9 -13
Переглянути файл
@@ -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.
-126
Переглянути файл
@@ -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<typeof import("@/platform/ipc")>()),
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<Element> }[] = [];
const OriginalResizeObserver = globalThis.ResizeObserver;
beforeEach(() => {
observers.length = 0;
globalThis.ResizeObserver = class {
private entry: { callback: ResizeObserverCallback; targets: Set<Element> };
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(
<SessionEditor input={{ kind: "agent-session", key: task.id, data: { task: task.id } }} />,
);
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);
});