Skip to content

fix: resolve 4 bugs in termui - #3671

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

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

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Aug 6, 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).
  • Filled empty catch block: silently swallowing the error hides failures; now logs for debugging.
  • 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: #3670

Summary by CodeRabbit

  • Bug Fixes
    • Improved keyboard navigation when selecting tabs.
    • Enhanced reload diagnostics by reporting child-process errors.
    • Improved switch animation positioning for smoother visual results.
    • Fixed value comparisons in tree selection controls when numeric values are involved.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The pull request applies targeted fixes for decimal parsing, floating-point rounding, numeric array comparison, and rejected child-process promise handling. The reload rejection callback currently contains invalid TypeScript syntax.

Changes

Correctness fixes

Layer / File(s) Summary
Numeric parsing, rounding, and sorting
examples/widget-gallery/src/index.ts, packages/ui/src/Switch.ts, packages/ui/src/TreeSelect.ts
Tab parsing now uses radix 10. Switch rounding adds Number.EPSILON. TreeSelect compares sorted values with numeric ordering.
Reload rejection logging
packages/dev-server/src/server.ts
The reload flow now attempts to log rejected child-process exit promises, but the .catch callback syntax is malformed.

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

Possibly related PRs

Suggested labels: type:bug, area:examples, area:ui, area:dev-server

Suggested reviewers: karanjot786

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the four fixes but omits the package list, required issue-closing syntax, GSSoC section, and most checklist items. Add the missing template sections, list affected packages, change the issue reference to Closes #3670``, and complete all applicable checklist items.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies this as a fix for 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
🧪 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/dev-server/src/server.ts

File contains syntax errors that prevent linting: Line 383: Expected a parenthesis '(' but instead found '=>'.


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/dev-server/src/server.ts`:
- Line 383: Fix the invalid catch callback in the exitedPromise handling by
accepting its rejection value and passing that value to console.error,
preserving the existing await and error-reporting behavior.

In `@packages/ui/src/TreeSelect.ts`:
- Around line 185-186: Update _valuesEqual so sortedA and sortedB both use the
same comparator. Preserve numeric ordering for numeric values and provide a
deterministic fallback for non-numeric values, ensuring equivalent
numeric-string arrays in different orders compare equal without changing the
existing equality behavior.
🪄 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: 720a039f-5ce2-4487-b6b8-eafa2195db4f

📥 Commits

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

📒 Files selected for processing (4)
  • examples/widget-gallery/src/index.ts
  • packages/dev-server/src/server.ts
  • packages/ui/src/Switch.ts
  • packages/ui/src/TreeSelect.ts

this._killChild();

await exitedPromise.catch(() => {});
await exitedPromise.catch( => console.error());

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 callback before merge.

Line [383] does not parse because the callback parameter is missing. This blocks the TypeScript build. Pass the rejection value to console.error; otherwise the error remains discarded.

Proposed fix
-            await exitedPromise.catch( => console.error());
+            await exitedPromise.catch((error) => {
+                console.error(error);
+            });
📝 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
await exitedPromise.catch( => console.error());
await exitedPromise.catch((error) => {
console.error(error);
});
🧰 Tools
🪛 Biome (2.5.6)

[error] 383-383: Expected a parenthesis '(' but instead found '=>'.

(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/dev-server/src/server.ts` at line 383, Fix the invalid catch
callback in the exitedPromise handling by accepting its rejection value and
passing that value to console.error, preserving the existing await and
error-reporting behavior.

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 | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== files =="
git ls-files | rg '(^|/)TreeSelect(\.ts|\.test\.ts|\.tsx)$|packages/ui/src/TreeSelect'

echo "== outline =="
if [ -f packages/ui/src/TreeSelect.ts ]; then
  ast-grep outline packages/ui/src/TreeSelect.ts || true
fi

echo "== relevant lines =="
if [ -f packages/ui/src/TreeSelect.ts ]; then
  sed -n '150,210p' packages/ui/src/TreeSelect.ts | cat -n
fi

echo "== tests with values =="
if [ -f packages/ui/src/TreeSelect.test.ts ]; then
  rg -n -C 3 "TreeSelect|_valuesEqual|values=|setKey|handleKey|sort|s|a|10|2" packages/ui/src/TreeSelect.test.ts || true
fi

echo "== package script availability =="
ls -la packages/ui/package.json 2>/dev/null || true

Repository: Karanjot786/TermUI

Length of output: 6604


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== all _valuesEqual usages =="
rg -n "_valuesEqual|selectedValues|selectedValues.set|selectedValues.has|selectedValues.add" packages/ui/src packages --glob '*.ts' --glob '*.tsx' || true

echo "== source around calls =="
sed -n '1,120p' packages/ui/src/TreeSelect.ts | cat -n

Repository: Karanjot786/TermUI

Length of output: 12579


🏁 Script executed:

#!/bin/bash
set -euo pipefail

node - <<'JS'
function valuesEqualNumeric(a, b) {
  const sortedA = [...a].sort((a, b) => a - b);
  const sortedB = [...b].sort();
  if (sortedA.length !== sortedB.length) return false;
  for (let i = 0; i < sortedA.length; i++) if (sortedA[i] !== sortedB[i]) return false;
  return true;
}
function valuesEqualSameComparator(a, b) {
  const compare = (left, right) => {
    const leftNumber = Number(left);
    const rightNumber = Number(right);
    if (Number.isFinite(leftNumber) && Number.isFinite(rightNumber)) return leftNumber - rightNumber;
    return left.localeCompare(right);
  };
  const sortedA = [...a].sort(compare);
  const sortedB = [...b].sort(compare);
  if (sortedA.length !== sortedB.length) return false;
  for (let i = 0; i < sortedA.length; i++) if (sortedA[i] !== sortedB[i]) return false;
  return true;
}
for (const pairs of [
  [['10','2'], ['2','10']],
  [['a','b'], ['b','a']],
  [['a','10'], ['10','a']]
]) {
  console.log(JSON.stringify({ pairs, current: valuesEqualNumeric(...pairs), sameComparator: valuesEqualSameComparator(...pairs) }));
}
JS

Repository: Karanjot786/TermUI

Length of output: 369


Use one comparator for _valuesEqual.

TreeSelect.test.ts uses non-numeric values ('s', 'a'), but _valuesEqual sorts next with the default locale comparator while still passing a callback to previous. If the values are numeric strings in a different order, such as ['10', '2'] versus ['2', '10'], the arrays compare unequal and causes extra change events. Use the same comparator for both arrays, including a deterministic non-numeric fallback.

🤖 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 _valuesEqual so
sortedA and sortedB both use the same comparator. Preserve numeric ordering for
numeric values and provide a deterministic fallback for non-numeric values,
ensuring equivalent numeric-string arrays in different orders compare equal
without changing the existing equality behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant