Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/ui/src/views/chatmessage/ChatMessage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,12 @@ const ChatMessage = ({ open, chatflowid, isAgentCanvas, isDialog, previews, setP
obj.agentFlowExecutedData = JSON.parse(message.execution.executionData)
return obj
})
setMessages((prevMessages) => [...prevMessages, ...loadedMessages])
// Use functional update to filter out previously loaded history messages (by id) before appending,
// preventing duplicate messages when the API is called multiple times (e.g. React StrictMode)
setMessages((prevMessages) => {
const initialMessages = prevMessages.filter((msg) => !msg.id || !loadedMessages.some((lm) => lm.id === msg.id))
return [...initialMessages, ...loadedMessages]
Comment thread
yuyol marked this conversation as resolved.
})
setLocalStorageChatflow(chatflowid, chatId)
}

Expand All @@ -1375,7 +1380,13 @@ const ChatMessage = ({ open, chatflowid, isAgentCanvas, isDialog, previews, setP
}
return obj
})
setMessages((prevMessages) => [...prevMessages, ...loadedMessages])
// Filter out previously loaded execution messages (by id) before appending,
// preventing duplicates when the API is called multiple times (e.g. React StrictMode)
// Messages without an ID (e.g., initial welcome message, in-progress user messages) are always preserved.
setMessages((prevMessages) => {
const initialMessages = prevMessages.filter((msg) => !msg.id || !loadedMessages.some((lm) => lm.id === msg.id))
return [...initialMessages, ...loadedMessages]
Comment thread
yuyol marked this conversation as resolved.
})
setLocalStorageChatflow(chatflowid, chatId)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down