From b2fdb9ac5758293fcc06af31dc2ee1555c9171d8 Mon Sep 17 00:00:00 2001 From: "roomote[bot]" <219738659+roomote[bot]@users.noreply.github.com> Date: Thu, 21 Aug 2025 02:21:41 -0700 Subject: [PATCH] fix: handle null/undefined token values in ContextCondenseRow to prevent UI crash (#6916) * fix: handle null/undefined token values in ContextCondenseRow to prevent UI crash - Added null/undefined checks for prevContextTokens, newContextTokens, and cost - Default to 0 when values are null or undefined - Added comprehensive test coverage for edge cases - Fixes #6914 * Delete webview-ui/src/components/chat/__tests__/ContextCondenseRow.spec.tsx --------- Co-authored-by: Roo Code Co-authored-by: Daniel <57051444+daniel-lxs@users.noreply.github.com> --- webview-ui/src/components/chat/ContextCondenseRow.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/webview-ui/src/components/chat/ContextCondenseRow.tsx b/webview-ui/src/components/chat/ContextCondenseRow.tsx index 9664b03e00..c2fdba802d 100644 --- a/webview-ui/src/components/chat/ContextCondenseRow.tsx +++ b/webview-ui/src/components/chat/ContextCondenseRow.tsx @@ -11,6 +11,11 @@ export const ContextCondenseRow = ({ cost, prevContextTokens, newContextTokens, const { t } = useTranslation() const [isExpanded, setIsExpanded] = useState(false) + // Handle null/undefined token values to prevent crashes + const prevTokens = prevContextTokens ?? 0 + const newTokens = newContextTokens ?? 0 + const displayCost = cost ?? 0 + return (
{t("chat:contextCondense.title")} - {prevContextTokens.toLocaleString()} → {newContextTokens.toLocaleString()} {t("tokens")} + {prevTokens.toLocaleString()} → {newTokens.toLocaleString()} {t("tokens")} - 0 ? "opacity-100" : "opacity-0"}>${cost.toFixed(2)} + 0 ? "opacity-100" : "opacity-0"}> + ${displayCost.toFixed(2)} +