import React from 'react'; interface Props { children: React.ReactNode; /** When this value changes (e.g. the route path), a caught error is cleared * so client-side navigation recovers without a full page reload. */ resetKey?: unknown; } interface State { hasError: boolean; error: Error | null; } export class ErrorBoundary extends React.Component { constructor(props: Props) { super(props); this.state = { hasError: false, error: null }; } static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } componentDidCatch(error: Error, info: React.ErrorInfo) { console.error('[AgentLens] Page error:', error, info.componentStack); } componentDidUpdate(prevProps: Props) { // Recover on navigation: a transient render error on one route used to wedge // the whole SPA until a hard refresh, because the boundary never reset. if (this.state.hasError && prevProps.resetKey !== this.props.resetKey) { this.setState({ hasError: false, error: null }); } } render() { if (this.state.hasError) { return (
💥

Something went wrong

{this.state.error?.message ?? 'An unexpected error occurred while rendering this page.'}

); } return this.props.children; } }