Skip to content

Commit 80c2dac

Browse files
committed
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.
1 parent 5121dad commit 80c2dac

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

apps/web/src/components/ChatView.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,14 +1509,14 @@ export default function ChatView({ threadId }: ChatViewProps) {
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);

0 commit comments

Comments
 (0)