-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.tsx
More file actions
56 lines (47 loc) · 1.47 KB
/
index.tsx
File metadata and controls
56 lines (47 loc) · 1.47 KB
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
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
console.log('[DEBUG] index.tsx is running');
class ErrorBoundary extends React.Component<{children: React.ReactNode}, {hasError: boolean, error: any}> {
constructor(props: any) {
super(props);
this.state = { hasError: false, error: null };
}
static getDerivedStateFromError(error: any) {
return { hasError: true, error };
}
componentDidCatch(error: any, errorInfo: any) {
console.error("ErrorBoundary caught an error", error, errorInfo);
}
render() {
if (this.state.hasError) {
return (
<div style={{color: 'red', padding: '20px', background: 'white', zIndex: 9999, position: 'relative'}}>
<h1>Something went wrong.</h1>
<pre>{this.state.error?.toString()}</pre>
<pre>{this.state.error?.stack}</pre>
</div>
);
}
return this.props.children;
}
}
const rootElement = document.getElementById('root');
if (!rootElement) {
console.error('[DEBUG] Could not find root element to mount to');
throw new Error("Could not find root element to mount to");
}
console.log('[DEBUG] Root element found', rootElement);
try {
const root = ReactDOM.createRoot(rootElement);
root.render(
<React.StrictMode>
<ErrorBoundary>
<App />
</ErrorBoundary>
</React.StrictMode>
);
console.log('[DEBUG] React root rendered');
} catch (e) {
console.error('[DEBUG] React render failed', e);
}