diff --git a/src/components/ErrorBoundary.tsx b/src/components/ErrorBoundary.tsx index 4649f24..0b4c729 100644 --- a/src/components/ErrorBoundary.tsx +++ b/src/components/ErrorBoundary.tsx @@ -12,21 +12,26 @@ interface Props { onError?: (error: Error, info: ErrorInfo) => void; /** Render fallback content as an in-page scoped panel instead of a full-page state. */ isolate?: boolean; + /** Optional support URL shown in the default fallback. */ + supportUrl?: string; } interface State { error: Error | null; resetKey: number; + componentStack: string | null; } export class ErrorBoundary extends Component { - state: State = { error: null, resetKey: 0 }; + state: State = { error: null, resetKey: 0, componentStack: null }; static getDerivedStateFromError(error: Error): Partial { return { error }; } componentDidCatch(error: Error, info: ErrorInfo) { + this.setState({ error, componentStack: info.componentStack ?? null }); + if (this.props.onError) { this.props.onError(error, info); return; @@ -44,8 +49,8 @@ export class ErrorBoundary extends Component { })); render() { - const { error, resetKey } = this.state; - const { children, fallback, isolate } = this.props; + const { error, resetKey, componentStack } = this.state; + const { children, fallback, isolate, supportUrl } = this.props; if (!error) return
{children}
; @@ -101,6 +106,26 @@ export class ErrorBoundary extends Component { : "Details are hidden in production."}

+ {supportUrl && ( + + Report this issue + + )} + {import.meta.env.DEV && componentStack && ( +
+ + Show component stack + +
+                {componentStack}
+              
+
+ )}