fix: 第一个chunk后loading class被移除导致后续内容更新全部跳过
updateLastAssistantMessage 的首次调用找到 .message.assistant.loading 后
立即 remove('loading'),导致后续 chunk 调用时选择器找不到元素,直接 return。
修复:
- 首次调用:找到 .loading,移除 loading 指示器,但保留 class 直到流结束
- 后续调用:.loading 选择器失败时回退到 .message.assistant:last-of-type
- loading class 在 sendMessage 的 try/finally 或 catch 中统一移除
This commit is contained in:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user