refactor: update NewChatPage to re-initialize thread on search space switch and add new SSE event for document updates

This commit is contained in:
DESKTOP-RTLN3BA\$punk 2026-03-29 02:52:23 -07:00
parent 461192174d
commit 2a06d035f5
2 changed files with 4 additions and 4 deletions

View file

@ -273,7 +273,6 @@ export default function NewChatPage() {
// Initialize thread and load messages // Initialize thread and load messages
// For new chats (no urlChatId), we use lazy creation - thread is created on first message // For new chats (no urlChatId), we use lazy creation - thread is created on first message
// biome-ignore lint/correctness/useExhaustiveDependencies: searchSpaceId triggers re-init when switching spaces with the same urlChatId
const initializeThread = useCallback(async () => { const initializeThread = useCallback(async () => {
setIsInitializing(true); setIsInitializing(true);
@ -334,7 +333,6 @@ export default function NewChatPage() {
} }
}, [ }, [
urlChatId, urlChatId,
searchSpaceId,
setMessageDocumentsMap, setMessageDocumentsMap,
setMentionedDocuments, setMentionedDocuments,
setSidebarDocuments, setSidebarDocuments,
@ -342,10 +340,10 @@ export default function NewChatPage() {
closeEditorPanel, closeEditorPanel,
]); ]);
// Initialize on mount // Initialize on mount, and re-init when switching search spaces (even if urlChatId is the same)
useEffect(() => { useEffect(() => {
initializeThread(); initializeThread();
}, [initializeThread]); }, [initializeThread, searchSpaceId]);
// Prefetch document titles for @ mention picker // Prefetch document titles for @ mention picker
// Runs when user lands on page so data is ready when they type @ // Runs when user lands on page so data is ready when they type @
@ -882,6 +880,7 @@ export default function NewChatPage() {
setMentionedDocuments, setMentionedDocuments,
setSidebarDocuments, setSidebarDocuments,
setMessageDocumentsMap, setMessageDocumentsMap,
setAgentCreatedDocuments,
queryClient, queryClient,
currentThread, currentThread,
currentUser, currentUser,

View file

@ -229,6 +229,7 @@ export type SSEEvent =
| { type: "data-thinking-step"; data: ThinkingStepData } | { type: "data-thinking-step"; data: ThinkingStepData }
| { type: "data-thread-title-update"; data: { threadId: number; title: string } } | { type: "data-thread-title-update"; data: { threadId: number; title: string } }
| { type: "data-interrupt-request"; data: Record<string, unknown> } | { type: "data-interrupt-request"; data: Record<string, unknown> }
| { type: "data-documents-updated"; data: Record<string, unknown> }
| { type: "error"; errorText: string }; | { type: "error"; errorText: string };
/** /**