Merge pull request #10479 from Kilo-Org/mercury-way

fix(vscode): clear stale diff preview loading
This commit is contained in:
Marius
2026-05-21 11:54:03 +02:00
committed by GitHub
3 changed files with 45 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"kilo-code": patch
---
Clear Agent Manager file diff previews stuck on `Loading diff...` when the active diff source stops or changes.
@@ -181,8 +181,12 @@ export class SourceController {
return
}
const diff = await source.fetchFile(file).catch(() => null)
// Drop the response if the source has been disposed/swapped while we waited.
if (this.epoch !== epoch) return
// Discard stale content after disposal/swap, but still complete the request
// so consumers can clear per-file loading state.
if (this.epoch !== epoch) {
this.send(this.messages.diffFile(source, file, null))
return
}
this.send(this.messages.diffFile(source, file, diff))
}
@@ -345,6 +345,40 @@ describe("SourceController.requestFile", () => {
controller.stop()
})
it("posts null when a pending fetchFile result is invalidated by stop", async () => {
let release: () => void = () => {}
const workspace: DiffSource = {
descriptor: WORKSPACE_DESC,
async fetch() {
return { diffs: [] }
},
async fetchFile() {
await new Promise<void>((resolve) => (release = resolve))
return {
file: "foo.ts",
before: "a",
after: "b",
additions: 1,
deletions: 1,
}
},
}
const { controller, posted } = make({ workspace })
controller.setContext({ workspaceRoot: "/repo" })
await controller.activate("workspace")
posted.length = 0
const request = controller.requestFile("foo.ts")
controller.stop()
release()
await request
const files = byType(posted, "diffViewer.diffFile")
expect(files).toHaveLength(1)
expect(files[0]!.file).toBe("foo.ts")
expect(files[0]!.diff).toBeNull()
})
})
describe("SourceController.reactivate", () => {