From 3ab8ba1be8deefa10ed8c51d03c1ce0e27918dd2 Mon Sep 17 00:00:00 2001 From: Monroe Williams Date: Mon, 15 Jun 2026 08:34:02 -0700 Subject: [PATCH] Fix: deleting a recently created session and then creating a new session shows the deleted session's content (#9351) Signed-off-by: Monroe Williams Co-authored-by: Douwe M Osinga --- ui/desktop/src/App.tsx | 10 ++++++++++ ui/desktop/src/components/sessions/SessionListView.tsx | 2 ++ ui/desktop/src/hooks/useChatStream.ts | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/ui/desktop/src/App.tsx b/ui/desktop/src/App.tsx index 6ec0ae915..bc71fb921 100644 --- a/ui/desktop/src/App.tsx +++ b/ui/desktop/src/App.tsx @@ -402,11 +402,21 @@ export function AppInner() { }); }; + const handleSessionDeleted = (event: Event) => { + const { sessionId } = (event as CustomEvent<{ sessionId: string }>).detail; + + setActiveSessions((prev) => { + return prev.filter((session) => session.sessionId !== sessionId); + }); + }; + window.addEventListener(AppEvents.ADD_ACTIVE_SESSION, handleAddActiveSession); window.addEventListener(AppEvents.CLEAR_INITIAL_MESSAGE, handleClearInitialMessage); + window.addEventListener(AppEvents.SESSION_DELETED, handleSessionDeleted); return () => { window.removeEventListener(AppEvents.ADD_ACTIVE_SESSION, handleAddActiveSession); window.removeEventListener(AppEvents.CLEAR_INITIAL_MESSAGE, handleClearInitialMessage); + window.removeEventListener(AppEvents.SESSION_DELETED, handleSessionDeleted); }; }, []); diff --git a/ui/desktop/src/components/sessions/SessionListView.tsx b/ui/desktop/src/components/sessions/SessionListView.tsx index 6afaec055..2f40af838 100644 --- a/ui/desktop/src/components/sessions/SessionListView.tsx +++ b/ui/desktop/src/components/sessions/SessionListView.tsx @@ -46,6 +46,7 @@ import { type SessionListItem, } from '../../acp/sessions'; import { getSearchShortcutText } from '../../utils/keyboardShortcuts'; +import { clearSessionCache } from '../../hooks/useChatStream'; const i18n = defineMessages({ editSessionTitle: { id: 'sessions.edit.title', defaultMessage: 'Edit Session Description' }, @@ -505,6 +506,7 @@ const SessionListView: React.FC = React.memo( window.dispatchEvent( new CustomEvent(AppEvents.SESSION_DELETED, { detail: { sessionId: sessionToDeleteId } }) ); + clearSessionCache(sessionToDeleteId); } catch (error) { console.error('Error deleting session:', error); toast.error(intl.formatMessage(i18n.deleteFailed, { name: sessionName, error: errorMessage(error, 'Unknown error') })); diff --git a/ui/desktop/src/hooks/useChatStream.ts b/ui/desktop/src/hooks/useChatStream.ts index da0ef9706..c1eb21aa2 100644 --- a/ui/desktop/src/hooks/useChatStream.ts +++ b/ui/desktop/src/hooks/useChatStream.ts @@ -32,6 +32,10 @@ import { useSessionEvents, type SessionEvent } from './useSessionEvents'; const resultsCache = new Map(); +export function clearSessionCache(sessionId: string): void { + resultsCache.delete(sessionId); +} + interface UseChatStreamProps { sessionId: string; onStreamFinish: () => void;