import React from 'react'
import { createRoot } from 'react-dom/client'
import App from './App'
import { I18nProvider } from './i18n'
import './index.css'
class ErrorBoundary extends React.Component<
{ children: React.ReactNode },
{ error: Error | null; info: string }
> {
state = { error: null as Error | null, info: '' }
static getDerivedStateFromError(error: Error) {
return { error }
}
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
console.error('[ErrorBoundary] React crashed:', error, errorInfo)
this.setState({ info: errorInfo.componentStack ?? '' })
}
render() {
if (this.state.error) {
return (
UI Error — React crashed
{this.state.error.message}
Stack trace
{this.state.error.stack}
{this.state.info && (
Component stack
{this.state.info}
)}
)
}
return this.props.children
}
}
// Global error handler for uncaught JS errors
window.addEventListener('error', (e) => {
console.error('[Global] Uncaught error:', e.error ?? e.message)
})
window.addEventListener('unhandledrejection', (e) => {
console.error('[Global] Unhandled promise rejection:', e.reason)
})
const root = document.getElementById('root')
if (!root) {
document.body.innerHTML = 'Root element not found
'
throw new Error('Root element #root not found')
}
try {
createRoot(root).render(
)
} catch (err) {
console.error('React render error:', err)
root.innerHTML = `React Error: ${err}
`
}