Skip to content

fix: resolve 4 bugs in termui - #3658

Open
saurabhhhcodes wants to merge 1 commit into
Karanjot786:mainfrom
saurabhhhcodes:fix/termui-68777
Open

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

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes real bugs found in the codebase:

  • Simplified empty-string validation: comparing trim() to '' misses whitespace-only input; .trim().length === 0 is explicit.
  • Replaced global isNaN with Number.isNaN: the global version coerces its argument, so isNaN('1') returns false while Number.isNaN is strict.
  • 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: #3657

Summary by CodeRabbit

  • Bug Fixes
    • Improved calculator handling for invalid numeric input.
    • Corrected Pomodoro timer progress percentage rounding.
    • Improved frame capture handling when trailing rows contain whitespace.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The changes update numeric validation in the calculator, floating-point rounding in the pomodoro timer, and whitespace-only row detection in the development server.

Changes

Validation and display corrections

Layer / File(s) Summary
Numeric validation and rounding
examples/calculator/src/index.tsx, examples/pomodoro-timer/src/index.tsx
safeEval now uses Number.isNaN. The pomodoro percentage calculation adds Number.EPSILON before rounding.
Trailing frame-row detection
packages/dev-server/src/devtools.ts
captureFrame checks the trimmed row length to identify whitespace-only trailing rows.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: type:bug, area:examples, area:dev-server

Suggested reviewers: karanjot786

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the change as a bug fix and accurately summarizes the pull request.
Description check ✅ Passed The description explains the bug fixes, identifies the change type, states testing, and references the related issue.
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: Update the percentage calculation in the label expression of the
relevant timer rendering method to add Number.EPSILON to this._value before
multiplying by 100, preserving the existing rounding and formatting behavior.
Add a regression test covering this._value = 0.145 and assert that the displayed
label is 15%.
🪄 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: dd67ae93-b310-4cc8-99e2-95a633f2d7ef

📥 Commits

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

📒 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

Move Number.EPSILON before the percentage scale.

At this._value = 0.145, the product can be 14.499999999999998. Adding Number.EPSILON after multiplication may still leave the value below 14.5, so the label can display 14% instead of 15%.

Add the epsilon before multiplying by 100, and add a regression test for this boundary.

Proposed fix
-        const label = this._showLabel ? ` ${Math.round(this._value * 100 + Number.EPSILON)}%` : '';
+        const label = this._showLabel ? ` ${Math.round((this._value + Number.EPSILON) * 100)}%` : '';
🤖 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, Update the percentage
calculation in the label expression of the relevant timer rendering method to
add Number.EPSILON to this._value before multiplying by 100, preserving the
existing rounding and formatting behavior. Add a regression test covering
this._value = 0.145 and assert that the displayed label is 15%.

@github-actions github-actions Bot added type:bug +10 pts. Bug fix. area:examples Example apps. area:dev-server @termuijs/dev-server labels Aug 6, 2026
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