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.
Unified · Split
| @@ -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 === 0 | 1518 | 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); |