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
1509 createdAt: messageCreatedAt,1509 createdAt: messageCreatedAt,
1510 });1510 });
1511 } catch (err) {1511 } catch (err) {
1512 setOptimisticUserMessages((existing) =>
1513 existing.filter((message) => message.id !== messageIdForSend),
1514 );
1512 if (1515 if (
1513 !attemptedTurnStart &&1516 !attemptedTurnStart &&
1514 promptRef.current.length === 0 &&1517 promptRef.current.length === 0 &&
1515 composerImagesRef.current.length === 01518 composerImagesRef.current.length === 0
1516 ) {1519 ) {
1517 setOptimisticUserMessages((existing) =>
1518 existing.filter((message) => message.id !== messageIdForSend),
1519 );
1520 promptRef.current = trimmed;1520 promptRef.current = trimmed;
1521 setPrompt(trimmed);1521 setPrompt(trimmed);
1522 setComposerImages(composerImagesSnapshot);1522 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