diff --git a/components/chat.tsx b/components/chat.tsx index 05b56a0..d3a03b9 100644 --- a/components/chat.tsx +++ b/components/chat.tsx @@ -303,6 +303,9 @@ export function Chat({ } // 🆕 检测是否包含图片(生成完成) + const messageText = messageData.parts?.[0]?.text || ""; + console.log("[Chat] 📝 Message text preview:", messageText.substring(0, 100)); + const hasImage = messageData.parts?.some( (part: any) => part.type === "text" && part.text && ( part.text.includes("![thumb|") || @@ -310,6 +313,8 @@ export function Chat({ part.text.includes("![Generated Image") ) ); + console.log("[Chat] 🔍 hasImage check:", hasImage); + if (hasImage) { console.log("[Chat] 🎉 Image generated, hiding placeholder"); setIsGeneratingImageFlag(false); @@ -351,6 +356,13 @@ export function Chat({ // 🆕 生成完成,清除持久化状态 completeGeneration(); console.log("[Chat] onFinish called"); + + // 🆕 刷新页面获取最新消息,确保 data-appendMessage 添加的消息不会丢失 + // 延迟执行以确保所有状态更新完成 + setTimeout(() => { + console.log("[Chat] Refreshing to sync messages from database"); + router.refresh(); + }, 500); }, onError: (error) => { if (error instanceof ChatSDKError) {