Skip to content

Commit b61057d

Browse files
committed
feat: implement production-grade React ErrorBoundary component to catch downstream runtime crashes
1 parent 6b44092 commit b61057d

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React, { Component } from "react";
2+
3+
class ErrorBoundary extends Component {
4+
constructor(props) {
5+
super(props);
6+
this.state = { hasError: false, error: null };
7+
}
8+
9+
static getDerivedStateFromError(error) {
10+
// Update state so the next render will show the fallback UI.
11+
return { hasError: true, error };
12+
}
13+
14+
componentDidCatch(error, errorInfo) {
15+
// Route technical crash telemetry directly into the browser console context
16+
console.error("── 💥 CRITICAL INTERFACE RENDERING PANIC ──");
17+
console.error("Exception Vector:", error);
18+
console.error("Component Stack Info:", errorInfo);
19+
}
20+
21+
render() {
22+
if (this.state.hasError) {
23+
return (
24+
<div className="p-6 border border-rose-900/60 rounded-2xl bg-neutral-950 text-neutral-200 w-96 font-mono border-dashed shadow-2xl shadow-rose-950/10">
25+
<div className="flex flex-col gap-3">
26+
<div className="flex items-center gap-2 text-rose-400">
27+
<span className="text-xs">⚠️</span>
28+
<h3 className="text-[10px] font-black uppercase tracking-[0.2em]">
29+
UI Circuit Fault Isolated
30+
</h3>
31+
</div>
32+
<p className="text-[11px] text-neutral-400 leading-relaxed">
33+
A fatal rendering exception occurred within a downstream layout node. The execution layer has been sandboxed to safeguard app runtime states.
34+
</p>
35+
<div className="mt-1 p-3 bg-neutral-900/60 border border-neutral-800/80 rounded text-[9px] text-rose-300/90 overflow-x-auto whitespace-pre-wrap max-h-24 select-all unique-scrollbar">
36+
{this.state.error?.toString() || "Unknown Component Exception"}
37+
</div>
38+
<button
39+
onClick={() => window.location.reload()}
40+
className="mt-2 text-center text-[9px] font-black uppercase tracking-wider py-2 bg-neutral-900 border border-neutral-800 hover:border-neutral-600 transition-all rounded text-neutral-400 hover:text-neutral-200"
41+
>
42+
Force Component Reset
43+
</button>
44+
</div>
45+
</div>
46+
);
47+
}
48+
49+
return this.props.children;
50+
}
51+
}
52+
53+
export default ErrorBoundary;

0 commit comments

Comments
 (0)