Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defineProps<{
<div class="mk-gray-card-sm">
<h6 class="mb-2">{{ t('execution.details.output') }}</h6>
<div class="break-all">
{{ data.result || '-' }}
{{ data.result == null || data.result === '' ? '-' : data.result }}
</div>
</div>
</DetailContainer>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. == (loose equality) will likely trip linting.
    data.result == null is the idiomatic null/undefined check, but eslint: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.

  2. NaN is still an edge case. NaN used to fall into the '-' branch; now it renders the literal text NaN. If result can be a numeric output, decide explicitly:

    Number.isNaN(data.result) ? '-' : data.result
  3. Type-check mismatch. If result is typed as string only (check the defineProps<{...}> above), comparing against 0/false is dead code, and if it's string | number | boolean, TS/ESLint may complain about the mixed comparison in a template. Make the prop type explicit (string | number | boolean | null | undefined).

  4. 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().

  5. Hard-coded '-' placeholder bypasses i18n. Elsewhere you already use t(...); consider a shared t('common.empty')/EMPTY_VALUE constant so the dash is consistent and localized.

  6. Newlines are collapsed. With break-all only, multi-line command/script output renders as one blob. If result is raw output, whitespace-pre-wrap break-words is usually better than break-all (which also breaks mid-word and hurts readability).

  7. Objects/arrays would render as [object Object] (pre-existing, but worth handling: JSON.stringify or 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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ defineProps<{
<div class="mk-gray-card-sm">
<h6 class="mb-2">{{ t('execution.details.output') }}</h6>
<div class="break-all">
{{ data.result || '-' }}
{{ data.result == null || data.result === '' ? '-' : data.result }}
</div>
</div>
</DetailContainer>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. 0 and false now render differently. The old data.result || '-' treated every falsy value as missing (0, false, NaN, '', null, undefined). The new code only treats null, undefined and '' as missing. That is probably the intent (so 0 shows as 0), but be aware:

    • false will now render "false" instead of -. Decide whether that's wanted.
    • NaN will render "NaN" instead of -. If result is numeric, add a Number.isNaN guard.
    • Non-empty whitespace ' ' still renders as blank rather than - — consider .trim() if that matters.
  2. Objects/arrays will still interpolate as [object Object] / comma-joined values. If result can be non-primitive, this should go through a formatter (e.g. JSON.stringify or toDisplayString).

Style / lint

  1. Loose equality data.result == null is a deliberate null/undefined check, but eslint's eqeqeq rule (often enabled with smart/allow-null in Vue projects) may complain. Prefer explicit data.result === null || data.result === undefined or a helper.

  2. 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
})
  1. Security: interpolation escapes HTML, so no XSS concern — good. Don't be tempted to switch to v-html for this.

Diff hygiene

  1. 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

  1. class="break-all" handles long unbroken strings, but very long multi-line results may still overflow — consider whitespace-pre-wrap if 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.

Expand Down
Loading