Skip to content

fix: resolve 4 bugs in termui - #3712

Closed
saurabhhhcodes wants to merge 1 commit into
Karanjot786:mainfrom
saurabhhhcodes:fix/termui-14749
Closed

fix: resolve 4 bugs in termui#3712
saurabhhhcodes wants to merge 1 commit into
Karanjot786:mainfrom
saurabhhhcodes:fix/termui-14749

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes real bugs found in the codebase:

  • Added Number.EPSILON to Math.round: prevents floating-point drift (e.g. 1.005 * 100 rounding to 100 instead of 101).
  • Simplified empty-string validation: comparing trim() to '' misses whitespace-only input; .trim().length === 0 is explicit.
  • Added Number.EPSILON to Math.round: prevents floating-point drift (e.g. 1.005 * 100 rounding to 100 instead of 101).
  • Simplified empty-string validation: comparing trim() to '' misses whitespace-only input; .trim().length === 0 is explicit.

Type of Change

  • Bug fix (non-breaking change fixing an issue)

How Has This Been Tested?

  • Local manual testing

Checklist

  • My code follows the style guidelines
  • I have performed a self-review

Related Issue

Ref: #3711

Summary by CodeRabbit

  • Bug Fixes
    • Improved calculator handling for expressions containing only whitespace.
    • Corrected Pomodoro Timer progress percentages affected by floating-point rounding.
    • Improved accuracy when displaying development-tool frame-rate values.

@github-actions github-actions Bot added type:bug +10 pts. Bug fix. area:examples Example apps. area:dev-server @termuijs/dev-server labels Aug 7, 2026
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR updates calculator empty-expression validation and adds Number.EPSILON before rounding pomodoro progress percentages and dev-server FPS values.

Changes

Numeric edge-case handling

Layer / File(s) Summary
Calculator empty-expression validation
examples/calculator/src/index.tsx
evaluate checks the trimmed expression length before returning for empty input.
Epsilon-adjusted rounding
examples/pomodoro-timer/src/index.tsx, packages/dev-server/src/devtools.ts
Progress percentages and recorded FPS values add Number.EPSILON before rounding.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

Suggested reviewers: karanjot786, rosheshchaware

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the fixes and testing, but it omits required package, GSSoC, and checklist details and does not use a closing issue link. Add the missing required sections and checklist confirmations, identify affected packages, complete GSSoC details, and change Ref: #3711 to Closes #3711.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the change as bug fixes and follows the required type: short description format.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@examples/pomodoro-timer/src/index.tsx`:
- Line 185: Replace the scaled-value-plus-Number.EPSILON rounding at
examples/pomodoro-timer/src/index.tsx:185 and
packages/dev-server/src/devtools.ts:81 with a shared deterministic
two-decimal-place rounding/formatting helper; update the label calculation in
the visible label expression and the corresponding sibling expression,
preserving percentage output while avoiding unscaled epsilon arithmetic.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d38e01af-ad19-4918-aaf6-78735fe08de8

📥 Commits

Reviewing files that changed from the base of the PR and between 6c7584e and ff4af2e.

📒 Files selected for processing (3)
  • examples/calculator/src/index.tsx
  • examples/pomodoro-timer/src/index.tsx
  • packages/dev-server/src/devtools.ts

const attrs = styleToCellAttrs(this._style);

const label = this._showLabel ? ` ${Math.round(this._value * 100)}%` : '';
const label = this._showLabel ? ` ${Math.round(this._value * 100 + Number.EPSILON)}%` : '';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'Relevant file locations and lines:\n'
fd -a 'index.tsx|devtools.ts' . | sed 's#^\./##' | while read -r f; do
  case "$f" in
    examples/pomodoro-timer/src/index.tsx|packages/dev-server/src/devtools.ts)
      echo "== $f =="
      nl -ba "$f" | sed -n '75,90p;175,192p'
      ;;
  esac
done

printf '\nSearch for Number.EPSILON usage:\n'
rg -n "Number\.EPSILON|FPS|_value|fps" examples/pomodoro-timer/src/index.tsx packages/dev-server/src/devtools.ts || true

printf '\nBehavioral probe for edge/floating cases:\n'
node - <<'JS'
const inputs = {
  percentage: [0.2929999999999997, 0.293, 0.9940000000000002],
  fps: [14.144999999999997, 14.145, 14.144000000000002],
};
for (const [name, values] of Object.entries(inputs)) {
  console.log(name);
  for (const v of values) {
    let out;
    if (name === 'percentage') {
      out = {current: Math.round(v * 100 + Number.EPSILON), proposed: Math.round((v + Number.EPSILON) * 100)};
    } else {
      out = {current: Math.round(v * 10 + Number.EPSILON) / 10, proposed: Math.round((v + Number.EPSILON) * 10) / 10};
    }
    console.log(`${v} -> current ${out.current}, proposed ${out.proposed}`);
  }
}
JS

Repository: Karanjot786/TermUI

Length of output: 1818


Use a deterministic rounding helper instead of adding Number.EPSILON after scaling.

Both expressions multiply the value, add one unscaled epsilon, then round. That works at the tested boundary values, but unscaled Number.EPSILON is too small to correct errors after scaling is applied. A deterministic 2 decimal-places formatter/rounding helper is clearer and avoids similar edge-case rounding mistakes.

📍 Affects 2 files
  • examples/pomodoro-timer/src/index.tsx#L185-L185 (this comment)
  • packages/dev-server/src/devtools.ts#L81-L81
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/pomodoro-timer/src/index.tsx` at line 185, Replace the
scaled-value-plus-Number.EPSILON rounding at
examples/pomodoro-timer/src/index.tsx:185 and
packages/dev-server/src/devtools.ts:81 with a shared deterministic
two-decimal-place rounding/formatting helper; update the label calculation in
the visible label expression and the corresponding sibling expression,
preserving percentage output while avoiding unscaled epsilon arithmetic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:dev-server @termuijs/dev-server area:examples Example apps. type:bug +10 pts. Bug fix.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant