import { Component, ErrorInfo, ReactNode } from 'react'; import { ErrorFallback } from '@/components/ErrorFallback'; interface ErrorBoundaryState { hasError: boolean; error: Error | null; errorInfo: ErrorInfo | null; } interface ErrorBoundaryProps { children: ReactNode; fallback?: ReactNode; } export class ErrorBoundary extends Component { constructor(props: ErrorBoundaryProps) { super(props); this.state = { hasError: false, error: null, errorInfo: null, }; } static getDerivedStateFromError(error: Error): Partial { return { hasError: true, error, }; } componentDidCatch(error: Error, errorInfo: ErrorInfo) { // Full detail (message + component stack) goes to the console for us; it is // deliberately NOT surfaced to users — stack traces can leak internal // structure and are meaningless noise to a skater. console.error('Error caught by ErrorBoundary:', error, errorInfo); this.setState({ error, errorInfo, }); } handleReset = () => { this.setState({ hasError: false, error: null, errorInfo: null, }); }; render() { if (this.state.hasError) { if (this.props.fallback) { return this.props.fallback; } return ( window.location.reload()} /> ); } return this.props.children; } }