import React from 'react' // ponytail: 无此 boundary 时,任意渲染异常都会让整个 React 树卸载成空白面板 // (用户报告"用着用着突然啥都没了")。捕获后显示错误+重载按钮,免得只能整窗重载。 interface BoundaryState { error: Error | null } export class ErrorBoundary extends React.Component<{ children: React.ReactNode }, BoundaryState> { state: BoundaryState = { error: null } static getDerivedStateFromError(error: Error): BoundaryState { return { error } } componentDidCatch(error: Error, info: React.ErrorInfo): void { console.error('[superpowers webview] render crash:', error, info.componentStack) } render(): React.ReactNode { const { error } = this.state if (!error) return this.props.children return (
{error.message}
{error.stack ? `\n\n${error.stack}` : ''}