Skip to content

Commit ed348b1

Browse files
authored
Merge pull request #472 from MODSetter/dev
feat: fix chat initialization logic in ResearcherPage
2 parents a9c9e3f + 461d6ab commit ed348b1

File tree

1 file changed

+15
-3
lines changed
  • surfsense_web/app/dashboard/[search_space_id]/researcher/[[...chat_id]]

1 file changed

+15
-3
lines changed

surfsense_web/app/dashboard/[search_space_id]/researcher/[[...chat_id]]/page.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { type CreateMessage, type Message, useChat } from "@ai-sdk/react";
44
import { useParams, useRouter } from "next/navigation";
5-
import { useEffect, useMemo } from "react";
5+
import { useEffect, useMemo, useRef } from "react";
66
import ChatInterface from "@/components/chat/ChatInterface";
77
import { useChatAPI, useChatState } from "@/hooks/use-chat";
88
import { useDocumentTypes } from "@/hooks/use-document-types";
@@ -12,10 +12,16 @@ import { useSearchSourceConnectors } from "@/hooks/use-search-source-connectors"
1212
export default function ResearcherPage() {
1313
const { search_space_id, chat_id } = useParams();
1414
const router = useRouter();
15+
const hasSetInitialConnectors = useRef(false);
1516

1617
const chatIdParam = Array.isArray(chat_id) ? chat_id[0] : chat_id;
1718
const isNewChat = !chatIdParam;
1819

20+
// Reset the flag when chat ID changes
21+
useEffect(() => {
22+
hasSetInitialConnectors.current = false;
23+
}, [chatIdParam]);
24+
1925
const {
2026
token,
2127
isLoading,
@@ -163,9 +169,14 @@ export default function ResearcherPage() {
163169
setTopK,
164170
]);
165171

166-
// Set all sources as default for new chats
172+
// Set all sources as default for new chats (only once on initial mount)
167173
useEffect(() => {
168-
if (isNewChat && selectedConnectors.length === 0 && documentTypes.length > 0) {
174+
if (
175+
isNewChat &&
176+
!hasSetInitialConnectors.current &&
177+
selectedConnectors.length === 0 &&
178+
documentTypes.length > 0
179+
) {
169180
// Combine all document types and live search connectors
170181
const allSourceTypes = [
171182
...documentTypes.map((dt) => dt.type),
@@ -174,6 +185,7 @@ export default function ResearcherPage() {
174185

175186
if (allSourceTypes.length > 0) {
176187
setSelectedConnectors(allSourceTypes);
188+
hasSetInitialConnectors.current = true;
177189
}
178190
}
179191
}, [

0 commit comments

Comments
 (0)