feat: 尝试改进 Error 处理以提升内存管理效率

This commit is contained in:
claude-code-best
2026-05-05 18:18:13 +08:00
parent d0915fc880
commit 18d6656a6a
4 changed files with 81 additions and 15 deletions

View File

@@ -131,8 +131,13 @@ type Props = {
const MULTI_CLICK_TIMEOUT_MS = 500;
const MULTI_CLICK_DISTANCE = 1;
type ErrorInfo = {
readonly message: string;
readonly stack?: string;
};
type State = {
readonly error?: Error;
readonly error?: ErrorInfo;
};
// Root component for all Ink apps
@@ -142,7 +147,7 @@ export default class App extends PureComponent<Props, State> {
static displayName = 'InternalApp';
static getDerivedStateFromError(error: Error) {
return { error };
return { error: { message: error.message, stack: error.stack } };
}
override state = {
@@ -221,7 +226,7 @@ export default class App extends PureComponent<Props, State> {
<TerminalFocusProvider>
<ClockProvider>
<CursorDeclarationContext.Provider value={this.props.onCursorDeclaration ?? (() => {})}>
{this.state.error ? <ErrorOverview error={this.state.error as Error} /> : this.props.children}
{this.state.error ? <ErrorOverview error={this.state.error} /> : this.props.children}
</CursorDeclarationContext.Provider>
</ClockProvider>
</TerminalFocusProvider>

View File

@@ -23,8 +23,13 @@ function getStackUtils(): StackUtils {
/* eslint-enable custom-rules/no-process-cwd */
type ErrorLike = {
readonly message: string;
readonly stack?: string;
};
type Props = {
readonly error: Error;
readonly error: ErrorLike;
};
export default function ErrorOverview({ error }: Props) {