History

Fix: always remove optimistic message on dispatch error to prevent ghost messages

When attemptedTurnStart is true but the thread.turn.start dispatch fails (e.g. network error), the optimistic user message was never removed from optimisticUserMessages. The catch block only cleaned up when !attemptedTurnStart, leaving a permanently visible ghost message. Move setOptimisticUserMessages filter outside the !attemptedTurnStart guard so it always runs on error. The prompt/image restoration remains gated behind !attemptedTurnStart since that only applies to pre-send failures.

Cursor Agent committed 8 months ago

Commit 80c2dac1 parent 5121dad1 file · +3 −3Browse files

Unified · Split

apps/web/src/components/ChatView.tsx+3−3
@@ -1509,14 +1509,14 @@ export default function ChatView({ threadId }: ChatViewProps) { · 1508 unmodified lines
15091509 createdAt: messageCreatedAt,
15101510 });
15111511 } catch (err) {
1512+ setOptimisticUserMessages((existing) =>
1513+ existing.filter((message) => message.id !== messageIdForSend),
1514+ );
15121515 if (
15131516 !attemptedTurnStart &&
15141517 promptRef.current.length === 0 &&
15151518 composerImagesRef.current.length === 0
15161519 ) {
1517− setOptimisticUserMessages((existing) =>
1518− existing.filter((message) => message.id !== messageIdForSend),
1519− );
15201520 promptRef.current = trimmed;
15211521 setPrompt(trimmed);
15221522 setComposerImages(composerImagesSnapshot);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t