From 689d8a844f2ec49986931e92a9893cfa34020ebb Mon Sep 17 00:00:00 2001 From: cartridgebasic <68982521+cartridgebasic@users.noreply.github.com> Date: Thu, 26 Nov 2026 10:32:50 -0700 Subject: [PATCH 1/2] Keep long changed-file lists scrollable An expanded changed-files list can exceed the panel. Bound its height, support keyboard scrolling and preserve row expansion during streaming. Refs #2723 --- webview-ui/playwright/gallery/stories.tsx | 21 ++++++++++ .../src/__tests__/FileChangesPanel.spec.tsx | 36 ++++++++++++++++++ webview-ui/src/components/chat/ChatView.tsx | 2 +- .../src/components/chat/FileChangesPanel.tsx | 13 +++++-- .../__tests__/FileChangesPanel.visual.tsx | 24 ++++++++++++ .../file-changes-expanded-dark.png | Bin 0 -> 10350 bytes 6 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 webview-ui/src/components/chat/__tests__/FileChangesPanel.visual.tsx create mode 100644 webview-ui/src/components/chat/__tests__/__screenshots__/file-changes-expanded-dark.png diff --git a/webview-ui/playwright/gallery/stories.tsx b/webview-ui/playwright/gallery/stories.tsx index 9dca3490895..29ba12bd7f2 100644 --- a/webview-ui/playwright/gallery/stories.tsx +++ b/webview-ui/playwright/gallery/stories.tsx @@ -1,4 +1,5 @@ import React, { useState } from "react" +import type { ClineMessage } from "@roo-code/types" type StoryProps = Record type Story = (props: StoryProps) => React.ReactNode | Promise @@ -12,6 +13,26 @@ const mermaidGantt = `gantt Ship release :active, release, after scope, 3d` export const stories: Record = { + "file-changes-long-list": async () => { + const [{ AppProviders }, { default: FileChangesPanel }] = await Promise.all([ + import("../AppProviders"), + import("@/components/chat/FileChangesPanel"), + ]) + const messages: ClineMessage[] = Array.from({ length: 40 }, (_, index) => ({ + type: "ask", + ask: "tool", + ts: index + 1, + isAnswered: true, + text: JSON.stringify({ tool: "appliedDiff", path: `src/file-${index}.ts`, diff: "+line" }), + })) + return ( + +
+ +
+
+ ) + }, "litellm-reasoning-settings": async () => { const [{ AppProviders }, { default: ApiOptions }, { providerIdentifiers }] = await Promise.all([ import("../AppProviders"), diff --git a/webview-ui/src/__tests__/FileChangesPanel.spec.tsx b/webview-ui/src/__tests__/FileChangesPanel.spec.tsx index 2a787d0cd04..9b4df08a70d 100644 --- a/webview-ui/src/__tests__/FileChangesPanel.spec.tsx +++ b/webview-ui/src/__tests__/FileChangesPanel.spec.tsx @@ -91,6 +91,28 @@ describe("FileChangesPanel", () => { expect(container.firstChild).toBeNull() }) + it("keeps an expanded file row open when streaming replaces the message array", () => { + const edit = createFileEditMessage("src/example.ts", "+first") + const { rerender } = renderPanel([edit], "task-1") + fireEvent.click(screen.getByRole("button", { name: /1 file/ })) + fireEvent.click(screen.getByTestId("accordian-toggle")) + expect(screen.getByTestId("accordian-toggle")).toHaveTextContent("expanded") + + rerender( + + + , + ) + + expect(screen.getByTestId("accordian-toggle")).toHaveTextContent("expanded") + }) + it("renders nothing when there are no file-edit messages", () => { const messages: ClineMessage[] = [ { @@ -152,6 +174,20 @@ describe("FileChangesPanel", () => { expect(paths.map((el) => el.textContent)).toEqual(expect.arrayContaining(["src/a.ts", "src/b.ts"])) }) + it("keeps a long expanded file list in a keyboard-scrollable region", () => { + const messages = Array.from({ length: 40 }, (_, index) => + createFileEditMessage(`src/file-${index}.ts`, `diff ${index}`), + ) + renderPanel(messages) + fireEvent.click(screen.getByText("40 file(s) changed in this conversation").closest("button")!) + + const list = screen.getByTestId("file-changes-list") + expect(list).toHaveClass("max-h-[40vh]", "overflow-y-auto") + expect(list).toHaveAttribute("tabindex", "0") + expect(screen.getAllByTestId("accordian-path")).toHaveLength(40) + expect(screen.getByText("40 file(s) changed in this conversation")).toBeVisible() + }) + it("collapsed by default: panel trigger shows chevron and expanding reveals file rows", () => { const messages = [createFileEditMessage("src/foo.ts", "diff")] renderPanel(messages) diff --git a/webview-ui/src/components/chat/ChatView.tsx b/webview-ui/src/components/chat/ChatView.tsx index d09e79ca6f3..ca87d9d71df 100644 --- a/webview-ui/src/components/chat/ChatView.tsx +++ b/webview-ui/src/components/chat/ChatView.tsx @@ -1803,7 +1803,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction -
+
{ setExpandedPaths(new Set()) setFinalContentByPath({}) pendingPathsRef.current = new Set() - }, [clineMessages, taskId]) + }, [taskId]) // Originals are keyed by message id, which is stable across message updates, so they only reset per task useEffect(() => { @@ -147,7 +148,7 @@ const FileChangesPanel = memo(({ clineMessages, taskId, className }: FileChanges const fileCount = byPath.size return ( - + ) : null} - +
{Array.from(byPath.entries()).map(([path, entries]) => { const originalContent = diff --git a/webview-ui/src/components/chat/__tests__/FileChangesPanel.visual.tsx b/webview-ui/src/components/chat/__tests__/FileChangesPanel.visual.tsx new file mode 100644 index 00000000000..b6b825c2d2b --- /dev/null +++ b/webview-ui/src/components/chat/__tests__/FileChangesPanel.visual.tsx @@ -0,0 +1,24 @@ +import { expect, test } from "../../../../playwright/coverage-fixture" +import { mountedStory } from "../../../../playwright/mounted-story" + +test("expanded file changes scroll while the summary header remains visible", async ({ mount }) => { + const story = mountedStory(await mount("file-changes-long-list")) + const header = story.getByRole("button", { name: /40 file/ }) + await header.click() + + const list = story.getByTestId("file-changes-list") + await expect(list).toBeVisible() + await expect(story).toHaveScreenshot("file-changes-expanded-dark.png") + const dimensions = await list.evaluate((element) => ({ + clientHeight: element.clientHeight, + scrollHeight: element.scrollHeight, + })) + expect(dimensions.clientHeight).toBeGreaterThan(0) + expect(dimensions.scrollHeight).toBeGreaterThan(dimensions.clientHeight) + + await list.focus() + await list.press("End") + await expect.poll(() => list.evaluate((element) => element.scrollTop)).toBeGreaterThan(0) + await expect(header).toBeInViewport() + await expect(story.getByText("src/file-39.ts")).toBeInViewport() +}) diff --git a/webview-ui/src/components/chat/__tests__/__screenshots__/file-changes-expanded-dark.png b/webview-ui/src/components/chat/__tests__/__screenshots__/file-changes-expanded-dark.png new file mode 100644 index 0000000000000000000000000000000000000000..c2c130d35546fb9c90dfd7e950052475286804fa GIT binary patch literal 10350 zcmeI2XH=8xx~@SGrqY~PP^!|UD!rp3y-HJh2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Nj4XlnTT`VSd$v@1G zhxo|C;=ka}0bpSbHU`yu#q>c{);?9c}#=N9nOZ2KLJx9nuV`{rOKwF zuem$dCm)+(I|f%K*2|d~$Hoda50D23D{PnB>%T0N3bp*lV*c>vlq4Jf;1!3>(I}`N z8M}MFl(*}Pq^S_Cq~F5o*r_(Nu(V&~uD|5`sI0cSo#zsB zu(yau5LJLjV>`z?=@@U7bcpXs-wf@5lv7bn9>@OBMlEq8o$Q)EH#{R1Huy6M<@V1M67Odb0K+#Qfvgd7U`@1rZ0PWYNvUWM++ zqE+1fYc7GQ^y`mN&E?&b?XPP4pjp{|rTq%Ih?7~jLhgIAcZJ-wm(oGPi+8d1c z?x&iG zO!6)Pl-xeHjrED9Q~BIkOQ}*KDYF#O_KxyPU9j}nS>$O3NmJ~x!RtTEFaNkNWNSvH z0Zyi$eDnv!{&IKdpX)XMXz Date: Wed, 2 Dec 2026 12:00:14 -0700 Subject: [PATCH 2/2] fix: refresh expanded file diffs after new edits --- .../src/__tests__/FileChangesPanel.spec.tsx | 29 ++++++++++++++++ .../src/components/chat/FileChangesPanel.tsx | 34 +++++++++++++++---- 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/webview-ui/src/__tests__/FileChangesPanel.spec.tsx b/webview-ui/src/__tests__/FileChangesPanel.spec.tsx index 9b4df08a70d..a5694f410bb 100644 --- a/webview-ui/src/__tests__/FileChangesPanel.spec.tsx +++ b/webview-ui/src/__tests__/FileChangesPanel.spec.tsx @@ -308,6 +308,35 @@ describe("FileChangesPanel", () => { expect(screen.getByTestId("accordian-code")).toHaveTextContent("+new line") }) + it.each([false, true])("refreshes an expanded file when another edit arrives (pending=%s)", (pending) => { + const first = createEditWithOriginal({ originalContent: "old line\n" }) + const next = { ...createFileEditMessage("src/foo.ts", "second edit"), messageId: "next-edit" } + const { rerender } = renderPanel([first], "task-1") + expandRow() + const reply = (content: string) => + respond({ type: "fileContent", fileContent: { path: "src/foo.ts", content } }) + if (!pending) reply("stale line\n") + + const update = () => + rerender( + + + , + ) + update() + expect(screen.getByTestId("accordian-toggle")).toHaveTextContent("expanded") + expect(screen.getByTestId("accordian-code")).not.toHaveTextContent("stale line") + if (pending) { + expect(requestsOfType("readFileContent")).toHaveLength(1) + reply("stale line\n") + } + update() + expect(requestsOfType("readFileContent")).toHaveLength(2) + reply("current line\n") + expect(screen.getByTestId("accordian-code")).toHaveTextContent("+current line") + expect(requestsOfType("readFileContent")).toHaveLength(2) + }) + it("keeps the recorded diff when the original cannot be loaded", () => { renderPanel([createEditWithOriginal({ originalContentLength: 5000 })]) expandRow() diff --git a/webview-ui/src/components/chat/FileChangesPanel.tsx b/webview-ui/src/components/chat/FileChangesPanel.tsx index 8f045f77241..3e034ff8740 100644 --- a/webview-ui/src/components/chat/FileChangesPanel.tsx +++ b/webview-ui/src/components/chat/FileChangesPanel.tsx @@ -21,12 +21,23 @@ interface FileChangesPanelProps { // `ts` is not unique, so the message's own id identifies it; `ts` only covers messages persisted without one. const originalKey = (entry: { messageId?: string; ts: number }) => entry.messageId ?? `ts:${entry.ts}` +// The number of edits distinguishes legacy siblings that share a timestamp. +const fileRevision = (entries: FileChangeEntry[]) => { + const last = entries.at(-1)! + return { key: entries.length + ":" + originalKey(last), diff: last.diff } +} +type FileRevision = ReturnType +const isCurrentRevision = (cached: FileRevision | undefined, revision: FileRevision) => + cached?.key === revision.key && cached.diff === revision.diff + const FileChangesPanel = memo(({ clineMessages, taskId, className }: FileChangesPanelProps) => { const { t } = useAppTranslation() const [panelExpanded, setPanelExpanded] = useState(false) const [expandedPaths, setExpandedPaths] = useState>(new Set()) - const [finalContentByPath, setFinalContentByPath] = useState>({}) - const pendingPathsRef = useRef>(new Set()) + const [finalContentByPath, setFinalContentByPath] = useState< + Record + >({}) + const pendingPathsRef = useRef(new Map()) // The extension omits `originalContent` from the messages it posts; it is requested when a row is expanded. const [originalContentByKey, setOriginalContentByKey] = useState>({}) // In-flight requests, keyed by task and message. Deliberately not reset with the caches below: a request cannot @@ -42,7 +53,6 @@ const FileChangesPanel = memo(({ clineMessages, taskId, className }: FileChanges useEffect(() => { setExpandedPaths(new Set()) setFinalContentByPath({}) - pendingPathsRef.current = new Set() }, [taskId]) // Originals are keyed by message id, which is stable across message updates, so they only reset per task @@ -95,13 +105,14 @@ const FileChangesPanel = memo(({ clineMessages, taskId, className }: FileChanges const entries = byPath.get(path) if (!entries?.length) continue const first = entries[0] + const revision = fileRevision(entries) const lookupPath = path.startsWith("./") ? path.slice(2) : path if ( first.hasOriginalContent && - !(lookupPath in finalContentByPath) && + !isCurrentRevision(finalContentByPath[lookupPath], revision) && !pendingPathsRef.current.has(lookupPath) ) { - pendingPathsRef.current.add(lookupPath) + pendingPathsRef.current.set(lookupPath, { ...revision, taskId }) vscode.postMessage({ type: "readFileContent", text: lookupPath }) } const requestKey = `${taskId ?? ""}|${originalKey(first)}` @@ -128,8 +139,14 @@ const FileChangesPanel = memo(({ clineMessages, taskId, className }: FileChanges const message: ExtensionMessage = event.data if (message.type === "fileContent" && message.fileContent?.path != null) { const fc = message.fileContent + const request = pendingPathsRef.current.get(fc.path) + if (!request) return pendingPathsRef.current.delete(fc.path) - setFinalContentByPath((prev) => ({ ...prev, [fc.path]: fc.content ?? null })) + setFinalContentByPath((prev) => + request.taskId === taskId + ? { ...prev, [fc.path]: { ...request, content: fc.content ?? null } } + : { ...prev }, + ) } else if (message.type === "originalContent" && message.originalContentInfo) { const { taskId: responseTaskId, content, ...id } = message.originalContentInfo const key = originalKey(id) @@ -189,7 +206,10 @@ const FileChangesPanel = memo(({ clineMessages, taskId, className }: FileChanges const originalContent = entries[0].originalContent ?? originalContentByKey[originalKey(entries[0])] ?? undefined const lookupPath = path.startsWith("./") ? path.slice(2) : path - const finalContent = finalContentByPath[lookupPath] + const cached = finalContentByPath[lookupPath] + const finalContent = isCurrentRevision(cached, fileRevision(entries)) + ? cached?.content + : undefined const hasMergedDiff = originalContent !== undefined && finalContent != null && finalContent !== "" const displayDiff = hasMergedDiff