Skip to content

fix: resolve 4 bugs in termui - #3518

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

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

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

Summary by CodeRabbit

  • Bug Fixes
    • Improved multi-select behavior so selected options appear in the correct numeric order.
    • Corrected tree selection comparisons for consistently ordered values.
    • Improved error visibility when form operations fail.
    • Ensured widget gallery tab selections are parsed consistently as decimal numbers.

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

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The changes add explicit decimal parsing for tab keys, log rejected form promises, and apply numeric sorting to selection values in MultiSelect and TreeSelect.

Changes

Input parsing

Layer / File(s) Summary
Tab key parsing
examples/widget-gallery/src/index.ts
WidgetGalleryApp.handleKey passes radix 10 to parseInt.

Promise rejection logging

Layer / File(s) Summary
Form rejection logging
packages/ui/src/Form.ts
The form adds a rejection handler that logs "Promise.all failed:" with console.error.

Selection ordering

Layer / File(s) Summary
Numeric selection sorting
packages/ui/src/MultiSelect.ts, packages/ui/src/TreeSelect.ts
MultiSelect sorts checked indices numerically. TreeSelect sorts values with a numeric comparator before comparison.

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

Possibly related PRs

Suggested reviewers: karanjot786

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies a bug-fix pull request that resolves four TermUI bugs.
Description check ✅ Passed The description explains the fixes, identifies the change as a bug fix, records testing and self-review, and references issue #3517.
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.

@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 await
Promise.all(validationPromises) by removing the standalone .catch expression and
wrapping the await in try/catch. In the rejection handler, reset _isValidating
and call markDirty(), then return or rethrow without processing results;
preserve normal result handling only after Promise.all resolves.

In `@packages/ui/src/TreeSelect.ts`:
- Around line 185-186: Update the _valuesEqual comparator so its two value
arrays use a type-consistent comparison: since a and b are string values, sort
both with the same lexicographic comparator and remove numeric subtraction.
Preserve order-independent equality and ensure the implementation passes the
packages/ui strict TypeScript check.
🪄 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: 4c484000-c9be-465b-8507-0b37af37d59d

📥 Commits

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

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

Attach the rejection handler to Promise.all correctly.

Line 142 starts a standalone .catch expression. Biome reports this as a parse error, so packages/ui/src/Form.ts cannot compile.

Use try/catch around the await Promise.all(validationPromises) at Line 83. In the rejection path, reset _isValidating and call markDirty() before returning or rethrowing. Do not continue with results after Promise.all rejects.

🧰 Tools
🪛 Biome (2.5.6)

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

(parse)

🤖 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 await Promise.all(validationPromises) by removing the standalone .catch
expression and wrapping the await in try/catch. In the rejection handler, reset
_isValidating and call markDirty(), then return or rethrow without processing
results; preserve normal result handling only after Promise.all resolves.

Source: Linters/SAST tools

Comment on lines +185 to 186
const sortedA = [...a].sort((a, b) => a - b);
const sortedB = [...b].sort();

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

🧩 Analysis chain

🏁 Script executed:

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

npx --no-install tsc --noEmit --pretty false

Repository: Karanjot786/TermUI

Length of output: 5708


🏁 Script executed:

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

echo "== files =="
git ls-files | rg '(^|/)TreeSelect\.(ts|test\.ts)$|(^|/)tsconfig.*\.json$|package\.json$' || true

echo "== TreeSelect outline =="
ast-grep outline packages/ui/src/TreeSelect.ts || true

echo "== relevant TreeSelect code =="
cat -n packages/ui/src/TreeSelect.ts | sed -n '140,210p'

echo "== test relevant code =="
cat -n packages/ui/src/TreeSelect.test.ts | sed -n '1,120p'

echo "== package tsconfig =="
for f in tsconfig.json packages/tsconfig.json; do
  [ -f "$f" ] && { echo "-- $f"; cat -n "$f"; }
done

echo "== build typecheck with project config =="
npx --no-install tsc --showConfig --build --dry 2>&1 | head -50 || true
npx --no-install tsc -b --noEmit 2>&1 | head -200 || true

Repository: Karanjot786/TermUI

Length of output: 11804


🏁 Script executed:

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

echo "== root/package configs =="
for f in package.json packages/ui/package.json packages/ui/tsconfig.json packages/ui/tsconfig.typecheck.json tsconfig.base.json; do
  [ -f "$f" ] && { echo "-- $f"; cat -n "$f"; }
done

echo "== TypeScript invocation with project =="
npx --no-install tsc -p packages/ui/tsconfig.typecheck.json --noEmit 2>&1

echo "== local JS sort/comparator behavior =="
node2 - <<'JS'
for (const pairs of [
  [['2', '10'], ['10', '2']],
  [['s', 'a'], ['a', 's']],
  [['one', 'two'], ['two', 'one']],
]) {
  const a = [...pairs[0]].sort((a, b) => a - b);
  const b = [...pairs[0]].sort();
  console.log(pairs[0].join(','), 'cmpA=', a.join(','), 'sort=', b.join(','));
}
JS

Repository: Karanjot786/TermUI

Length of output: 5927


Fix the value-equality comparator.

a and b are string values in _valuesEqual, so subtracting them fails the packages/ui TypeScript strict check. If the values are meant to be strings, use the same lexicographic sort for both arrays; if numeric values are required, make the value type/comparator consistent and add tests for numeric and nonnumeric inputs.

🤖 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` around lines 185 - 186, Update the
_valuesEqual comparator so its two value arrays use a type-consistent
comparison: since a and b are string values, sort both with the same
lexicographic comparator and remove numeric subtraction. Preserve
order-independent equality and ensure the implementation passes the packages/ui
strict TypeScript check.

Source: Coding guidelines

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