"use client"; import * as Sentry from "@sentry/nextjs"; import type { ErrorInfo, ReactNode } from "react"; import { Component } from "react"; interface NodeErrorBoundaryProps { children: ReactNode; nodeType: string; } interface NodeErrorBoundaryState { hasError: boolean; errorMessage?: string; } export class NodeErrorBoundary extends Component< NodeErrorBoundaryProps, NodeErrorBoundaryState > { state: NodeErrorBoundaryState = { hasError: false, }; static getDerivedStateFromError(error: Error): NodeErrorBoundaryState { return { hasError: true, errorMessage: error.message, }; } override componentDidCatch(error: Error, errorInfo: ErrorInfo) { Sentry.captureException(error, { tags: { nodeType: this.props.nodeType }, extra: { componentStack: errorInfo.componentStack }, }); console.error("Node rendering error", { nodeType: this.props.nodeType, error, componentStack: errorInfo.componentStack, }); } private handleRetry = () => { this.setState({ hasError: false, errorMessage: undefined }); }; override render() { if (this.state.hasError) { return (

Node render failed ({this.props.nodeType})

{this.state.errorMessage && (

{this.state.errorMessage}

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