File size: 1,755 Bytes
3c665d2
 
 
 
 
 
 
 
 
 
 
 
 
 
ce1c471
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3c665d2
ce1c471
3c665d2
ce1c471
3c665d2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App'
import './index.css'

// Restore persisted theme
try {
  const saved = localStorage.getItem('theme') as 'dark' | 'light' | null
  if (saved) document.documentElement.setAttribute('data-theme', saved)
  else document.documentElement.setAttribute('data-theme', 'dark')
} catch {
  document.documentElement.setAttribute('data-theme', 'dark')
}

class ErrorBoundary extends React.Component<
  { children: React.ReactNode },
  { error: Error | null }
> {
  constructor(props: { children: React.ReactNode }) {
    super(props)
    this.state = { error: null }
  }
  static getDerivedStateFromError(error: Error) {
    return { error }
  }
  render() {
    if (this.state.error) {
      return (
        <div style={{
          height: '100vh', display: 'flex', alignItems: 'center', justifyContent: 'center',
          background: '#08080d', color: '#fff', flexDirection: 'column', gap: 16, padding: 32,
          fontFamily: 'monospace'
        }}>
          <div style={{ fontSize: 14, color: '#ef4444', marginBottom: 8 }}>Runtime error</div>
          <pre style={{ fontSize: 11, color: '#9ca3af', maxWidth: 600, overflow: 'auto' }}>
            {this.state.error.message}
          </pre>
          <button
            onClick={() => window.location.reload()}
            style={{ marginTop: 8, padding: '8px 16px', background: '#8b5cf6', border: 'none',
              color: '#fff', borderRadius: 8, cursor: 'pointer', fontSize: 12 }}
          >
            Reload
          </button>
        </div>
      )
    }
    return this.props.children
  }
}

ReactDOM.createRoot(document.getElementById('root')!).render(
  <ErrorBoundary>
    <App />
  </ErrorBoundary>
)