Repository navigation
fix: preserve zero and false in tool execution results - #8220
Conversation
| {{ data.result == null || data.result === '' ? '-' : data.result }} | ||
| </div> | ||
| </div> | ||
| </DetailContainer> |
There was a problem hiding this comment.
What the change does
{{ data.result || '-' }} → {{ data.result == null || data.result === '' ? '-' : data.result }}
Good: it fixes the main bug of the original line. The || operator treated every falsy value as empty, so a legitimate result of 0 or false was silently replaced with -. The new version correctly shows 0 and false.
Potential issues
-
==(loose equality) will likely trip linting.
data.result == nullis the idiomatic null/undefined check, buteslint:eqeqeq(often enabled in Vue/TS projects) will flag it. Safer/clearer:data.result === null || data.result === undefined || data.result === ''
or keep
??for the null part. -
NaNis still an edge case.NaNused to fall into the'-'branch; now it renders the literal textNaN. Ifresultcan be a numeric output, decide explicitly:Number.isNaN(data.result) ? '-' : data.result
-
Type-check mismatch. If
resultis typed asstringonly (check thedefineProps<{...}>above), comparing against0/falseis dead code, and if it'sstring | number | boolean, TS/ESLint may complain about the mixed comparison in a template. Make the prop type explicit (string | number | boolean | null | undefined). -
Whitespace-only strings (
' ','\n') are not caught and will render as blank space — arguably fine, but if the intent is "empty →-", consider!data.result.toString().trim(). -
Hard-coded
'-'placeholder bypasses i18n. Elsewhere you already uset(...); consider a sharedt('common.empty')/EMPTY_VALUEconstant so the dash is consistent and localized. -
Newlines are collapsed. With
break-allonly, multi-line command/script output renders as one blob. Ifresultis raw output,whitespace-pre-wrap break-wordsis usually better thanbreak-all(which also breaks mid-word and hurts readability). -
Objects/arrays would render as
[object Object](pre-existing, but worth handling:JSON.stringifyor a guarded format).
Optimization suggestions
-
Move the logic out of the template into a
computed, which is easier to test, lint, and reuse:const displayResult = computed(() => { const r = props.data.result if (r === null || r === undefined || r === '') return EMPTY_VALUE if (typeof r === 'number' && Number.isNaN(r)) return EMPTY_VALUE return r })
<div class="whitespace-pre-wrap break-words">{{ displayResult }}</div>
-
If this "empty → dash" pattern appears in several components, extract a small
formatResult(value)util or a global filter rather than repeating the ternary. -
Add a unit test covering
0,false,'',null,undefined,NaN, and a normal string — that's exactly the regression the old code had.
Verdict: the change is a genuine bug fix and safe to ship; just address the eqeqeq lint concern, decide on NaN/whitespace handling, and consider hoisting the expression into a computed property.
| {{ data.result == null || data.result === '' ? '-' : data.result }} | ||
| </div> | ||
| </div> | ||
| </DetailContainer> |
There was a problem hiding this comment.
Review of the change
The change itself is fine (and arguably a bug fix), but there are a few things worth flagging.
Correctness / behaviour changes
-
0andfalsenow render differently. The olddata.result || '-'treated every falsy value as missing (0,false,NaN,'',null,undefined). The new code only treatsnull,undefinedand''as missing. That is probably the intent (so0shows as0), but be aware:falsewill now render"false"instead of-. Decide whether that's wanted.NaNwill render"NaN"instead of-. Ifresultis numeric, add aNumber.isNaNguard.- Non-empty whitespace
' 'still renders as blank rather than-— consider.trim()if that matters.
-
Objects/arrays will still interpolate as
[object Object]/ comma-joined values. Ifresultcan be non-primitive, this should go through a formatter (e.g.JSON.stringifyortoDisplayString).
Style / lint
-
Loose equality
data.result == nullis a deliberate null/undefined check, buteslint'seqeqeqrule (often enabled withsmart/allow-nullin Vue projects) may complain. Prefer explicitdata.result === null || data.result === undefinedor a helper. -
Inline template logic is getting long. Extracting it improves readability and testability:
// composable or util
export const displayValue = (v: unknown, fallback = '-') =>
v === null || v === undefined || v === '' ? fallback : v<div class="break-all">{{ displayValue(data.result) }}</div>@@ or a local computed @@
const resultText = computed(() => {
const v = props.data.result
return v === null || v === undefined || v === '' ? '-' : v
})- Security: interpolation escapes HTML, so no XSS concern — good. Don't be tempted to switch to
v-htmlfor this.
Diff hygiene
- The hunk header context (
defineProps<{) doesn't match the actual changed line (it's in the<template>). Probably just a truncated diff, but verify the hunk headers are correct if this is being applied as a patch.
Minor
class="break-all"handles long unbroken strings, but very long multi-line results may still overflow — considerwhitespace-pre-wrapif line breaks in the value should be preserved.
Bottom line: the fix is reasonable; just make the "missing value" policy explicit (what about false, NaN, whitespace, objects?) and extract the expression to a computed/utility for readability.
fix: preserve zero and false in tool execution results