fix(chatbot): preserve optimistic message during history playback of active sessions

This commit is contained in:
yiling
2026-07-11 15:08:07 +08:00
parent b13c47f207
commit 6a5f8db0d6
2 changed files with 187 additions and 1 deletions
+3 -1
View File
@@ -196,10 +196,12 @@ export const useChatbotStore = create<ChatbotState>((set) => ({
} else if (data.type === 'entry') {
const entry = data.entry as ChatMessage
set((s) => {
const isExisting = s.messages.some((m) => m.id === entry.id)
// Replace temp/optimistic message when the real user message streams back
const filtered = s.messages.filter(
(m) =>
m.id !== entry.id && !(entry.role === 'user' && m.id.startsWith('temp-')),
m.id !== entry.id &&
!(entry.role === 'user' && !isExisting && m.id.startsWith('temp-')),
)
// Prevent duplicates by ID