fix: Hide raw HTML during streaming - show loading until complete
All checks were successful
BotUI CI/CD / build (push) Successful in 42s

This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2026-04-15 07:59:16 -03:00
parent 2081ee8000
commit 4b85eb5d32

View file

@ -309,17 +309,16 @@ function addMessage(sender, content, msgId) {
"</div>";
} else {
var cleanContent = stripMarkdownBlocks(content);
// Check if content has HTML (any tag, including comments)
var hasHtmlTags = /<\/?[a-zA-Z][^>]*>|<!--|-->/i.test(cleanContent);
console.log("Bot message - hasHtmlTags:", hasHtmlTags, "content length:", cleanContent.length, "msgId:", msgId);
var parsed;
if (hasHtmlTags && msgId) {
// Streaming HTML content - don't show raw HTML, show loading indicator
// Content will be rendered at finalizeStreaming
// When msgId is present, we're in streaming mode - show loading until complete
// This prevents raw HTML from flashing during streaming
if (msgId) {
parsed = '<div class="streaming-loading"><span class="loading-dots">...</span></div>';
} else if (hasHtmlTags) {
// Complete HTML content - render directly
// Complete HTML content (not streaming) - render directly
parsed = cleanContent;
} else {
// Markdown content
@ -791,15 +790,8 @@ function updateStreaming(content) {
msgContent.innerHTML = renderMentionInMessage(cleanContent);
lastRenderTime = Date.now();
if (!isUserScrolling) scrollToBottom(true);
} else {
// Tags not balanced yet - show escaped HTML to avoid showing raw tags
// This prevents HTML from appearing as raw text before it's ready
var escapedContent = escapeHtml(cleanContent);
// Only update if content changed to avoid flickering
if (msgContent.textContent !== cleanContent) {
msgContent.textContent = cleanContent;
}
}
// If not balanced, keep showing loading - don't show raw HTML text!
} else {
// Standard markdown/text rendering
var parsed = typeof marked !== "undefined" && marked.parse