diff --git a/src/renderer/src/hooks/useTopic.ts b/src/renderer/src/hooks/useTopic.ts index ecd03bd89f..e8b9077690 100644 --- a/src/renderer/src/hooks/useTopic.ts +++ b/src/renderer/src/hooks/useTopic.ts @@ -34,7 +34,7 @@ export function useActiveTopic(assistantId: string, topic?: Topic) { useEffect(() => { // activeTopic not in assistant.topics - if (assistant && !find(assistant.topics, { id: activeTopic?.id })) { + if (assistant && assistant.topics.length > 0 && !find(assistant.topics, { id: activeTopic?.id })) { setActiveTopic(assistant.topics[0]) } }, [activeTopic?.id, assistant]) diff --git a/src/renderer/src/pages/home/HomePage.tsx b/src/renderer/src/pages/home/HomePage.tsx index 2a8f946c65..78ac37bde3 100644 --- a/src/renderer/src/pages/home/HomePage.tsx +++ b/src/renderer/src/pages/home/HomePage.tsx @@ -29,6 +29,7 @@ const HomePage: FC = () => { const setActiveAssistant = useCallback( (newAssistant: Assistant) => { + if (newAssistant.id === activeAssistant.id) return startTransition(() => { _setActiveAssistant(newAssistant) // 同步更新 active topic,避免不必要的重新渲染 @@ -36,7 +37,7 @@ const HomePage: FC = () => { _setActiveTopic((prev) => (newTopic?.id === prev.id ? prev : newTopic)) }) }, - [_setActiveTopic] + [_setActiveTopic, activeAssistant] ) const setActiveTopic = useCallback(