fix: load messages early to trigger streaming poll

The messages were being streamed successfully but never displayed because:
- loadMessages() was only called after sendMessage() completed
- By then isStreaming was already false
- The polling effect never triggered

Now we load messages shortly after starting the send to:
1. Show the user message immediately
2. Trigger the polling effect for streaming updates
This commit is contained in:
Claude
2026-01-16 22:37:12 +00:00
parent ba6a22e5c4
commit 62fd43d086

View File

@@ -186,7 +186,8 @@ export function AIChat({ conversation, onConversationUpdate }: AIChatProps) {
try {
setStatus(`Connecting to ${conversation.model}...`);
await aiService.sendMessage(
// Start the message send (don't await yet)
const sendPromise = aiService.sendMessage(
conversation.id,
content,
(_chunk, _fullContent) => {
@@ -194,6 +195,15 @@ export function AIChat({ conversation, onConversationUpdate }: AIChatProps) {
},
);
// Small delay to let the user message and streaming assistant message be created
await new Promise((resolve) => setTimeout(resolve, 100));
// Load messages to show user message and start polling for streaming updates
await loadMessages();
// Now wait for the stream to complete
await sendPromise;
// Reload messages to get final state
await loadMessages();
setStatus(null);