Files
healer-man/src/ui/SceneErrorBoundary.tsx
T
2026-08-14 15:56:39 -04:00

31 lines
1019 B
TypeScript

import { Component, type ErrorInfo, type ReactNode } from "react";
import { useGameStore } from "../game/store";
interface Props { children: ReactNode }
interface State { error: Error | null }
export class SceneErrorBoundary extends Component<Props, State> {
state: State = { error: null };
static getDerivedStateFromError(error: Error): State {
return { error };
}
componentDidCatch(error: Error, info: ErrorInfo) {
console.error("Healer Man scene failed", error, info.componentStack);
useGameStore.getState().setAssetStatus("error", error.message);
}
render() {
if (!this.state.error) return this.props.children;
return (
<div className="scene-error" role="alert">
<p className="eyebrow">Dungeon load interrupted</p>
<h1>The cavern could not be assembled.</h1>
<p>{this.state.error.message}</p>
<button type="button" className="button button--primary" onClick={() => window.location.reload()}>Retry loading</button>
</div>
);
}
}