From 1de10841736a387caa6326f9512940edf93687fb Mon Sep 17 00:00:00 2001 From: Metona Date: Sun, 5 Apr 2026 00:34:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=AC=AC=E4=B8=80=E4=B8=AAchunk?= =?UTF-8?q?=E5=90=8Eloading=20class=E8=A2=AB=E7=A7=BB=E9=99=A4=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E5=90=8E=E7=BB=AD=E5=86=85=E5=AE=B9=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=85=A8=E9=83=A8=E8=B7=B3=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updateLastAssistantMessage 的首次调用找到 .message.assistant.loading 后 立即 remove('loading'),导致后续 chunk 调用时选择器找不到元素,直接 return。 修复: - 首次调用:找到 .loading,移除 loading 指示器,但保留 class 直到流结束 - 后续调用:.loading 选择器失败时回退到 .message.assistant:last-of-type - loading class 在 sendMessage 的 try/finally 或 catch 中统一移除 --- js/components/chat-area.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/js/components/chat-area.js b/js/components/chat-area.js index 3ad6f24..b29c394 100644 --- a/js/components/chat-area.js +++ b/js/components/chat-area.js @@ -221,14 +221,21 @@ export function appendMessageDOM(msg, index) { /** 更新最后一条 assistant 消息(流式输出) */ export function updateLastAssistantMessage(content, think, stats, model) { - const lastMsg = messagesContainerEl.querySelector('.message.assistant.loading'); + let lastMsg = messagesContainerEl.querySelector('.message.assistant.loading'); + if (!lastMsg) { + // loading class 已在首次调用时移除,用 last-of-type 回退 + lastMsg = messagesContainerEl.querySelector('.message.assistant:last-of-type'); + } if (!lastMsg) return; - lastMsg.classList.remove('loading'); - const loadingDots = lastMsg.querySelector('.loading-dots'); - const loadingText = lastMsg.querySelector('.loading-text'); - if (loadingDots) loadingDots.remove(); - if (loadingText) loadingText.remove(); + // 仅首次调用时移除 loading 指示器 + if (lastMsg.classList.contains('loading')) { + lastMsg.classList.remove('loading'); + const loadingDots = lastMsg.querySelector('.loading-dots'); + const loadingText = lastMsg.querySelector('.loading-text'); + if (loadingDots) loadingDots.remove(); + if (loadingText) loadingText.remove(); + } if (model) { let modelTag = lastMsg.querySelector('.model-tag');