fix: dismiss HiCAD loading state reliably
This commit is contained in:
parent
e308142afd
commit
ae76c45e27
@ -1,7 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { AlertTriangle, RefreshCw } from "lucide-react";
|
import { AlertTriangle, RefreshCw } from "lucide-react";
|
||||||
import { useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
|
|
||||||
type ZooDesignStudioFrameProps = {
|
type ZooDesignStudioFrameProps = {
|
||||||
isReady: boolean;
|
isReady: boolean;
|
||||||
@ -15,6 +15,30 @@ export function ZooDesignStudioFrame({
|
|||||||
src,
|
src,
|
||||||
}: ZooDesignStudioFrameProps) {
|
}: ZooDesignStudioFrameProps) {
|
||||||
const [loaded, setLoaded] = useState(false);
|
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) {
|
if (!isReady) {
|
||||||
return (
|
return (
|
||||||
@ -54,6 +78,7 @@ export function ZooDesignStudioFrame({
|
|||||||
allow="clipboard-read; clipboard-write; fullscreen; gamepad; pointer-lock; web-share; xr-spatial-tracking"
|
allow="clipboard-read; clipboard-write; fullscreen; gamepad; pointer-lock; web-share; xr-spatial-tracking"
|
||||||
className="h-full w-full border-0"
|
className="h-full w-full border-0"
|
||||||
onLoad={() => setLoaded(true)}
|
onLoad={() => setLoaded(true)}
|
||||||
|
ref={iframeRef}
|
||||||
referrerPolicy="strict-origin-when-cross-origin"
|
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"
|
sandbox="allow-downloads allow-forms allow-modals allow-pointer-lock allow-popups allow-presentation allow-same-origin allow-scripts"
|
||||||
src={src}
|
src={src}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user