Skip to content

Commit 8254ef3

Browse files
Chukwuebuka-2003dokterbob
authored andcommitted
fix: clear attachments when switching chat profiles
Clear attachments when confirming a profile switch to prevent confusing behavior where attachments appear but aren't sent (their serverId was tied to the old session). Fixes #2853
1 parent 088106b commit 8254ef3

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

frontend/src/components/header/ChatProfiles.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useContext, useEffect, useState } from 'react';
2+
import { useSetRecoilState } from 'recoil';
23

34
import {
45
ChainlitContext,
@@ -22,6 +23,8 @@ import {
2223
SelectValue
2324
} from '@/components/ui/select';
2425

26+
import { IAttachment, attachmentsState } from '@/state/chat';
27+
2528
import { NewChatDialog } from './NewChat';
2629

2730
interface Props {
@@ -34,6 +37,7 @@ export default function ChatProfiles({ navigate }: Props) {
3437
const { chatProfile, setChatProfile } = useChatSession();
3538
const { firstInteraction } = useChatMessages();
3639
const { clear } = useChatInteract();
40+
const setAttachments = useSetRecoilState<IAttachment[]>(attachmentsState);
3741
const [newChatProfile, setNewChatProfile] = useState<string | null>(null);
3842
const [openDialog, setOpenDialog] = useState(false);
3943

@@ -70,6 +74,7 @@ export default function ChatProfiles({ navigate }: Props) {
7074
const handleConfirm = (profile: string) => {
7175
setChatProfile(profile);
7276
setNewChatProfile(null);
77+
setAttachments([]);
7378
clear();
7479
handleClose();
7580
};

0 commit comments

Comments
 (0)