Skip to content

fix: resolve 4 bugs in termui - #3683

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

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

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Aug 7, 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.
  • 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.
  • 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: #3682

Summary by CodeRabbit

  • Bug Fixes
    • Improved the clear-form keyboard shortcut behavior.
    • Fixed numeric tab-key handling in the showcase example for more consistent navigation.
    • Improved FPS display rounding to provide more accurate performance readings.

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

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The changes update a form shortcut condition, make tab-key parsing explicitly decimal, and improve FPS rounding with Number.EPSILON.

Changes

Correctness fixes

Layer / File(s) Summary
Input condition and radix handling
examples/forms-and-validation/src/index.tsx, examples/showcase/src/index.tsx
The form shortcut uses the updated control-key condition. Tab-key parsing now uses radix 10.
FPS rounding correction
packages/dev-server/src/devtools.ts
FPS calculation adds Number.EPSILON before rounding to one decimal place.

Estimated code review effort: 2 (Simple) | ~5 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 covers the changes and testing but omits required package, GSSoC, checklist, and issue-closing details. Complete the repository template, including package names, a closing reference such as "Closes #3682", all checklist items, and GSSoC participation details.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the pull request as four bug fixes in TermUI and follows the required type-prefix format.
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

🧹 Nitpick comments (1)
packages/dev-server/src/devtools.ts (1)

81-81: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a regression test for the FPS rounding boundary.

The existing recordRender test in packages/dev-server/src/devtools.test.ts, Lines [308]-[313], checks hover-state cleanup only. Add a test that controls render timestamps and asserts the reported FPS at a one-decimal rounding boundary. This verifies that the Number.EPSILON change prevents the targeted regression.

🤖 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, Add a regression test
alongside the existing recordRender test in devtools.test.ts that controls
render timestamps to produce an FPS value at a one-decimal rounding boundary,
then assert the reported FPS uses the expected rounded value. Keep the test
focused on the Number.EPSILON behavior in recordRender rather than hover-state
cleanup.
🤖 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: Update the clear-shortcut condition in the event-key handler to use
logical negation of event.ctrl, ensuring unmodified “c” opens the modal while
Ctrl+C remains unaffected.

---

Nitpick comments:
In `@packages/dev-server/src/devtools.ts`:
- Line 81: Add a regression test alongside the existing recordRender test in
devtools.test.ts that controls render timestamps to produce an FPS value at a
one-decimal rounding boundary, then assert the reported FPS uses the expected
rounded value. Keep the test focused on the Number.EPSILON behavior in
recordRender rather than hover-state cleanup.
🪄 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: f332fd9e-0e17-44ac-988a-58d83a30ef49

📥 Commits

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

📒 Files selected for processing (3)
  • examples/forms-and-validation/src/index.tsx
  • examples/showcase/src/index.tsx
  • packages/dev-server/src/devtools.ts

}

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 | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate and inspect the key section without running repository code.
printf 'File candidates:\n'
fd -a 'index\.tsx$' . | sed 's#^\./##' | grep 'examples/forms-and-validation/src/index.tsx' || true

printf '\nFile size:\n'
wc -l examples/forms-and-validation/src/index.tsx

printf '\nRelevant lines 110-130:\n'
sed -n '110,130p' examples/forms-and-validation/src/index.tsx | nl -ba -v110

printf '\nSearch shortcut-related lines:\n'
rg -n "event\.key|quit|clear|Ctrl|ctrl|modal|key==='c'|key === 'c'" examples/forms-and-validation/src/index.tsx

Repository: Karanjot786/TermUI

Length of output: 362


🏁 Script executed:

#!/bin/bash
set -euo pipefail
# Check TypeScript availability for a deterministic syntax/scope probe only if needed.
if command -v tsc >/dev/null 2>&1; then
  tsc --version
else
  echo 'tsc not installed'
fi

Repository: Karanjot786/TermUI

Length of output: 170


Use logical negation for the clear shortcut.

event.ctrl ! is a postfix non-null assertion, not !event.ctrl. Unmodified c therefore does not open the modal. Ctrl+C exits before this condition runs.

-        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, Update the
clear-shortcut condition in the event-key handler to use logical negation of
event.ctrl, ensuring unmodified “c” opens the modal while Ctrl+C remains
unaffected.

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