🐛 fix: when use agentbuilder the topic id should use new & clear topic… (#10983)

* feat: when use agentbuilder the topic id should use new & clear topicid in unmount

* feat: when click chat button,should clear topicid first
This commit is contained in:
Shinji-Li
2025-12-26 11:34:31 +08:00
committed by GitHub
parent 7f69cb1e54
commit 0b2b0963d4
2 changed files with 18 additions and 1 deletions
@@ -12,6 +12,7 @@ import ModelSelect from '@/features/ModelSelect';
import { useQueryRoute } from '@/hooks/useQueryRoute';
import { useAgentStore } from '@/store/agent';
import { agentSelectors } from '@/store/agent/selectors';
import { useChatStore } from '@/store/chat';
import EditorCanvas from '../EditorCanvas';
import AgentHeader from './AgentHeader';
@@ -22,6 +23,7 @@ const ProfileEditor = memo(() => {
const config = useAgentStore(agentSelectors.currentAgentConfig, isEqual);
const updateConfig = useAgentStore((s) => s.updateAgentConfig);
const agentId = useAgentStore((s) => s.activeAgentId);
const switchTopic = useChatStore((s) => s.switchTopic);
const router = useQueryRoute();
return (
@@ -63,6 +65,8 @@ const ProfileEditor = memo(() => {
icon={PlayIcon}
onClick={() => {
if (!agentId) return;
// Clear topicId before navigating to prevent stale state
switchTopic(undefined, true);
router.push(urlJoin('/agent', agentId));
}}
type={'primary'}
@@ -1,4 +1,4 @@
import { type ReactNode, memo, useMemo } from 'react';
import { type ReactNode, memo, useEffect, useMemo } from 'react';
import { ConversationProvider } from '@/features/Conversation';
import { useOperationState } from '@/hooks/useOperationState';
@@ -17,6 +17,19 @@ interface AgentBuilderProviderProps {
*/
const AgentBuilderProvider = memo<AgentBuilderProviderProps>(({ agentId, children }) => {
const activeTopicId = useChatStore((s) => s.activeTopicId);
const switchTopic = useChatStore((s) => s.switchTopic);
// Reset topicId on mount and unmount to avoid stale topicId leaking
// when navigating from Profile page to agent conversation page
useEffect(() => {
// Mount: start with a fresh conversation (topicId = undefined)
switchTopic(undefined, true);
return () => {
// Unmount: clean up topicId to prevent state leakage
switchTopic(undefined, true);
};
}, [switchTopic]);
// Build conversation context for agent builder
// Using agent_builder scope for message management