Skip to content

Commit d008d1e

Browse files
fix: clear attachments when switching chat profiles (Chainlit#2858)
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 Chainlit#2853 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Clear attachments when confirming a chat profile switch to avoid showing files from the previous session that wouldn’t send. On confirm, reset `attachmentsState` via `recoil` and clear the chat session. Fixes Chainlit#2853. <sup>Written for commit a886879. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. -->
1 parent fa7bc09 commit d008d1e

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

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)