DiffWeave / studio /src /components /ErrorBoundary.jsx
shak3008's picture
fix(studio): resolve temporal dead zone ReferenceError in WorkspaceHub and wrap App in ErrorBoundary
aefa338
Raw History Blame Contribute Delete
2.91 kB
import React from 'react';
import { AlertTriangle, RefreshCw, Home } from 'lucide-react';
export default class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false, error: null, errorInfo: null };
}
static getDerivedStateFromError(error) {
return { hasError: true, error };
}
componentDidCatch(error, errorInfo) {
console.error('DiffWeave Caught Runtime Error:', error, errorInfo);
this.setState({ errorInfo });
}
handleReset = () => {
this.setState({ hasError: false, error: null, errorInfo: null });
window.location.href = '/';
};
handleReload = () => {
window.location.reload();
};
render() {
if (this.state.hasError) {
return (
<div className="min-h-screen bg-[#080B11] text-slate-100 flex items-center justify-center p-6">
<div className="max-w-lg w-full bg-[#0D1117] border border-rose-500/30 rounded-2xl p-8 shadow-2xl space-y-6 text-center">
<div className="w-16 h-16 rounded-2xl bg-rose-500/10 border border-rose-500/20 text-rose-400 flex items-center justify-center mx-auto shadow-lg shadow-rose-500/10">
<AlertTriangle className="w-8 h-8" />
</div>
<div className="space-y-2">
<h2 className="text-xl font-bold text-white tracking-tight">Something went wrong</h2>
<p className="text-xs text-slate-400">
DiffWeave encountered an unexpected client error. Don't worry, your workspace data and documents are safely stored.
</p>
</div>
{this.state.error && (
<div className="p-3.5 rounded-xl bg-black/60 border border-[#30363D] text-left overflow-auto max-h-40">
<p className="font-mono text-xs text-rose-400 font-semibold break-words">
{this.state.error.toString()}
</p>
</div>
)}
<div className="flex items-center justify-center space-x-3 pt-2">
<button
onClick={this.handleReload}
className="px-4 py-2.5 rounded-xl bg-[#21262D] hover:bg-[#30363D] border border-[#30363D] text-slate-200 text-xs font-semibold flex items-center space-x-2 transition"
>
<RefreshCw className="w-3.5 h-3.5" />
<span>Reload Page</span>
</button>
<button
onClick={this.handleReset}
className="px-4 py-2.5 rounded-xl bg-emerald-600 hover:bg-emerald-500 text-white text-xs font-bold flex items-center space-x-2 transition shadow-lg shadow-emerald-600/20"
>
<Home className="w-3.5 h-3.5" />
<span>Return to Hub</span>
</button>
</div>
</div>
</div>
);
}
return this.props.children;
}
}