Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/components/chat/hooks/useChatSessionState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,14 @@ export function useChatSessionState({

const chatMessages = useMemo(() => {
const all = normalizedToChatMessages(storeMessages);
// Show pending user message when no session data exists yet (new session, pre-backend-response)
if (pendingUserMessage && all.length === 0) {
return [pendingUserMessage];
// Show pending user message until a user message actually appears in the store.
// This covers both the "no messages yet" case and the race condition where
// `stream_delta` (AI content) arrives in realtime before the echoed user
// message — without this check the pending message would disappear and the
// AI response would briefly appear as the first visible message.
const hasUserMessage = all.some((m) => m.type === 'user');
if (pendingUserMessage && !hasUserMessage) {
return [...all, pendingUserMessage];
}
if (viewHiddenCount > 0 && viewHiddenCount < all.length) return all.slice(0, -viewHiddenCount);
return all;
Expand Down