/** * External dependencies */ import { Component, type ReactNode } from 'react'; /** * WordPress dependencies */ import { __ } from '@wordpress/i18n'; import { Button, Flex, Notice } from '@wordpress/components'; interface Props { children: ReactNode; } interface State { hasError: boolean; error?: Error; } export class ErrorBoundaryNext extends Component< Props, State > { constructor( props: Props ) { super( props ); this.state = { hasError: false }; } static getDerivedStateFromError( error: Error ): State { return { hasError: true, error }; } componentDidCatch( error: Error, errorInfo: React.ErrorInfo ) { // Log error for debugging // eslint-disable-next-line no-console console.error( `Error in surface:`, error, errorInfo ); } render() { if ( this.state.hasError ) { return (
{ __( `An error occurred while loading the content.`, 'woocommerce-shipping' ) }
{ process.env.NODE_ENV === 'development' && this.state.error && (
{ __( 'Error Details', 'woocommerce-shipping' ) }
									{ this.state.error.stack }
								
) }
); } return this.props.children; } }