Skip to content

Commit a77d28c

Browse files
committed
fix(webview): reset FileChangesPanel original-content state when taskId changes
A request left pending under the previous taskId was never retried, because the response for it is rejected once the taskId arrives or changes.
1 parent 4d13b64 commit a77d28c

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎webview-ui/src/__tests__/FileChangesPanel.spec.tsx‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,24 @@ describe("FileChangesPanel", () => {
316316
expect(b).toHaveTextContent("-old b")
317317
})
318318

319+
it("requests the original again when the task id arrives after a request is already pending", () => {
320+
const messages = [createEditWithOriginal({ originalContentLength: 5000 })]
321+
const { rerender } = renderPanel(messages)
322+
expandRow()
323+
expect(requestsOfType("readOriginalContent")).toHaveLength(1)
324+
325+
rerender(
326+
<TranslationProvider>
327+
<FileChangesPanel clineMessages={messages} taskId="task-1" />
328+
</TranslationProvider>,
329+
)
330+
fireEvent.click(screen.getByTestId("accordian-toggle"))
331+
332+
const requests = requestsOfType("readOriginalContent")
333+
expect(requests).toHaveLength(2)
334+
expect(requests[1]).toMatchObject({ taskId: "task-1" })
335+
})
336+
319337
it("ignores an original answered for a different task", () => {
320338
renderPanel([createEditWithOriginal({ originalContentLength: 5000 })], "task-1")
321339
expandRow()

‎webview-ui/src/components/chat/FileChangesPanel.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const FileChangesPanel = memo(({ clineMessages, taskId, className }: FileChanges
3838
pendingPathsRef.current = new Set()
3939
setOriginalContentByKey({})
4040
pendingOriginalKeysRef.current = new Set()
41-
}, [clineMessages])
41+
}, [clineMessages, taskId])
4242

4343
const fileChanges = useMemo(() => fileChangesFromMessages(clineMessages), [clineMessages])
4444

0 commit comments

Comments
 (0)