mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-08-28 19:11:03 +08:00
494817da26
handleSessionDeleted cleared the draft Maps inside the cleanup batch, but PromptInput's createEffect(on(draftKey, ...)) runs after the batch ends. When the active session was deleted, the effect saw draftKey transition from ...:session:<id> to ...:pending:<id> (draftSessionID was left pointing at the deleted id) and called saveDraft(prev, currentText, currentImages), which wrote the unsent draft and attached image data URLs straight back into the just-cleared ...:session:<id> entry. Two changes: - Move deleteDraftsForSession(sessionID) out of the batch so it runs after the effect's recreate is also cleaned up. - Clear draftSessionID alongside currentSessionID in the active-session delete branch so draftKey falls all the way to the 'new' bucket instead of ...:pending:<deleted-id>. Tests: regression in prompt-drafts.test.ts covering the recreate-then- cleanup path, plus contract assertions in prompt-send-contract.test.ts that setDraftSessionID is cleared and deleteDraftsForSession is called outside the batch.
22 lines
728 B
TypeScript
22 lines
728 B
TypeScript
import type { ReviewComment } from "../types/messages"
|
|
import type { ImageAttachment } from "../hooks/useImageAttachments"
|
|
|
|
export const drafts = new Map<string, string>()
|
|
export const reviewDrafts = new Map<string, ReviewComment[]>()
|
|
export const imageDrafts = new Map<string, ImageAttachment[]>()
|
|
|
|
export function deleteDraftsForSession(id: string) {
|
|
if (!id) return
|
|
const sessionSuffix = `:session:${id}`
|
|
const pendingSuffix = `:pending:${id}`
|
|
const maps = [drafts, reviewDrafts, imageDrafts]
|
|
for (const map of maps) {
|
|
for (const key of map.keys()) {
|
|
if (typeof key !== "string") continue
|
|
if (key.endsWith(sessionSuffix) || key.endsWith(pendingSuffix)) {
|
|
map.delete(key)
|
|
}
|
|
}
|
|
}
|
|
}
|