diff --git a/src/components/ErrorBoundary.js b/src/components/ErrorBoundary.js index c8e72484..503c8730 100755 --- a/src/components/ErrorBoundary.js +++ b/src/components/ErrorBoundary.js @@ -1,14 +1,14 @@ import React from 'react'; -import { - Box, - Alert, - AlertIcon, - AlertTitle, - AlertDescription, - Button, - VStack, - Container -} from '@chakra-ui/react'; +// import { +// Box, +// Alert, +// AlertIcon, +// AlertTitle, +// AlertDescription, +// Button, +// VStack, +// Container +// } from '@chakra-ui/react'; import { logger } from '../utils/logger'; class ErrorBoundary extends React.Component { @@ -40,66 +40,68 @@ class ErrorBoundary extends React.Component { } render() { - // 如果有错误,显示错误边界(所有环境) - if (this.state.hasError) { - return ( - - - - - - - 页面出现错误! - - - {process.env.NODE_ENV === 'development' - ? '组件渲染时发生错误,请查看下方详情和控制台日志。' - : '页面加载时发生了未预期的错误,请尝试刷新页面。'} - - - + // 静默模式:捕获错误并记录日志(已在 componentDidCatch 中完成) + // 但继续渲染子组件,不显示错误页面 + // 注意:如果组件因错误无法渲染,该区域可能显示为空白 + // // 如果有错误,显示错误边界(所有环境) + // if (this.state.hasError) { + // return ( + // + // + // + // + // + // + // 页面出现错误! + // + // + // {process.env.NODE_ENV === 'development' + // ? '组件渲染时发生错误,请查看下方详情和控制台日志。' + // : '页面加载时发生了未预期的错误,请尝试刷新页面。'} + // + // + // - {/* 开发环境显示详细错误信息 */} - {process.env.NODE_ENV === 'development' && this.state.error && ( - - 错误详情: - - {this.state.error.name}: {this.state.error.message} - {this.state.error.stack && ( - {this.state.error.stack} - )} - {this.state.errorInfo && this.state.errorInfo.componentStack && ( - <> - 组件堆栈: - {this.state.errorInfo.componentStack} - - )} - - - )} - - - - - ); - } + // {/* 开发环境显示详细错误信息 */} + // {process.env.NODE_ENV === 'development' && this.state.error && ( + // + // 错误详情: + // + // {this.state.error.name}: {this.state.error.message} + // {this.state.error.stack && ( + // {this.state.error.stack} + // )} + // {this.state.errorInfo && this.state.errorInfo.componentStack && ( + // <> + // 组件堆栈: + // {this.state.errorInfo.componentStack} + // + // )} + // + // + // )} + // + // + // + // ); + // } return this.props.children; } }