Skip to content

fix: resolve 4 bugs in termui - #3541

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

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

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Aug 5, 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).
  • Fixed default sort: .sort() coerces elements to strings, so [10, 9, 2] sorts as [10, 2, 9]; numeric comparator sorts correctly.
  • Added rejection handler to Promise.all: an unhandled rejection in any input promise previously crashed silently.
  • 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: #3540

Summary by CodeRabbit

  • Bug Fixes
    • Improved progress percentage rounding at boundary values.
    • Corrected tab selection when navigating with the keyboard.
    • Ensured multi-select options remain in the correct numeric order, including larger option lists.
    • Added clearer console reporting when form operations fail.

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

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The changes apply four targeted correctness fixes: more precise percentage rounding, explicit decimal tab parsing, numeric sorting of selected options, and logging for rejected form operations.

Changes

Correctness fixes

Layer / File(s) Summary
Numeric handling corrections
examples/pomodoro-timer/src/index.tsx, examples/showcase/src/index.tsx, packages/ui/src/MultiSelect.ts
Percentage rounding adds Number.EPSILON. Tab-key parsing uses radix 10. Checked option indices sort numerically.
Promise rejection logging
packages/ui/src/Form.ts
Rejected Promise.all operations are logged with console.error.

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

Possibly related PRs

Suggested labels: type:bug

Suggested reviewers: karanjot786

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the changes but omits required package, GSSoC, and template checklist information, and it does not use the required issue-closing format. Complete every required template section, identify the affected packages, provide the GSSoC profile, complete the checklist, and change the issue reference to Closes #3540``.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the four bug fixes and follows the required type-and-description 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 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Biome (2.5.6)
packages/ui/src/Form.ts

File contains syntax errors that prevent linting: Line 142: Expected a statement but instead found '.catch(err => console.error("Promise.all failed:", err))'.


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 5, 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: 2

🤖 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 percentage calculation in the label expression within the
timer rendering method so Number.EPSILON is applied to this._value before
multiplying by 100, ensuring values near rounding boundaries display the correct
percentage while preserving the existing conditional label behavior.

In `@packages/ui/src/Form.ts`:
- Around line 141-142: Fix the Promise.all flow in Form validation by attaching
the rejection handler directly to the Promise.all call near the existing
validation logic, or wrap it in try/catch. On rejection, reset _isValidating,
call markDirty(), and return before invoking _onSubmit; do not allow submission
to continue with an empty result.
🪄 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: c4940d80-a89d-425b-ba50-de3ede733e59

📥 Commits

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

📒 Files selected for processing (4)
  • examples/pomodoro-timer/src/index.tsx
  • examples/showcase/src/index.tsx
  • packages/ui/src/Form.ts
  • packages/ui/src/MultiSelect.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

Apply the epsilon before scaling the value.

Number.EPSILON is added after multiplication by 100. At this magnitude, it can have no effect. A value near 0.285 can still display 28% instead of 29%.

Apply the epsilon before multiplication, or scale it for the percentage calculation.

Proposed fix
-        const label = this._showLabel ? ` ${Math.round(this._value * 100 + Number.EPSILON)}%` : '';
+        const label = this._showLabel ? ` ${Math.round((this._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 label = this._showLabel ? ` ${Math.round(this._value * 100 + Number.EPSILON)}%` : '';
const label = this._showLabel ? ` ${Math.round((this._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/pomodoro-timer/src/index.tsx` at line 185, Update the percentage
calculation in the label expression within the timer rendering method so
Number.EPSILON is applied to this._value before multiplying by 100, ensuring
values near rounding boundaries display the correct percentage while preserving
the existing conditional label behavior.

Comment thread packages/ui/src/Form.ts
Comment on lines +141 to +142

.catch(err => console.error("Promise.all failed:", err)); No newline at end of file

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

Attach the rejection handler to Promise.all.

The standalone .catch(...) at Line 142 is not attached to an expression. Biome reports a parse error, so the package cannot build.

Attach the handler to the Promise.all call at Line 83, or use try/catch. On rejection, reset _isValidating, call markDirty(), and return before _onSubmit. Do not convert the rejection into an empty result that allows submission to continue.

🧰 Tools
🪛 Biome (2.5.6)

[error] 142-142: Expected a statement but instead found '.catch(err => console.error("Promise.all failed:", err))'.

(parse)

🪛 GitHub Actions: CI / 0_build-and-test.txt

[error] 142-142: The @termuijs/ui build failed during tsup/esbuild because of an unexpected '.' in .catch(err => console.error("Promise.all failed:", err));. TypeScript also reported syntax errors including TS1128, TS1005, and TS2304.

🪛 GitHub Actions: CI / build-and-test

[error] 142-142: The @termuijs/ui build failed during tsup/esbuild: unexpected '.' at '.catch(err => console.error("Promise.all failed:", err));'. TypeScript also reported TS1128, TS1005, and TS2304 syntax errors.

🤖 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/ui/src/Form.ts` around lines 141 - 142, Fix the Promise.all flow in
Form validation by attaching the rejection handler directly to the Promise.all
call near the existing validation logic, or wrap it in try/catch. On rejection,
reset _isValidating, call markDirty(), and return before invoking _onSubmit; do
not allow submission to continue with an empty result.

Source: Linters/SAST tools

@coderabbitai coderabbitai Bot mentioned this pull request Aug 5, 2026
4 tasks
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