Skip to content

fix: resolve 4 bugs in termui - #3656

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

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

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Aug 6, 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: #3655

Summary by CodeRabbit

  • Bug Fixes
    • Improved weather updates by preventing overlapping polling timers and maintaining consistent five-second refreshes.
    • Improved FPS display precision for more consistent performance readings.
    • Refined switch animation positioning to prevent minor rounding inaccuracies and visual jitter.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR tracks the weather polling interval and adds Number.EPSILON before rounding FPS and switch animation values.

Changes

Timer and rendering corrections

Layer / File(s) Summary
Weather polling timer tracking
examples/weather/src/index.tsx
The weather example clears the existing interval and stores the new five-second polling interval on window.__interval.
Rendering rounding precision
packages/dev-server/src/devtools.ts, packages/ui/src/Switch.ts
DevTools.recordRender and switch knob positioning add Number.EPSILON before rounding. Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

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

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 and testing, but it omits the package section, required checklist items, GSSoC details, and an explicit issue-closing link. Add the missing template sections, complete the required checklist, provide the GSSoC profile if applicable, and change the issue reference to an explicit closing link such as Closes #3655.
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 clearly identifies a bug-fix change and follows the required type-and-description format.
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 `@packages/dev-server/src/devtools.ts`:
- Line 81: Update the FPS rounding expression in the devtools FPS calculation so
the epsilon is applied relative to the scaled value before Math.round, rather
than adding raw Number.EPSILON to the original product. Preserve the existing
one-decimal output behavior.
🪄 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: d2181fb5-0c99-418d-bb7a-e8015e93f655

📥 Commits

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

📒 Files selected for processing (3)
  • examples/weather/src/index.tsx
  • packages/dev-server/src/devtools.ts
  • packages/ui/src/Switch.ts

widgetCount,
lastRenderAt: now,
fps: Math.round(fps * 10) / 10,
fps: Math.round(fps * 10 + Number.EPSILON) / 10,

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:

#!/usr/bin/env bash
set -euo pipefail

node <<'EOF'
for (const fps of [10, 30, 60, 120]) {
    const scaled = fps * 10;
    const current = scaled + Number.EPSILON;
    const scaleAware = scaled + Number.EPSILON * Math.max(1, Math.abs(scaled));

    console.log({
        fps,
        currentChangesValue: current !== scaled,
        scaleAwareChangesValue: scaleAware !== scaled,
    });
}
EOF

Repository: Karanjot786/TermUI

Length of output: 437


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate and inspect the relevant file around the changed line.
if [ -f packages/dev-server/src/devtools.ts ]; then
  echo "---- packages/dev-server/src/devtools.ts lines 60-95 ----"
  sed -n '60,95p' packages/dev-server/src/devtools.ts | nl -ba -v60
else
  echo "missing packages/dev-server/src/devtools.ts"
  fd -a 'devtools\.ts$' .
fi

echo "---- behavioral probe for intended boundary cases ----"
node - <<'EOF'
function current(fps) {
  return Math.round(fps * 10 + Number.EPSILON) / 10;
}
function scaleAware(fps) {
  const scaledFps = fps * 10;
  return Math.round(
    scaledFps + Number.EPSILON * Math.max(1, Math.abs(scaledFps)),
  ) / 10;
}

const inputs = [
  0.005, 0.015, 0.05,
  1.005, 1.015, 1.05,
  10.005, 10.015, 10.05,
  30.005, 30.015, 30.05,
  60.005, 60.015, 60.05,
  120.05,
  Number.float64FromBits?(0x3fd0000000000000n): undefined,
];
for (const fps of inputs) {
  const scaled = fps * 10;
  if (Number.isNaN(scaled)) continue;
  console.log(JSON.stringify({
    fps,
    rounded: current(fps),
    scaleAwareRounded: scaleAware(fps),
    boundaryNear: fps === Math.round(fps * 10 + Number.EPSILON * Math.max(1, Math.abs(fps * 10))) / 10 + 0,
    scaled: scaled,
    currentChangesScaled: Number.NEXT_UP(scaled) !== scaled,
    maxSafeIntFloor: Math.floor(Number.MAX_SAFE_INTEGER)
  }));
}
EOF

Repository: Karanjot786/TermUI

Length of output: 254


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - <<'PY'
from pathlib import Path
p = Path("packages/dev-server/src/devtools.ts")
if p.exists():
    lines = p.read_text().splitlines()
    print("---- packages/dev-server/src/devtools.ts lines 60-95 ----")
    for i, line in enumerate(lines[59:95], start=60):
        print(f"{i}\t{line}")
else:
    print("missing packages/dev-server/src/devtools.ts")
PY

echo "---- behavioral probe for intended boundary cases ----"
node - <<'EOF'
function current(fps) {
  return Math.round(fps * 10 + Number.EPSILON) / 10;
}
function scaleAware(fps) {
  const scaledFps = fps * 10;
  return Math.round(
    scaledFps + Number.EPSILON * Math.max(1, Math.abs(scaledFps)),
  ) / 10;
}

const inputs = [
  0.005, 0.015, 0.05,
  1.005, 1.015, 1.05,
  10.005, 10.015, 10.05,
  30.005, 30.015, 30.05,
  60.005, 60.015, 60.05,
  120.05,
];
for (const fps of inputs) {
  const scaled = fps * 10;
  console.log(JSON.stringify({
    fps,
    currentRounded: current(fps),
    scaleAwareRounded: scaleAware(fps),
    scaledFloat: scaled,
    currentChangesScaled: scaled + Number.EPSILON !== scaled,
    scaleAwareChangesScaled: scaled + Number.EPSILON * Math.max(1, Math.abs(scaled)) !== scaled,
  }));
}
EOF

Repository: Karanjot786/TermUI

Length of output: 3982


Scale the epsilon with the rounded FPS value.

At 60 FPS, fps * 10 becomes 600, and Number.EPSILON is far smaller than the spacing of values around 600. This makes the + Number.EPSILON correction ineffective for normal FPS values. Apply the epsilon to the scaled value instead.

🤖 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 `@packages/dev-server/src/devtools.ts` at line 81, Update the FPS rounding
expression in the devtools FPS calculation so the epsilon is applied relative to
the scaled value before Math.round, rather than adding raw Number.EPSILON to the
original product. Preserve the existing one-decimal output behavior.

@github-actions github-actions Bot added area:examples Example apps. area:ui @termuijs/ui 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. area:ui @termuijs/ui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant