Skip to content

fix: resolve 4 bugs in termui - #3678

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

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

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes real bugs found in the codebase:

  • 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).
  • 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).

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

Summary by CodeRabbit

  • Bug Fixes
    • Improved percentage and FPS display accuracy by preventing minor rounding errors.
    • Prevented duplicate weather refresh timers, ensuring updates occur at the intended five-second interval.

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

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The changes adjust percentage and FPS rounding with Number.EPSILON and manage the weather refresh interval by clearing the previous timer before scheduling a new one.

Changes

Floating-point rounding fixes

Layer / File(s) Summary
Epsilon-adjusted display rounding
examples/pomodoro-timer/src/index.tsx, packages/dev-server/src/devtools.ts
The pomodoro percentage label and recordRender FPS output add Number.EPSILON before rounding.

Weather refresh scheduling

Layer / File(s) Summary
Managed refresh interval
examples/weather/src/index.tsx
The refresh logic clears window.__interval before creating and storing a new 5-second interval.

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

Possibly related PRs

Suggested labels: type:bug

Suggested reviewers: karanjot786

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the fixes but omits required package, GSSoC, full checklist, and exact issue-closing information. Add all template sections, identify affected packages, complete the checklist and GSSoC profile, and change the issue reference to Closes #3677``.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title follows the required type format and accurately describes the bug-fix changes.
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.

@github-actions github-actions Bot added the type:bug +10 pts. Bug fix. label Aug 7, 2026

@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 percent-label rounding in
examples/pomodoro-timer/src/index.tsx at lines 185-185 to add Number.EPSILON
scaled relative to this._value * 100 before Math.round; apply the same
magnitude-aware epsilon pattern to the fps * 10 rounding in
packages/dev-server/src/devtools.ts at lines 81-81.
🪄 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: 3f2298c8-80d8-4799-82bb-e64195c824a7

📥 Commits

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

📒 Files selected for processing (3)
  • examples/pomodoro-timer/src/index.tsx
  • examples/weather/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

echo "== locate files =="
fd -a 'index.tsx|devtools.ts' . | sed 's#^\./##'

echo "== relevant lines =="
sed -n '170,190p' examples/pomodoro-timer/src/index.tsx 2>/dev/null || true
sed -n '70,90p' packages/dev-server/src/devtools.ts 2>/dev/null || true

echo "== surrounding declarations/usages =="
rg -n "_showLabel|_value|fps:|Number\.EPSILON|0\.145|toFixed|Math\.round" examples/pomodoro-timer/src/index.tsx packages/dev-server/src/devtools.ts packages -g '*.{ts,tsx}' 2>/dev/null | head -200

echo "== JS numeric behavior probe =="
node - <<'JS'
const cases = [
  {name:'progress 0.145', value:0.145, scale:100},
  {name:'fps 14.5', value:14.5, scale:10},
  {name:'boundary around .5', value:0.5, scale:1},
  {name:'negative scaled .5', value:-0.5, scale:10},
];
for (const c of cases) {
  const scaled = c.value * c.scale;
  const current = Math.round(c.value * c.scale * 100 + Number.EPSILON) / 100;
  const naive = Math.round(scaled + Number.EPSILON);
  const magnitudeAware = Math.round(scaled + Number.EPSILON * Math.max(1, Math.abs(scaled)));
  const epsilonBefore = Math.round((c.value + Number.EPSILON) * c.scale);
  console.log(JSON.stringify({
    name:c.name, scaled, current, naive, magnitudeAware, epsilonBefore,
  }));
}

console.log({
  exact0145Scaled: 0.145*100,
  eps: Number.EPSILON,
  roundScalesEps: Math.round(0.145*100 + Number.EPSILON),
  roundScalesEpsTimes100: Math.round(0.145*100 + Number.EPSILON) / 100,
});
JS

Repository: Karanjot786/TermUI

Length of output: 22481


Use a magnitude-aware epsilon in both rounding paths.

Add epsilon relative to the scaled operand so the fix covers floating-point rounding errors across the full numeric range.

  • examples/pomodoro-timer/src/index.tsx#L185: Round this._value * 100 with a scaled epsilon before rendering the percent label.
  • packages/dev-server/src/devtools.ts#L81: Round fps * 10 with the same scaled epsilon pattern.
📍 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, Update the percent-label
rounding in examples/pomodoro-timer/src/index.tsx at lines 185-185 to add
Number.EPSILON scaled relative to this._value * 100 before Math.round; apply the
same magnitude-aware epsilon pattern to the fps * 10 rounding in
packages/dev-server/src/devtools.ts at lines 81-81.

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