fix(P0): 修复新线程发消息后跳回欢迎屏
Trigger auto deployment for soc-langgraph / build-and-deploy (push) Failing after 20s
Deploy LangGraph UI to Azure Static Web Apps / build-and-deploy (push) Failing after 38s

根因:ensureThread() 通过 setCurrentThreadId 设置新线程ID,但 React 状态
未同步刷新,useStream 仍绑定 threadId=undefined,导致 submit() 提交到
错误的线程。

修复:在 submit 前手动调 thread.switchThread(activeThreadId),确保
useStream 立即指向新创建的线程。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
gongzhiyong
2026-04-15 02:51:45 +08:00
co-authored by Claude Opus 4.6
parent 1c82092735
commit 36e7197994
+4 -3
View File
@@ -217,11 +217,12 @@ function App() {
setConcurrentStatus("idle");
return;
}
// For a newly created thread, currentThreadId just changed so the useEffect
// would call thread.switchThread() which clears thread.messages mid-stream.
// Skip it — useStream already uses the updated threadId prop from currentThreadId.
// For a newly created thread, currentThreadId just changed via setCurrentThreadId
// but React state hasn't flushed yet — useStream still has threadId=undefined.
// Manually switch useStream to the new thread so submit() targets the right thread.
if (!currentThreadId) {
skipNextSwitchRef.current = true;
thread.switchThread(activeThreadId);
}
try { localStorage.removeItem(`draft_${activeThreadId}`); } catch { /* ignore */ }