fix(site): remove optimistic message when real server message arrives on agents page (#22432)

This commit is contained in:
Danielle Maywood
2026-02-28 16:29:42 +00:00
committed by GitHub
parent bde772cfa3
commit 607c25b07e
@@ -236,9 +236,23 @@ const createChatStore = (): ChatStore => {
const nextMessagesByID = new Map(state.messagesByID);
nextMessagesByID.set(message.id, message);
const nextOrderedMessageIDs = isDuplicate
? state.orderedMessageIDs
: buildOrderedMessageIDs(Array.from(nextMessagesByID.values()));
// When a real server message (positive ID) arrives, remove any
// optimistic placeholder (negative ID) for the same role so the
// user doesn't momentarily see the message twice.
if (message.id > 0) {
for (const [id, existing] of nextMessagesByID) {
if (id < 0 && existing.role === message.role) {
nextMessagesByID.delete(id);
}
}
}
const needsReorder =
!isDuplicate || nextMessagesByID.size !== state.messagesByID.size;
const nextOrderedMessageIDs = needsReorder
? buildOrderedMessageIDs(Array.from(nextMessagesByID.values()))
: state.orderedMessageIDs;
setState((current) => ({
...current,