import { Component } from "react" import type { ReactNode, ErrorInfo } from "react" interface ErrorBoundaryState { hasError: boolean error: Error | null } interface ErrorBoundaryProps { children: ReactNode /** Optional custom fallback UI. Receives the caught error. */ fallback?: (error: Error) => ReactNode } /** * Catches render errors in the subtree and shows a fallback UI. * * React error boundaries must be class components — getDerivedStateFromError * and componentDidCatch have no hook equivalents. * * Place this in App.tsx around your tab layout, or wrap individual tabs for * finer-grained recovery. * * @example *

Tab failed: {err.message}

}> * *
*/ export class ErrorBoundary extends Component { constructor(props: ErrorBoundaryProps) { super(props) this.state = { hasError: false, error: null } } static getDerivedStateFromError(error: Error): ErrorBoundaryState { return { hasError: true, error } } componentDidCatch(error: Error, info: ErrorInfo): void { // Replace with your error reporting service (e.g. Sentry, Datadog) console.error("[MFE ErrorBoundary]", error, info.componentStack) } render(): ReactNode { if (this.state.hasError && this.state.error) { if (this.props.fallback) { return this.props.fallback(this.state.error) } return (
Something went wrong loading this view.
) } return this.props.children } }