From 2a06d035f5f039ef2b51f419cfde2ec806b816c2 Mon Sep 17 00:00:00 2001 From: "DESKTOP-RTLN3BA\\$punk" Date: Sun, 29 Mar 2026 02:52:23 -0700 Subject: [PATCH] refactor: update NewChatPage to re-initialize thread on search space switch and add new SSE event for document updates --- .../[search_space_id]/new-chat/[[...chat_id]]/page.tsx | 7 +++---- surfsense_web/lib/chat/streaming-state.ts | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx b/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx index 699160aeb..9809c9b2e 100644 --- a/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx +++ b/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx @@ -273,7 +273,6 @@ export default function NewChatPage() { // Initialize thread and load messages // 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 () => { setIsInitializing(true); @@ -334,7 +333,6 @@ export default function NewChatPage() { } }, [ urlChatId, - searchSpaceId, setMessageDocumentsMap, setMentionedDocuments, setSidebarDocuments, @@ -342,10 +340,10 @@ export default function NewChatPage() { closeEditorPanel, ]); - // Initialize on mount + // Initialize on mount, and re-init when switching search spaces (even if urlChatId is the same) useEffect(() => { initializeThread(); - }, [initializeThread]); + }, [initializeThread, searchSpaceId]); // Prefetch document titles for @ mention picker // Runs when user lands on page so data is ready when they type @ @@ -882,6 +880,7 @@ export default function NewChatPage() { setMentionedDocuments, setSidebarDocuments, setMessageDocumentsMap, + setAgentCreatedDocuments, queryClient, currentThread, currentUser, diff --git a/surfsense_web/lib/chat/streaming-state.ts b/surfsense_web/lib/chat/streaming-state.ts index 895edebf9..7894c8115 100644 --- a/surfsense_web/lib/chat/streaming-state.ts +++ b/surfsense_web/lib/chat/streaming-state.ts @@ -229,6 +229,7 @@ export type SSEEvent = | { type: "data-thinking-step"; data: ThinkingStepData } | { type: "data-thread-title-update"; data: { threadId: number; title: string } } | { type: "data-interrupt-request"; data: Record } + | { type: "data-documents-updated"; data: Record } | { type: "error"; errorText: string }; /**