From 19f9de4523c7585a2541fa8e6bcf15447ce820ee Mon Sep 17 00:00:00 2001 From: Marco Fugaro Date: Thu, 20 Jun 2024 15:42:33 +0200 Subject: [PATCH] Correctly throw Spline errors --- src/Spline.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Spline.tsx b/src/Spline.tsx index 9f3f002..05e1d8c 100644 --- a/src/Spline.tsx +++ b/src/Spline.tsx @@ -58,6 +58,12 @@ const Spline = forwardRef( ) => { const canvasRef = useRef(null); const [isLoading, setIsLoading] = useState(true); + const [error, setError] = useState(); + + // We throw the error so ErrorBoundary can catch it + if (error) { + throw error; + } // Initialize runtime when component is mounted useEffect(() => { @@ -122,7 +128,9 @@ const Spline = forwardRef( onLoad?.(speApp); } - init(); + init().catch((err) => { + setError(err as Error); + }); } return () => {