Skip to content

fix: resolve 4 bugs in termui - #3478

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

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

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Aug 4, 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).
  • Prevented interval leak: repeated mounts now clear the previous interval before scheduling a new one.
  • Added Number.EPSILON to Math.round: prevents floating-point drift (e.g. 1.005 * 100 rounding to 100 instead of 101).
  • Added explicit radix to parseInt: without 10, strings like '0x1F' or '08' parse in unintended bases.

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: #3477

Summary by CodeRabbit

  • Bug Fixes
    • Improved streaming updates to prevent overlapping refresh timers.
    • Corrected percentage rounding at floating-point boundaries in the to-do example.
    • Improved keyboard tab selection in the widget gallery.
    • Enhanced animated switch positioning for smoother, more accurate movement.

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

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The changes fix four small correctness issues: overlapping AI streaming intervals, floating-point rounding in todo percentages and switch positions, and decimal parsing for widget-gallery tab keys.

Changes

Correctness fixes

Layer / File(s) Summary
Streaming timer lifecycle
examples/ai-streaming/src/index.tsx
The constructor clears the stored interval before creating a new streaming update interval.
Numeric rounding and parsing
examples/todo-app/src/index.ts, packages/ui/src/Switch.ts, examples/widget-gallery/src/index.ts
Percentage and switch-position calculations add Number.EPSILON before rounding. Widget tab-key parsing uses radix 10.

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

Possibly related PRs

Suggested reviewers: karanjot786

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description summarizes the fixes and testing, but it omits the package section and required issue-closing syntax. Add the affected package(s), use Closes #3477``, and complete the repository checklist and required GSSoC section.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title follows the required format and clearly identifies four bug fixes in TermUI.
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.

@saurabhhhcodes saurabhhhcodes mentioned this pull request Aug 4, 2026
4 tasks

@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/todo-app/src/index.ts`:
- Line 107: Update the percentage calculation at the pct assignment to scale
Number.EPSILON correctly: add it to value before multiplying by 100, or use an
equivalent epsilon scaled to the percentage value, so values such as 0.285 round
to 29.
🪄 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: c6e51e2a-7efc-4847-87c5-9333cd712bb9

📥 Commits

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

📒 Files selected for processing (4)
  • examples/ai-streaming/src/index.tsx
  • examples/todo-app/src/index.ts
  • examples/widget-gallery/src/index.ts
  • packages/ui/src/Switch.ts

const filled = Math.round(barWidth * value);

const pct = Math.round(value * 100);
const pct = Math.round(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

node <<'NODE'
const value = 0.285;
const current = Math.round(value * 100 + Number.EPSILON);
const fixed = Math.round((value + Number.EPSILON) * 100);

if (current !== 28 || fixed !== 29) process.exit(1);
console.log({ current, fixed });
NODE

Repository: Karanjot786/TermUI

Length of output: 183


Scale the epsilon before rounding the percentage.

value = 0.285 can round to 28 with the current code instead of the expected 29. Add the epsilon before multiplying, or apply a scaled epsilon after multiplication.

Proposed fix
-            const pct = Math.round(value * 100 + Number.EPSILON);
+            const pct = Math.round((value + Number.EPSILON) * 100);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const pct = Math.round(value * 100 + Number.EPSILON);
const pct = Math.round((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/todo-app/src/index.ts` at line 107, Update the percentage
calculation at the pct assignment to scale Number.EPSILON correctly: add it to
value before multiplying by 100, or use an equivalent epsilon scaled to the
percentage value, so values such as 0.285 round to 29.

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant