Skip to content

fix: resolve 4 bugs in termui - #3660

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

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

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes real bugs found in the codebase:

  • Added explicit radix to parseInt: without 10, strings like '0x1F' or '08' parse in unintended bases.
  • 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).
  • Removed redundant boolean comparison: x === true is equivalent to x (and x === false to !x), and shorter to read.

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

Summary by CodeRabbit

  • Bug Fixes
    • Fixed the clear-form keyboard shortcut in the forms and validation example.
    • Improved hexadecimal entity decoding in the RSS reader.
    • Increased progress percentage accuracy near rounding boundaries in the todo app.
    • Prevented duplicate weather refresh timers and ensured updates continue every five seconds.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Four example applications update form shortcut handling, RSS hexadecimal parsing, progress rounding, and weather refresh interval management.

Changes

Forms validation shortcut

Layer / File(s) Summary
Update clear-form shortcut condition
examples/forms-and-validation/src/index.tsx
The condition changes from event.ctrl === false to the syntactically incomplete event.ctrl ! expression.

RSS entity parsing

Layer / File(s) Summary
Limit hexadecimal entity parsing
examples/rss-reader/src/index.tsx
Hexadecimal entities now parse at most eight hexadecimal digits after &#x``.

Todo progress rounding

Layer / File(s) Summary
Adjust percentage rounding
examples/todo-app/src/index.ts
Percentage labels now add Number.EPSILON before rounding.

Weather refresh interval

Layer / File(s) Summary
Manage refresh interval
examples/weather/src/index.tsx
The refresh logic clears window.__interval before assigning a new five-second interval.

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

Possibly related PRs

Suggested labels: type:bug, area:examples

Suggested reviewers: karanjot786

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the changes and testing, but it omits the required package section and uses Ref: #3659`` instead of a closing issue link. Add the affected package names, use Closes #3659``, and complete all required template sections and checklist items.
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 describes the four bug fixes and follows the required type: short 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: 3

🤖 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/forms-and-validation/src/index.tsx`:
- Line 125: Fix the condition in the keyboard event handler by restoring the
negation before event.ctrl, so the clear-form modal opens only for plain “c” and
Ctrl+C continues through the existing quit branch.

In `@examples/rss-reader/src/index.tsx`:
- Line 30: Update the hexadecimal entity parsing near codePoint so the matched
suffix accepts at most eight hexadecimal digits. Ensure entities with more than
eight digits are returned unchanged rather than truncated, while preserving
decoding for valid entities within the limit.

In `@examples/todo-app/src/index.ts`:
- Line 107: Update the percentage calculation in the progress-rendering logic
around pct so Number.EPSILON is scaled appropriately after value * 100 and
before Math.round. Preserve the existing percentage output while ensuring
boundary values such as 29 / 200 round to 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: 2a8d4092-eb08-4c27-bdf0-1f97b2451e50

📥 Commits

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

📒 Files selected for processing (4)
  • examples/forms-and-validation/src/index.tsx
  • examples/rss-reader/src/index.tsx
  • examples/todo-app/src/index.ts
  • examples/weather/src/index.tsx

}

if (event.key === 'c' && event.ctrl === false) {
if (event.key === 'c' && event.ctrl !) {

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 | 🔴 Critical | ⚡ Quick win

Restore the missing negation operator.

event.ctrl ! is invalid TypeScript syntax, so the application cannot compile. Use !event.ctrl to open the clear-form modal only for plain c; Ctrl+C remains handled by the quit branch on Lines 121-123.

Proposed fix
-        if (event.key === 'c' && event.ctrl !) {
+        if (event.key === 'c' && !event.ctrl) {
📝 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
if (event.key === 'c' && event.ctrl !) {
if (event.key === 'c' && !event.ctrl) {
🤖 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/forms-and-validation/src/index.tsx` at line 125, Fix the condition
in the keyboard event handler by restoring the negation before event.ctrl, so
the clear-form modal opens only for plain “c” and Ctrl+C continues through the
existing quit branch.

return value.replace(/&(#x?[0-9a-fA-F]+|[a-zA-Z]+);/g, (match, entity: string) => {
if (entity.startsWith('#x')) {
const codePoint = Number.parseInt(entity.slice(2), 16);
const codePoint = Number.parseInt(entity.slice(2, 10), 16);

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

Reject hexadecimal entities longer than eight digits instead of truncating them.

Line 28 still matches an unlimited hexadecimal suffix. Line 30 then discards digits after the first eight. For example, A decodes from 00000004 instead of 00000041, which corrupts RSS content.

Check the digit count and return match when it exceeds eight digits, or limit the regular expression to {1,8}.

Proposed fix
-      const codePoint = Number.parseInt(entity.slice(2, 10), 16);
+      const digits = entity.slice(2);
+      if (digits.length > 8) {
+        return match;
+      }
+      const codePoint = Number.parseInt(digits, 16);
📝 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 codePoint = Number.parseInt(entity.slice(2, 10), 16);
const digits = entity.slice(2);
if (digits.length > 8) {
return match;
}
const codePoint = Number.parseInt(digits, 16);
🤖 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/rss-reader/src/index.tsx` at line 30, Update the hexadecimal entity
parsing near codePoint so the matched suffix accepts at most eight hexadecimal
digits. Ensure entities with more than eight digits are returned unchanged
rather than truncated, while preserving decoding for valid entities within the
limit.

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:

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

node <<'NODE'
const value = 29 / 200;
const current = Math.round(value * 100 + Number.EPSILON);
const proposed = Math.round((value + Number.EPSILON) * 100);

if (current !== 14) {
  throw new Error(`Expected current expression to produce 14, got ${current}`);
}
if (proposed !== 15) {
  throw new Error(`Expected proposed expression to produce 15, got ${proposed}`);
}
NODE

Repository: Karanjot786/TermUI

Length of output: 156


🏁 Script executed:

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

printf 'Current expression behavior for boundary values:\n'
node <<'NODE'
const boundaries = [29 / 200, 57 / 200, 85 / 200, 4 / 50, 6 / 50, 29 / 200000000, 1.000000012345678e-8, 2e-14, 1.3333333333333333e-8];
for (const value of boundaries) {
  const scaled = value * 100;
  const current = Math.round(scaled + Number.EPSILON);
  const proposed = Math.round((value + Number.EPSILON) * 100);
  console.log({
    value,
    roundedValue: scaled.toFixed(20),
    current,
    proposed
  });
}
NODE

printf '\nRelevant src/index.ts context:\n'
sed -n '80,120p' examples/todo-app/src/index.ts

Repository: Karanjot786/TermUI

Length of output: 2869


Add Number.EPSILON before rounding the percentage.

Number.EPSILON after value * 100 is smaller than the floating-point error at percentage boundaries, so values such as 29 / 200 can still render as 14% instead of 15%.

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 in the progress-rendering logic around pct so Number.EPSILON is
scaled appropriately after value * 100 and before Math.round. Preserve the
existing percentage output while ensuring boundary values such as 29 / 200 round
to 15%.

@saurabhhhcodes saurabhhhcodes mentioned this pull request Aug 6, 2026
4 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Aug 7, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant