Skip to content

fix: resolve 4 bugs in termui - #3503

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

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

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.
  • Filled empty catch block: silently swallowing the error hides failures; now logs for debugging.
  • Added Number.EPSILON to Math.round: prevents floating-point drift (e.g. 1.005 * 100 rounding to 100 instead of 101).
  • Simplified empty-string validation: comparing trim() to '' misses whitespace-only input; .trim().length === 0 is explicit.

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

Summary by CodeRabbit

  • Bug Fixes
    • Chat content now handles whitespace-only lines correctly, improving paragraph formatting.
    • Pomodoro timer progress percentages round more accurately at boundary values.
    • Tree selection comparisons now correctly handle numeric ordering in selected values.
    • Development server reload failures provide clearer error reporting instead of being silently ignored.

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

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This change updates four isolated behaviors: whitespace-only paragraph detection, floating-point percentage rounding, reload error logging, and numeric sorting in TreeSelect.

Changes

Chat parsing

Layer / File(s) Summary
Whitespace paragraph handling
examples/chat-app/src/index.tsx
parseBlocks treats whitespace-only lines as empty paragraphs.

Pomodoro rounding

Layer / File(s) Summary
Percentage rounding
examples/pomodoro-timer/src/index.tsx
Progress percentage formatting adds Number.EPSILON before rounding.

Reload error logging

Layer / File(s) Summary
Exit promise rejection handling
packages/dev-server/src/server.ts
The reload handler logs rejected child-process exit promises, but the catch parameter syntax is incomplete.

TreeSelect comparison

Layer / File(s) Summary
Numeric value sorting
packages/ui/src/TreeSelect.ts
_valuesEqual uses numeric ordering when sorting both value arrays.

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

Possibly related PRs

Suggested labels: type:bug

Suggested reviewers: karanjot786, rosheshchaware

🚥 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 the package section, GSSoC information, and a closing issue link. Add the affected package names, complete the required GSSoC section and checklist, and change Ref: #3502 to a closing issue reference such as `Closes `#3502.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies four bug fixes and follows the required type: short 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.5)
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.

@github-actions github-actions Bot added the type:bug +10 pts. Bug fix. label Aug 4, 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 `@packages/dev-server/src/server.ts`:
- Line 383: Fix the rejection handler in the exitedPromise flow by adding a
valid arrow-function parameter and passing the captured rejection reason to
console.error, preserving the existing catch behavior.

In `@packages/ui/src/TreeSelect.ts`:
- Line 185: Update _valuesEqual so both sorted arrays use the same explicit
numeric comparator, replacing the existing sortedA comparator and applying
Number(left) - Number(right) to sortedB as well. Preserve the existing equality
comparison and handling of multi-digit string 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: 939d566f-2da7-41df-96f9-2946f9f08d2f

📥 Commits

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

📒 Files selected for processing (4)
  • examples/chat-app/src/index.tsx
  • examples/pomodoro-timer/src/index.tsx
  • packages/dev-server/src/server.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 arrow function syntax.

The arrow function ( => console.error()) is missing its parameter list. This is a syntax error and will fail to parse.

Biome confirms this: "Expected a parenthesis '(' but instead found '=>'."

Also pass the rejection reason to console.error, otherwise the log gives no information about the failure.

🐛 Proposed fix
-            await exitedPromise.catch( => console.error());
+            await exitedPromise.catch((err) => console.error(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
await exitedPromise.catch( => console.error());
await exitedPromise.catch((err) => console.error(err));
🧰 Tools
🪛 Biome (2.5.5)

[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 rejection handler in
the exitedPromise flow by adding a valid arrow-function parameter and passing
the captured rejection reason to console.error, preserving the existing catch
behavior.

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:

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

file="packages/ui/src/TreeSelect.ts"

# Confirm both arrays use the same comparator.
rg -n -C 2 'sortedA|sortedB|sort\(' "$file"

# Locate the repository's declared type-check command.
rg -n '"(typecheck|type-check|build)"' package.json packages/ui/package.json 2>/dev/null || true

Repository: Karanjot786/TermUI

Length of output: 740


🏁 Script executed:

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

file="packages/ui/src/TreeSelect.ts"
sed -n '160,195p' "$file"
echo '---'
sed -n '1,60p' "$file"
echo '---'
node - <<'JS'
const a = ["2", "10"];
const b = ["10", "2"];
const sortedA = [...a].sort((x, y) => x - y);
const sortedB = [...b].sort();
console.log(JSON.stringify({a, b, sortedA, sortedB}));
console.log(sortedA.every((v, i) => v === sortedB[i]));
JS

Repository: Karanjot786/TermUI

Length of output: 3502


🏁 Script executed:

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

node - <<'TS'
// Read-only behavioral probe for JavaScript subtraction order on strings.
// This does not execute repository code; it only exercises runtime semantics.
const cases = [
  [
    ["2", "10"],
    ["10", "2"]
  ],
  [
    ["10", "2"],
    ["2", "10"]
  ],
  [
    ["1", "20", "3"],
    ["3", "20", "1"],
  ],
];

for (const [a, b] of cases) {
  const sortedA = [...a].sort((a, b) => a - b);
  const sortedB = [...b].sort();
  console.log(JSON.stringify({
    a,
    b,
    sortedA,
    sortedB,
    equal: sortedA.every((v, i) => v === sortedB[i])
  }));
}
TS

Repository: Karanjot786/TermUI

Length of output: 436


Use a shared numeric comparator for both value arrays.

_valuesEqual uses different sort orders: sortedA uses numeric coercion through subtraction, while sortedB uses default lexicographic ordering. Equal selections with multi-digit values, such as ["2", "10"] and ["10", "2"], compare unequal. Replace the string subtraction with an explicit Number(left) - Number(right) comparator applied to both arrays.

🤖 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 so both
sorted arrays use the same explicit numeric comparator, replacing the existing
sortedA comparator and applying Number(left) - Number(right) to sortedB as well.
Preserve the existing equality comparison and handling of multi-digit string
values.

Source: Coding guidelines

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

Labels

area:dev-server @termuijs/dev-server 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