fix(P1): load thread state before switching threadId to prevent welcome flash
Previously: setHistoricalMessages([]) + setCurrentThreadId() fired together, causing a render where both thread.messages (cleared by switchThread) and historicalMessages were empty → welcome screen shown. Fix: await loadThreadState() first, then set historicalMessages/ui and currentThreadId atomically. historicalMessages is populated before the first render after the switch, so the welcome screen never flashes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
23527b3bdc
commit
820a40982e
@@ -43,13 +43,13 @@ export function useConversation(
|
||||
} catch {
|
||||
setInput("");
|
||||
}
|
||||
setHistoricalMessages([]);
|
||||
setHistoricalUi([]);
|
||||
// Load state BEFORE switching threadId so historicalMessages is populated
|
||||
// when the first render after the switch fires — avoids flash of welcome screen.
|
||||
const state = await loadThreadState(client, threadId);
|
||||
setHistoricalMessages(state.messages.length ? state.messages : []);
|
||||
setHistoricalUi(state.ui.length ? (state.ui as UIMsgLocal[]) : []);
|
||||
setCurrentThreadId(threadId);
|
||||
setSidebarOpen(false);
|
||||
const state = await loadThreadState(client, threadId);
|
||||
if (state.messages.length) setHistoricalMessages(state.messages);
|
||||
if (state.ui.length) setHistoricalUi(state.ui as UIMsgLocal[]);
|
||||
}, [currentThreadId, input, client, setInput]);
|
||||
|
||||
const handleDeleteThread = useCallback(async (threadId: string) => {
|
||||
|
||||
Reference in New Issue
Block a user