import { Trans } from "@lingui/react/macro"; import * as React from "react"; interface Props { children: React.ReactNode; /** The underlying field kind to show in the error message */ fieldKind: string; } interface State { hasError: boolean; error?: Error; } /** * Error boundary that wraps trusted plugin field widgets. * On render error, shows a warning with a retry button instead of crashing the editor. */ export class PluginFieldErrorBoundary extends React.Component { constructor(props: Props) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } override render() { if (this.state.hasError) { return (

Plugin widget error

{this.state.error?.message || The plugin field widget failed to render.}

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