fix: dismiss HiCAD loading state reliably
This commit is contained in:
parent
da5c0699dd
commit
1ab1495e62
@ -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<HTMLIFrameElement>(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}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user