import { Component, type ErrorInfo, type ReactNode } from "react"; import { trackStudioEvent } from "../utils/studioTelemetry"; interface Props { children: ReactNode; } interface State { error: Error | null; } export class StudioErrorBoundary extends Component { state: State = { error: null }; static getDerivedStateFromError(error: Error): State { return { error }; } componentDidCatch(error: Error, info: ErrorInfo) { console.error("[Studio] Uncaught error:", error, info.componentStack); trackStudioEvent("crash", { error_message: error.message, error_name: error.name, stack_trace: error.stack?.slice(0, 4000) ?? null, component_stack: info.componentStack?.slice(0, 2000) ?? null, }); } render() { if (!this.state.error) return this.props.children; return (
Something went wrong
{this.state.error.message}
); } }