From 96aafcebace8e0449477674ed5d2f03c80a5e4c9 Mon Sep 17 00:00:00 2001 From: gongzhiyong Date: Wed, 15 Apr 2026 02:49:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(P0):=20=E4=BF=AE=E5=A4=8D=E5=8F=91=E9=80=81?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=90=8E=E4=B8=BB=E5=8C=BA=E5=9F=9F=E8=B7=B3?= =?UTF-8?q?=E5=9B=9E=E6=AC=A2=E8=BF=8E=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- langgraph/src/main.tsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/langgraph/src/main.tsx b/langgraph/src/main.tsx index 6f0c6ee..9e59f56 100644 --- a/langgraph/src/main.tsx +++ b/langgraph/src/main.tsx @@ -98,7 +98,7 @@ function App() { }, []); // Clear error and stale stream state when thread switches. - // Skip when doSubmit already called switchThread manually (to avoid clearing mid-stream). + // Skip when doSubmit set the flag (new thread created during submit — don't clear mid-stream). useEffect(() => { if (skipNextSwitchRef.current) { skipNextSwitchRef.current = false; @@ -217,12 +217,11 @@ function App() { setConcurrentStatus("idle"); return; } - // Only need to switchThread manually when a new thread was just created. - // For existing threads, currentThreadId didn't change so useEffect won't fire. - // Setting the skip flag prevents the useEffect from re-firing and clearing messages. + // 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. if (!currentThreadId) { skipNextSwitchRef.current = true; - thread.switchThread(activeThreadId); } try { localStorage.removeItem(`draft_${activeThreadId}`); } catch { /* ignore */ }