fix: ChatPage loadMessages 中 mapped.forEach 闭包错误导致页面白屏;移至 async 内部
This commit is contained in:
1 parent
5d1370156e
commit
c0ec9e0e88
1 file changed
+6
-7
@@ -557,6 +557,12 @@ const ChatPage: React.FC = () => {
|
|||||||
createdAt: m.createdAt || m.created_at || new Date().toISOString(),
|
createdAt: m.createdAt || m.created_at || new Date().toISOString(),
|
||||||
}));
|
}));
|
||||||
setMessages(mapped);
|
setMessages(mapped);
|
||||||
|
// 页面刷新时若仍有「⏳」占位的媒体消息,继续轮询后端回写结果
|
||||||
|
mapped.forEach((m) => {
|
||||||
|
if (m.role === 'assistant' && typeof m.content === 'string' && m.content.startsWith('⏳')) {
|
||||||
|
startMediaPolling(id, m.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('加载消息失败', err);
|
console.error('加载消息失败', err);
|
||||||
setMessages([]);
|
setMessages([]);
|
||||||
@@ -565,13 +571,6 @@ const ChatPage: React.FC = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
loadMessages();
|
loadMessages();
|
||||||
|
|
||||||
// 页面刷新时若仍有「⏳」占位的媒体消息,继续轮询后端回写结果
|
|
||||||
mapped.forEach((m) => {
|
|
||||||
if (m.role === 'assistant' && typeof m.content === 'string' && m.content.startsWith('⏳')) {
|
|
||||||
startMediaPolling(id, m.id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
// 媒体(图像/视频)异步生成轮询:后端先返回「⏳」占位,前端定时拉取该消息最新内容并回写
|
// 媒体(图像/视频)异步生成轮询:后端先返回「⏳」占位,前端定时拉取该消息最新内容并回写
|
||||||
|
|||||||
Reference in new issue
Block a user