Skip to content

fix: resolve 4 bugs in termui - #3561

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

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

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes real bugs found in the codebase:

  • Fixed default sort: .sort() coerces elements to strings, so [10, 9, 2] sorts as [10, 2, 9]; numeric comparator sorts correctly.
  • Added Number.EPSILON to Math.round: prevents floating-point drift (e.g. 1.005 * 100 rounding to 100 instead of 101).
  • Added rejection handler to Promise.all: an unhandled rejection in any input promise previously crashed silently.
  • 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: #3560

Summary by CodeRabbit

  • Bug Fixes
    • Improved percentage rounding so progress values display the expected whole-number percentages.
    • Corrected multi-select ordering for lists with more than nine options.
    • Added error logging when form-related asynchronous 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 pull request updates percentage rounding in two examples, adds rejection logging to a form Promise.all operation, and applies numeric sorting to selected MultiSelect option indexes.

Changes

Correctness fixes

Layer / File(s) Summary
Percentage rounding updates
examples/pomodoro-timer/src/index.tsx, examples/todo-app/src/index.ts
Percentage displays add Number.EPSILON before rounding.
Form Promise rejection logging
packages/ui/src/Form.ts
The form logs "Promise.all failed:" and the error when Promise.all rejects.
Numeric selected option ordering
packages/ui/src/MultiSelect.ts
Checked option indexes use numeric sorting before mapping to options.

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 fixes and testing, but it omits required package, GSSoC, and linked issue details. Add the affected packages, complete the required checklist and GSSoC section, and replace Ref: #3560 with a closing issue link such as `Closes `#3560.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies a bug-fix pull request that resolves four TermUI bugs.
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: Move Number.EPSILON before percentage scaling in both renderers:
update the percentage calculation in examples/pomodoro-timer/src/index.tsx at
lines 185-185 and the corresponding calculation in
examples/todo-app/src/index.ts at lines 107-107 to round (value +
Number.EPSILON) after adding epsilon to the normalized value, preserving the
existing conditional label behavior.

In `@packages/ui/src/Form.ts`:
- Around line 141-142: Fix the validation flow around the Promise.all call so
its rejection handler is syntactically attached, or replace it with try/catch.
On rejection, reset _isValidating, call markDirty(), and return before
submitting unvalidated values.
🪄 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: 8f2a8778-dfbe-46f8-9b3f-4f9575291fea

📥 Commits

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

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

Move Number.EPSILON before percentage scaling in both renderers.

Adding epsilon after multiplication by 100 can leave the floating-point error unchanged. Apply the fix at the normalized-value scale.

  • examples/pomodoro-timer/src/index.tsx#L185-L185: use Math.round((this._value + Number.EPSILON) * 100).
  • examples/todo-app/src/index.ts#L107-L107: use Math.round((value + Number.EPSILON) * 100).
📍 Affects 2 files
  • examples/pomodoro-timer/src/index.tsx#L185-L185 (this comment)
  • examples/todo-app/src/index.ts#L107-L107
🤖 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, Move Number.EPSILON
before percentage scaling in both renderers: update the percentage calculation
in examples/pomodoro-timer/src/index.tsx at lines 185-185 and the corresponding
calculation in examples/todo-app/src/index.ts at lines 107-107 to round (value +
Number.EPSILON) after adding epsilon to the normalized value, 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.

At Line 142, .catch(...) is a standalone expression. It is not attached to the Promise.all call at Line 83. This causes the parse error reported by Biome and blocks compilation.

Attach the handler to the Promise.all expression or use try/catch. On rejection, reset _isValidating, call markDirty(), and return before submitting unvalidated values.

Proposed fix
-        const results = await Promise.all(validationPromises);
+        const results = await Promise.all(validationPromises).catch((err) => {
+            console.error("Promise.all failed:", err);
+            this._isValidating = false;
+            this.markDirty();
+            return undefined;
+        });
+        if (results === undefined) return;
...
-.catch(err => console.error("Promise.all failed:", err));
📝 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
.catch(err => console.error("Promise.all failed:", err));
const results = await Promise.all(validationPromises).catch((err) => {
console.error("Promise.all failed:", err);
this._isValidating = false;
this.markDirty();
return undefined;
});
if (results === undefined) return;
🧰 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: esbuild failed to parse TypeScript/JS: Unexpected "." at src/Form.ts:142:0. Code shown: .catch(err => console.error("Promise.all failed:", err));


[error] 142-142: TypeScript DTS build failed with syntax errors at src/Form.ts(142,1): TS1128 Declaration or statement expected.


[error] 142-142: TypeScript DTS build failed at src/Form.ts(142,2): TS1005 'try' expected.


[error] 142-142: TypeScript DTS build failed at src/Form.ts(142,12): TS1005 ')' expected.


[error] 142-142: TypeScript DTS build failed at src/Form.ts(142,56): TS1005 ';' expected.


[error] 142-142: TypeScript DTS build failed at src/Form.ts(142,52): TS2304 Cannot find name 'err'.

🪛 GitHub Actions: CI / build-and-test

[error] 142-142: esbuild build failed in package @termuijs/ui with error: Unexpected "." at src/Form.ts:142:0. Offending code shown: .catch(err => console.error("Promise.all failed:", err));


[error] 142-142: TypeScript DTS build failed with TS1128: Declaration or statement expected (src/Form.ts:142:1).


[error] 142-142: TypeScript DTS build failed with TS1005: 'try' expected (src/Form.ts:142:2).


[error] 142-142: TypeScript DTS build failed with TS1005: ')' expected (src/Form.ts:142:12).


[error] 142-142: TypeScript DTS build failed with TS1005: ';' expected (src/Form.ts:142:56).


[error] 142-142: TypeScript DTS build failed with TS2304: Cannot find name 'err' (src/Form.ts:142:52).

🤖 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 validation flow
around the Promise.all call so its rejection handler is syntactically attached,
or replace it with try/catch. On rejection, reset _isValidating, call
markDirty(), and return before submitting unvalidated values.

Source: Linters/SAST tools

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