fix: 添加 React Error Boundary 防止生产环境渲染崩溃

增强 SentryErrorBoundary 组件,捕获渲染错误时输出诊断信息
(错误消息 + component stack)到 stderr 和终端,而非静默返回
null。在 replLauncher 根节点和 Messages 组件层级包裹 Error
Boundary,防止 Ink 内部的 Error Boundary 直接终止进程。

Co-Authored-By: glm-5-turbo <zai-org@claude-code-best.win>
This commit is contained in:
claude-code-best
2026-05-09 22:02:04 +08:00
parent 0707284939
commit 2006ab25ff
4 changed files with 71 additions and 43 deletions

View File

@@ -1,5 +1,6 @@
import { feature } from 'bun:bundle';
import chalk from 'chalk';
import { SentryErrorBoundary } from './SentryErrorBoundary.js';
import type { UUID } from 'crypto';
import type { RefObject } from 'react';
import * as React from 'react';
@@ -890,7 +891,7 @@ const MessagesImpl = ({
);
return (
<>
<SentryErrorBoundary name="MessagesBoundary">
{/* Logo */}
{!hideLogo && !(renderRange && renderRange[0] > 0) && <LogoHeader agentDefinitions={agentDefinitions} />}
@@ -977,7 +978,7 @@ const MessagesImpl = ({
/>
</Box>
)}
</>
</SentryErrorBoundary>
);
};