From 1ab1495e6280c3c79e76d62727c43f4b6e5d209c Mon Sep 17 00:00:00 2001 From: 134 Date: Mon, 13 Jul 2026 15:55:07 +0800 Subject: [PATCH] fix: dismiss HiCAD loading state reliably --- components/ai-cad/zoo-design-studio-frame.tsx | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/components/ai-cad/zoo-design-studio-frame.tsx b/components/ai-cad/zoo-design-studio-frame.tsx index c22282d5c..1d66629fd 100644 --- a/components/ai-cad/zoo-design-studio-frame.tsx +++ b/components/ai-cad/zoo-design-studio-frame.tsx @@ -1,7 +1,7 @@ "use client"; import { AlertTriangle, RefreshCw } from "lucide-react"; -import { useState } from "react"; +import { useEffect, useRef, useState } from "react"; type ZooDesignStudioFrameProps = { isReady: boolean; @@ -15,6 +15,30 @@ export function ZooDesignStudioFrame({ src, }: ZooDesignStudioFrameProps) { const [loaded, setLoaded] = useState(false); + const iframeRef = useRef(null); + + useEffect(() => { + if (!isReady) { + return; + } + + const iframe = iframeRef.current; + if (!iframe) { + return; + } + + const markLoaded = () => setLoaded(true); + iframe.addEventListener("load", markLoaded); + try { + if (iframe.contentDocument?.readyState === "complete") { + markLoaded(); + } + } catch { + // The regular load event remains the fallback if access is unavailable. + } + + return () => iframe.removeEventListener("load", markLoaded); + }, [isReady, src]); if (!isReady) { return ( @@ -54,6 +78,7 @@ export function ZooDesignStudioFrame({ allow="clipboard-read; clipboard-write; fullscreen; gamepad; pointer-lock; web-share; xr-spatial-tracking" className="h-full w-full border-0" onLoad={() => setLoaded(true)} + ref={iframeRef} referrerPolicy="strict-origin-when-cross-origin" sandbox="allow-downloads allow-forms allow-modals allow-pointer-lock allow-popups allow-presentation allow-same-origin allow-scripts" src={src}