Skip to content

fix: resolve 4 bugs in termui - #3512

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

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

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Aug 4, 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 rejection handler to Promise.all: an unhandled rejection in any input promise previously crashed silently.
  • Simplified empty-string validation: comparing trim() to '' misses whitespace-only input; .trim().length === 0 is explicit.
  • Replaced global isNaN with Number.isNaN: the global version coerces its argument, so isNaN('1') returns false while Number.isNaN is strict.

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

Summary by CodeRabbit

  • Bug Fixes
    • Improved calculator validation for negative number inputs.
    • Improved selection comparison to correctly handle numeric string values.
    • Added clearer console reporting when multiple form operations fail, making troubleshooting easier.

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

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The pull request updates calculator token validation, form promise rejection logging, and tree selection array comparison.

Changes

Calculator validation

Layer / File(s) Summary
Negative token validation
examples/calculator/src/index.tsx
safeEval uses Number.isNaN for initial negative-number validation.

Form error logging

Layer / File(s) Summary
Promise rejection logging
packages/ui/src/Form.ts
The form logs rejected Promise.all operations with "Promise.all failed:".

Tree selection comparison

Layer / File(s) Summary
Numeric value sorting
packages/ui/src/TreeSelect.ts
_valuesEqual sorts the first value array with a numeric comparator before comparison.

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

Possibly related PRs

Suggested reviewers: karanjot786

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
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 (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies a bug-fix pull request and matches the four bug fixes described in the changeset.
Description check ✅ Passed The description explains the four fixes, identifies the change type, records testing, and references related issue #3511.
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.

@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 `@packages/ui/src/Form.ts`:
- Around line 141-142: Fix the validation flow around the awaited Promise.all
and the trailing catch expression: attach rejection handling directly to the
promise or wrap the await in try/catch. On rejection, reset _isValidating, call
markDirty(), and return so the form cannot remain stuck when validation fails.

In `@packages/ui/src/TreeSelect.ts`:
- Line 185: Update _valuesEqual to use a shared string comparator when sorting
both value arrays, including selectedValues, instead of numeric subtraction.
Ensure arbitrary string values are compared consistently and remain valid under
strict TypeScript.
🪄 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: 0269f72a-9b13-44d4-8b40-d26ce6fb2c3a

📥 Commits

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

📒 Files selected for processing (3)
  • examples/calculator/src/index.tsx
  • packages/ui/src/Form.ts
  • packages/ui/src/TreeSelect.ts

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

Fix the invalid .catch expression before merging.

Promise.all is awaited at Line 83, but .catch starts as a separate statement at Lines 141-142. This is invalid TypeScript, and Biome reports a parse error.

Attach the handler directly to the promise or wrap Line 83 in try/catch. On rejection, reset _isValidating and call markDirty() before returning; otherwise Lines 92 and 97 are skipped and the form can remain stuck in validation.

🧰 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: unexpected '.' at .catch(err => console.error("Promise.all failed:", err));. TypeScript also reported malformed syntax (TS1128, TS1005, and TS2304).

🪛 GitHub Actions: CI / build-and-test

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

🤖 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 awaited Promise.all and the trailing catch expression: attach
rejection handling directly to the promise or wrap the await in try/catch. On
rejection, reset _isValidating, call markDirty(), and return so the form cannot
remain stuck when validation fails.

Source: Linters/SAST tools

function _valuesEqual(a: string[], b: string[]): boolean {
if (a.length !== b.length) return false;
const sortedA = [...a].sort();
const sortedA = [...a].sort((a, b) => a - b);

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

rg -n -C 5 '_valuesEqual|sortedA|sortedB|node\.value|selectedValues' \
  packages/ui/src/TreeSelect.ts packages/ui/src/TreeSelect.test.ts

fd -H 'tsconfig*.json' . --exec rg -n '"strict"\s*:\s*true' {}

Repository: Karanjot786/TermUI

Length of output: 7492


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "## package.json scripts / dependencies relevant to type checking"
python3 - <<'PY'
import json
from pathlib import Path
for p in [Path('package.json'), Path('packages/ui/package.json')]:
    if p.exists():
        data=json.loads(p.read_text())
        print(f"--- {p} ---")
        print(json.dumps({'scripts': data.get('scripts'), 'devDependencies': data.get('devDependencies'), 'dependencies': data.get('dependencies')}, indent=2, sort_keys=True))
PY

echo
echo "## TreeSelect root/root helpers"
sed -n '1,180p' packages/ui/src/TreeSelect.ts | cat -n

echo
echo "## TreeSelect tests around value content"
sed -n '1,130p' packages/ui/src/TreeSelect.test.ts | cat -n

echo
echo "## TypeScript availability and strict parameter subtraction check"
node - <<'JS'
try {
  require.resolve('typescript');
  console.log('typescript available');
} catch {
  console.log('typescript unavailable');
}
JS

Repository: Karanjot786/TermUI

Length of output: 12989


Use the same comparator for both value arrays.

_valuesEqual accepts arbitrary string[], and a - b is invalid in strict TypeScript. The same concern appears for the selectedValues contract, which is not limited to numeric strings. Use one string sort comparator for both arrays and handle non-numeric values consistently.


\

🤖 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/TreeSelect.ts` at line 185, Update _valuesEqual to use a
shared string comparator when sorting both value arrays, including
selectedValues, instead of numeric subtraction. Ensure arbitrary string values
are compared consistently and remain valid under strict TypeScript.

Source: Coding guidelines

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