fix(frontend): prevent stale 'new' thread ID from triggering 422 history requests (#1960)
After history.replaceState updates the URL from /chats/new to
/chats/{UUID}, Next.js useParams does not update because replaceState
bypasses the router. The useEffect in useThreadChat would then set
threadIdFromPath ('new') as the threadId, causing the LangGraph SDK
to call POST /threads/new/history which returns HTTP 422 (Invalid
thread ID: must be a UUID).
This fix adds a guard to skip the threadId update when
threadIdFromPath is the literal string 'new', preserving the
already-correct UUID that was set when the thread was created.
This commit is contained in:
parent
722a9c4753
commit
24805200f0
|
|
@ -24,6 +24,14 @@ export function useThreadChat() {
|
||||||
setThreadId(uuid());
|
setThreadId(uuid());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Guard: after history.replaceState updates the URL from /chats/new to
|
||||||
|
// /chats/{UUID}, Next.js useParams may still return the stale "new" value
|
||||||
|
// because replaceState does not trigger router updates. Avoid propagating
|
||||||
|
// this invalid thread ID to downstream hooks (e.g. useStream), which would
|
||||||
|
// cause a 422 from LangGraph Server.
|
||||||
|
if (threadIdFromPath === "new") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
setIsNewThread(false);
|
setIsNewThread(false);
|
||||||
setThreadId(threadIdFromPath);
|
setThreadId(threadIdFromPath);
|
||||||
}, [pathname, threadIdFromPath]);
|
}, [pathname, threadIdFromPath]);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue