fix(vscode): persist notification dismissals so they don't reappear

Add optimistic dismiss in the webview so the notification hides
immediately when the user clicks X, and update the cached message
in KiloProvider so the dismiss survives API failures and offline
fallback paths.  Previously a dismissed notification could reappear
when the webview re-mounted or the CLI backend was temporarily
unavailable because the cached payload still contained the old
dismissedIds list.
This commit is contained in:
kiloconnect[bot]
2026-03-18 16:08:55 +01:00
committed by Mark IJbema
parent 82d6b73c91
commit 0c28c7c0f2
2 changed files with 28 additions and 0 deletions
+27
View File
@@ -1404,6 +1404,18 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
private async fetchAndSendNotifications(): Promise<void> {
if (!this.client) {
if (this.cachedNotificationsMessage) {
// Merge the latest dismissed IDs from globalState into the cached
// message so that dismissals persisted while offline are honoured.
const persisted = this.extensionContext?.globalState.get<string[]>("kilo.dismissedNotificationIds", []) ?? []
if (persisted.length > 0) {
const cached = this.cachedNotificationsMessage as {
type: string
notifications: unknown[]
dismissedIds: string[]
}
const merged = Array.from(new Set([...cached.dismissedIds, ...persisted]))
this.cachedNotificationsMessage = { ...cached, dismissedIds: merged }
}
this.postMessage(this.cachedNotificationsMessage)
}
return
@@ -1624,6 +1636,21 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
if (!existing.includes(notificationId)) {
await this.extensionContext.globalState.update("kilo.dismissedNotificationIds", [...existing, notificationId])
}
// Update the cached message so the dismiss persists even if
// fetchAndSendNotifications() fails (e.g. no client / API error).
if (this.cachedNotificationsMessage) {
const cached = this.cachedNotificationsMessage as {
type: string
notifications: unknown[]
dismissedIds: string[]
}
if (!cached.dismissedIds.includes(notificationId)) {
this.cachedNotificationsMessage = {
...cached,
dismissedIds: [...cached.dismissedIds, notificationId],
}
}
}
await this.fetchAndSendNotifications()
this.connectionService.notifyNotificationDismissed(notificationId)
}
@@ -57,6 +57,7 @@ export const NotificationsProvider: ParentComponent = (props) => {
})
const dismiss = (id: string) => {
setDismissedIds((prev) => (prev.includes(id) ? prev : [...prev, id]))
vscode.postMessage({ type: "dismissNotification", notificationId: id })
}