fix: discard reverted optimistic messages after send

Removes reverted branch messages from the optimistic shadow after a successful send
Prevents deleted messages from being merged back in on the next tail refresh
Covers the cleanup behavior with an updated test
This commit is contained in:
Bohdan Triapitsyn
2026-07-29 01:50:22 +03:00
parent 3cf1d82106
commit 840431b49a
2 changed files with 17 additions and 1 deletions
+11
View File
@@ -937,6 +937,17 @@ export async function optimisticSend(input: {
const part = { ...stateBeforeSend.part }
for (const revertedMessage of revertedMessages) delete part[revertedMessage.id]
store.setState({ session, message, part })
// A server-backed user message can still remain in the loader's optimistic
// shadow until a page fetch confirms it. Forget the reverted branch there
// too, or the next tail refresh will merge those deleted messages back in.
for (const revertedMessage of revertedMessages) {
_optimisticConfirm?.({
sessionID: input.sessionId,
directory: targetDirectory,
messageID: revertedMessage.id,
})
}
}
const messageID = ascendingId("msg")