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:48:40 +08:00
parent 2a14ae8445
commit 96e4c8ebe0

View File

@ -675,7 +675,34 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF
</div>
)}
{messages.map((message) => (
{messages.map((message) => {
// 🆕 清理消息中的内部标记并检查是否有实际内容
const cleanedParts = message.parts?.map((part: any) => {
if (part.type === 'text' && part.text) {
return {
...part,
text: part.text.replace(/\n*<!-- GENERATING_IMAGE -->\n*/g, '').trim()
};
}
return part;
});
// 检查清理后是否有内容
const hasContent = cleanedParts?.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;
});
// 没有内容则不渲染
if (!hasContent && cleanedParts?.length > 0) {
return null;
}
// 使用清理后的消息
const cleanedMessage = { ...message, parts: cleanedParts };
return (
<div
key={message.id}
className={cn(
@ -731,7 +758,7 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF
{/* 消息内容 */}
<div className="whitespace-pre-wrap break-words leading-relaxed">
{message.parts?.map((part: any, i: number) => {
{cleanedMessage.parts?.map((part: any, i: number) => {
if (part.type === 'text') {
// 提取并显示图片
const imageUrls = extractImageUrls(part.text || '');
@ -766,7 +793,8 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF
</div>
</div>
</div>
))}
);
})}
{isLoading && (
<div className="flex gap-3">