fix: Remove streaming message from DOM when user sends new message
All checks were successful
BotUI CI/CD / build (push) Successful in 41s
All checks were successful
BotUI CI/CD / build (push) Successful in 41s
This fixes the visual ordering issue where user messages appeared in the middle of bot streaming responses. Now when user sends a new message, the incomplete streaming message is removed from the DOM, ensuring proper conversation ordering.
This commit is contained in:
parent
bb05239890
commit
af9ba310fe
1 changed files with 46 additions and 34 deletions
|
|
@ -935,44 +935,56 @@ function updateStreaming(content) {
|
|||
});
|
||||
}
|
||||
|
||||
function sendMessage(messageContent) {
|
||||
var input = document.getElementById("messageInput");
|
||||
if (!input) {
|
||||
console.error("Chat input not found");
|
||||
return;
|
||||
}
|
||||
function sendMessage(messageContent) {
|
||||
var input = document.getElementById("messageInput");
|
||||
if (!input) {
|
||||
console.error("Chat input not found");
|
||||
return;
|
||||
}
|
||||
|
||||
// If no messageContent provided, read from input
|
||||
var content = messageContent || input.value.trim();
|
||||
if (!content) {
|
||||
return;
|
||||
}
|
||||
// If no messageContent provided, read from input
|
||||
var content = messageContent || input.value.trim();
|
||||
if (!content) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If called from input field (no messageContent provided), clear input
|
||||
if (!messageContent) {
|
||||
hideMentionDropdown();
|
||||
input.value = "";
|
||||
input.focus();
|
||||
}
|
||||
// Cancel and remove any ongoing streaming message before sending new message
|
||||
// This ensures the conversation order stays correct
|
||||
if (isStreaming && streamingMessageId) {
|
||||
var streamingEl = document.getElementById(streamingMessageId);
|
||||
if (streamingEl) {
|
||||
streamingEl.remove();
|
||||
}
|
||||
isStreaming = false;
|
||||
streamingMessageId = null;
|
||||
currentStreamingContent = "";
|
||||
}
|
||||
|
||||
addMessage("user", content);
|
||||
// If called from input field (no messageContent provided), clear input
|
||||
if (!messageContent) {
|
||||
hideMentionDropdown();
|
||||
input.value = "";
|
||||
input.focus();
|
||||
}
|
||||
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
bot_id: currentBotId,
|
||||
user_id: currentUserId,
|
||||
session_id: currentSessionId,
|
||||
channel: "web",
|
||||
content: content,
|
||||
message_type: MessageType.USER,
|
||||
timestamp: new Date().toISOString(),
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
notify("Not connected to server. Message not sent.", "warning");
|
||||
}
|
||||
}
|
||||
addMessage("user", content);
|
||||
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
bot_id: currentBotId,
|
||||
user_id: currentUserId,
|
||||
session_id: currentSessionId,
|
||||
channel: "web",
|
||||
content: content,
|
||||
message_type: MessageType.USER,
|
||||
timestamp: new Date().toISOString(),
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
notify("Not connected to server. Message not sent.", "warning");
|
||||
}
|
||||
}
|
||||
|
||||
window.sendMessage = sendMessage;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue