Skip to content

Commit 1fc6c65

Browse files
Fix v2
1 parent b7a6b4f commit 1fc6c65

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

src/ErrorBoundary.jsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from 'react';
2+
3+
class ErrorBoundary extends React.Component {
4+
constructor(props) {
5+
super(props);
6+
this.state = { hasError: false, error: null, errorInfo: null };
7+
}
8+
9+
static getDerivedStateFromError(error) {
10+
return { hasError: true };
11+
}
12+
13+
componentDidCatch(error, errorInfo) {
14+
console.error("Uncaught error:", error, errorInfo);
15+
this.setState({ error, errorInfo });
16+
}
17+
18+
render() {
19+
if (this.state.hasError) {
20+
return (
21+
<div style={{ padding: '2rem', color: '#ef4444', backgroundColor: '#1a1a1a', minHeight: '100vh', fontFamily: 'monospace' }}>
22+
<h1>Something went wrong.</h1>
23+
<details style={{ whiteSpace: 'pre-wrap' }}>
24+
{this.state.error && this.state.error.toString()}
25+
<br />
26+
{this.state.errorInfo && this.state.errorInfo.componentStack}
27+
</details>
28+
</div>
29+
);
30+
}
31+
32+
return this.props.children;
33+
}
34+
}
35+
36+
export default ErrorBoundary;

src/main.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ import ReactDOM from 'react-dom/client'
33
import App from './App.jsx'
44
import './index.css'
55

6+
import ErrorBoundary from './ErrorBoundary'
7+
68
ReactDOM.createRoot(document.getElementById('root')).render(
79
<React.StrictMode>
8-
<App />
10+
<ErrorBoundary>
11+
<App />
12+
</ErrorBoundary>
913
</React.StrictMode>,
1014
)

vite.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import react from '@vitejs/plugin-react'
44
// https://vitejs.dev/config/
55
export default defineConfig({
66
plugins: [react()],
7-
base: '/Prompt-Generator/',
7+
base: './',
88
build: {
99
outDir: 'dist',
1010
sourcemap: false,

0 commit comments

Comments
 (0)