fix(frontend):keep DeerFlow chat thread ids in sync (#1931)

* fix: replay thread sync changes on top of main

* fix: avoid stale thread ids during stream startup
This commit is contained in:
Admire
2026-04-07 17:15:46 +08:00
committed by GitHub
parent 3b3e8e1b0b
commit ab41de2961
4 changed files with 34 additions and 10 deletions
@@ -41,20 +41,22 @@ export default function AgentChatPage() {
const { agent } = useAgent(agent_name);
const { threadId, isNewThread, setIsNewThread } = useThreadChat();
const { threadId, setThreadId, isNewThread, setIsNewThread } =
useThreadChat();
const [settings, setSettings] = useThreadSettings(threadId);
const { showNotification } = useNotification();
const [thread, sendMessage] = useThreadStream({
threadId: isNewThread ? undefined : threadId,
context: { ...settings.context, agent_name: agent_name },
onStart: () => {
onStart: (createdThreadId) => {
setThreadId(createdThreadId);
setIsNewThread(false);
// ! Important: Never use next.js router for navigation in this case, otherwise it will cause the thread to re-mount and lose all states. Use native history API instead.
history.replaceState(
null,
"",
`/workspace/agents/${agent_name}/chats/${threadId}`,
`/workspace/agents/${agent_name}/chats/${createdThreadId}`,
);
},
onFinish: (state) => {