Fix: deleting a recently created session and then creating a new session shows the deleted session's content (#9351)
Signed-off-by: Monroe Williams <monroe@pobox.com> Co-authored-by: Douwe M Osinga <douwe@sidewalklabs.com>
This commit is contained in:
@@ -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);
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -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<SessionListViewProps> = 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') }));
|
||||
|
||||
@@ -32,6 +32,10 @@ import { useSessionEvents, type SessionEvent } from './useSessionEvents';
|
||||
|
||||
const resultsCache = new Map<string, { messages: Message[]; session: Session }>();
|
||||
|
||||
export function clearSessionCache(sessionId: string): void {
|
||||
resultsCache.delete(sessionId);
|
||||
}
|
||||
|
||||
interface UseChatStreamProps {
|
||||
sessionId: string;
|
||||
onStreamFinish: () => void;
|
||||
|
||||
Reference in New Issue
Block a user