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 <roomote@roocode.com>
Co-authored-by: Daniel <57051444+daniel-lxs@users.noreply.github.com>
This commit is contained in:
roomote[bot] 2025-08-21 02:21:41 -07:00 committed by GitHub
parent a5b143bb44
commit b2fdb9ac57
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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 (
<div className="mb-2">
<div
@ -33,9 +38,11 @@ export const ContextCondenseRow = ({ cost, prevContextTokens, newContextTokens,
<span className="codicon codicon-compress text-blue-400" />
<span className="font-bold text-vscode-foreground">{t("chat:contextCondense.title")}</span>
<span className="text-vscode-descriptionForeground text-sm">
{prevContextTokens.toLocaleString()} {newContextTokens.toLocaleString()} {t("tokens")}
{prevTokens.toLocaleString()} {newTokens.toLocaleString()} {t("tokens")}
</span>
<VSCodeBadge className={cost > 0 ? "opacity-100" : "opacity-0"}>${cost.toFixed(2)}</VSCodeBadge>
<VSCodeBadge className={displayCost > 0 ? "opacity-100" : "opacity-0"}>
${displayCost.toFixed(2)}
</VSCodeBadge>
</div>
<span className={`codicon codicon-chevron-${isExpanded ? "up" : "down"}`}></span>
</div>