import { Component, ReactNode } from 'react'; interface Props { children: ReactNode; onError?: (error: Error) => void; /** Explicit switch-to-2D action (replaces the old dead `use-2d-fallback` event). */ onUse2D?: () => void; } interface State { hasError: boolean; error: Error | null; } /** * ErrorBoundary для 3D Canvas. * Ловит ошибки Three.js/WebGL и показывает fallback вместо чёрного экрана. */ export default class ThreeErrorBoundary extends Component { constructor(props: Props) { super(props); this.state = { hasError: false, error: null }; } static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: unknown) { console.error('3D Canvas error caught by ErrorBoundary:', error, errorInfo); this.props.onError?.(error); } handleReload = () => { this.setState({ hasError: false, error: null }); window.location.reload(); }; handleUse2D = () => { this.setState({ hasError: false, error: null }); this.props.onUse2D?.(); }; render() { if (this.state.hasError) { return (

3D Scene Failed

3D rendering encountered an error. You can reload or switch to stable 2D fallback.

{import.meta.env.DEV && this.state.error && (
              {this.state.error.message}
            
)}
{this.props.onUse2D && ( )}
); } return this.props.children; } }