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.
This commit is contained in:
1 parent
5121dad193
commit
80c2dac816
1 file changed
+3
-3
@@ -1509,14 +1509,14 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
createdAt: messageCreatedAt,
|
||||
});
|
||||
} catch (err) {
|
||||
setOptimisticUserMessages((existing) =>
|
||||
existing.filter((message) => message.id !== messageIdForSend),
|
||||
);
|
||||
if (
|
||||
!attemptedTurnStart &&
|
||||
promptRef.current.length === 0 &&
|
||||
composerImagesRef.current.length === 0
|
||||
) {
|
||||
setOptimisticUserMessages((existing) =>
|
||||
existing.filter((message) => message.id !== messageIdForSend),
|
||||
);
|
||||
promptRef.current = trimmed;
|
||||
setPrompt(trimmed);
|
||||
setComposerImages(composerImagesSnapshot);
|
||||
|
||||
Reference in new issue
Block a user