fix: 过滤清理后为空的消息,避免显示空对话框
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Your Name 2026-02-01 16:42:23 +08:00
parent 2f667cede8
commit 2a14ae8445

View File

@ -341,13 +341,26 @@ function PureMessages({
if (part.type === "text" && part.text) {
return {
...part,
text: part.text.replace(/\n*<!-- GENERATING_IMAGE -->\n*/g, "")
text: part.text.replace(/\n*<!-- GENERATING_IMAGE -->\n*/g, "").trim()
};
}
return part;
})
};
// 🆕 检查清理后的消息是否有实际内容
// 如果所有 parts 都为空,跳过渲染
const hasContent = cleanedMessage.parts?.some((part: any) => {
if (part.type === "text") return part.text && part.text.trim().length > 0;
if (part.type === "file" || part.type === "image") return part.url;
return true; // 其他类型的 part 默认有内容
});
// 如果没有内容,不渲染这条消息
if (!hasContent && cleanedMessage.parts?.length > 0) {
return null;
}
return (
<PreviewMessage
chatId={chatId}