From b8b48bf7ed7502c4023b7d5ac13242fbf0a06e6e Mon Sep 17 00:00:00 2001 From: claude-code-best Date: Tue, 28 Apr 2026 09:15:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20truncate=20?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E6=8E=A5=E6=94=B6=E5=88=B0=20undefined/null?= =?UTF-8?q?=20=E6=97=B6=E5=B4=A9=E6=BA=83=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BackgroundTask 组件渲染时传入的 task 属性(description、title、command 等) 可能为 undefined,导致 str.indexOf('\n') 抛出 TypeError。 Co-Authored-By: Claude Opus 4.7 --- src/utils/truncate.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/truncate.ts b/src/utils/truncate.ts index aff5c72ef..025e19033 100644 --- a/src/utils/truncate.ts +++ b/src/utils/truncate.ts @@ -132,10 +132,11 @@ export function truncateToWidthNoEllipsis( * @returns The truncated string with ellipsis if needed */ export function truncate( - str: string, + str: string | undefined | null, maxWidth: number, singleLine: boolean = false, ): string { + if (str == null) return '' let result = str // If singleLine is true, truncate at first newline