From 13c45916b742909f317020a18f38db3db47ba4a1 Mon Sep 17 00:00:00 2001 From: Gemini AI Date: Sun, 28 Dec 2025 12:07:52 +0400 Subject: [PATCH] fix: LiveCanvas now always renders when user toggles to Preview mode --- components/AIAssist.tsx | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/components/AIAssist.tsx b/components/AIAssist.tsx index b5e80be..2427a47 100644 --- a/components/AIAssist.tsx +++ b/components/AIAssist.tsx @@ -38,11 +38,10 @@ const LiveCanvas = memo(({ data, type, isStreaming }: { data: string, type: stri const iframeRef = useRef(null); useEffect(() => { - if (!iframeRef.current) return; + if (!iframeRef.current || !data) return; - const isHtml = data.includes("<") && data.includes(">"); + // Decode HTML entities if present const isEncodedHtml = data.includes("<") && data.includes(">"); - const shouldRender = isHtml || isEncodedHtml || ["web", "app", "design", "html", "ui"].includes(type); const normalized = isEncodedHtml ? data .replace(/</g, "<") @@ -51,8 +50,20 @@ const LiveCanvas = memo(({ data, type, isStreaming }: { data: string, type: stri .replace(/"/g, "\"") .replace(/'/g, "'") : data; - if (shouldRender) { - const doc = ` + + // Check if the content is a full HTML document or a fragment + const isFullDocument = normalized.trim().startsWith("/i, ` + + + `); + } else { + // Wrap fragments in a styled container + doc = ` @@ -81,19 +92,20 @@ const LiveCanvas = memo(({ data, type, isStreaming }: { data: string, type: stri margin: 0; padding: 24px; font-family: "Space Grotesk", "IBM Plex Sans", system-ui, sans-serif; - background: #0b1414; - color: #ecfdf3; + background: #f8fafc; + color: #1e293b; min-height: 100vh; } - + ${normalized} `; - iframeRef.current.srcdoc = doc; } + + iframeRef.current.srcdoc = doc; }, [data, type]); return ( @@ -624,7 +636,7 @@ export default function AIAssist() {
- {viewMode === "preview" && previewData && canRenderPreview ? ( + {viewMode === "preview" && previewData ? (