fix(P0): 修复新线程发消息后跳回欢迎屏
根因: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:
co-authored by
Claude Opus 4.6
parent
1c82092735
commit
36e7197994
@@ -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 */ }
|
||||
|
||||
Reference in New Issue
Block a user