Skip to content

Commit 3de8f91

Browse files
authored
Correctly throw Spline errors (#193)
1 parent ff77f56 commit 3de8f91

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Spline.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ const Spline = forwardRef<HTMLDivElement, SplineProps>(
4949
) => {
5050
const canvasRef = useRef<HTMLCanvasElement>(null);
5151
const [isLoading, setIsLoading] = useState(true);
52+
const [error, setError] = useState<Error>();
53+
54+
// We throw the error so ErrorBoundary can catch it
55+
if (error) {
56+
throw error;
57+
}
5258

5359
// Initialize runtime when component is mounted
5460
useEffect(() => {
@@ -113,7 +119,9 @@ const Spline = forwardRef<HTMLDivElement, SplineProps>(
113119
onLoad?.(speApp);
114120
}
115121

116-
init();
122+
init().catch((err) => {
123+
setError(err as Error);
124+
});
117125
}
118126

119127
return () => {

0 commit comments

Comments
 (0)