Skip to content

Commit 939cd08

Browse files
committed
race condition fix
1 parent 7315b9a commit 939cd08

File tree

2 files changed

+6
-5
lines changed
  • apps/web/client/src
    • app/project/[id]/_components/right-panel/chat-tab/chat-input
    • components/store/editor/chat

2 files changed

+6
-5
lines changed

apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-input/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,21 @@ export const ChatInput = observer(({
138138
}
139139

140140
const savedInput = inputValue.trim();
141-
setInputValue('');
142141

143142
try {
144143
if (isStreaming) {
145-
// Queue the message if currently streaming
144+
// Queue the message if streaming
146145
const queuedMessage = editorEngine.chat.queue.enqueue(savedInput, chatMode);
147146
console.log('Message queued:', queuedMessage);
148147
} else {
149148
// Send immediately if not streaming
150149
await onSendMessage(savedInput, chatMode);
151150
}
151+
// Clear input
152+
setInputValue('');
152153
} catch (error) {
153154
console.error('Error sending message', error);
154155
toast.error('Failed to send message. Please try again.');
155-
setInputValue(savedInput);
156156
}
157157
}
158158

apps/web/client/src/components/store/editor/chat/queue.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,13 @@ export class MessageQueue {
6868
return;
6969
}
7070

71+
this._isProcessing = true;
72+
7173
const nextMessage = this.dequeue();
7274
if (!nextMessage) {
75+
this._isProcessing = false;
7376
return;
7477
}
75-
76-
this._isProcessing = true;
7778

7879
try {
7980
await this.editorEngine.chat.sendMessage(nextMessage.content, nextMessage.type);

0 commit comments

Comments
 (0)