Skip to content

fix: resolve 4 bugs in termui - #3517

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

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

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).
  • 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: #3516

Summary by CodeRabbit

  • Bug Fixes
    • Improved progress percentage rounding so values near whole numbers display more accurately.
    • Updated showcase tab navigation to interpret numeric keyboard input consistently.
    • Improved development reload diagnostics by reporting errors that occur during the reload process.
    • Standardized dependency ordering during builds for more consistent generated results.

@github-actions github-actions Bot added area:examples Example apps. area:dev-server @termuijs/dev-server 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 PR updates percentage rounding, tab-key parsing, child-process error handling, and dependency sorting. The reload error-handling change contains an incomplete catch callback that causes a syntax error.

Changes

Correctness fixes

Layer / File(s) Summary
Numeric rounding and parsing
examples/pomodoro-timer/src/index.tsx, examples/showcase/src/index.tsx
Percentage labels add Number.EPSILON before rounding. Tab-key parsing uses radix 10.
Reload error logging
packages/dev-server/src/server.ts
Child-process exit errors are passed to logging, but the catch callback is syntactically incomplete.
Dependency sorting
scripts/build-registry.ts
collectDeps uses numeric subtraction to compare dependency strings.

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

Possibly related PRs

Suggested reviewers: karanjot786

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the four fixes, but it omits the package section and does not provide the required issue-closing syntax or full template checklist. Add the affected package names, change Ref: #3516 to `Closes `#3516, and complete the required checklist and GSSoC sections.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title follows the required format and accurately identifies the pull request as a four-bug fix.
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/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 malformed catch callback on exitedPromise by adding a valid
rejection parameter and pass it to console.error, preserving the existing await
and error-handling flow.

In `@scripts/build-registry.ts`:
- Line 47: Update the dependency sorting in collectDeps to use a string
comparator for identifiers rather than numeric subtraction, ensuring
alphabetical ordering such as `@termuijs/core`, `@termuijs/motion`, and
`@termuijs/widgets` while preserving deduplication.
🪄 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: 45270f72-a220-46ea-b5c0-0574abff90fe

📥 Commits

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

📒 Files selected for processing (4)
  • examples/pomodoro-timer/src/index.tsx
  • examples/showcase/src/index.tsx
  • packages/dev-server/src/server.ts
  • scripts/build-registry.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 malformed .catch callback.

Line 383 is invalid TypeScript because the arrow function has no parameter list. This prevents packages/dev-server/src/server.ts from parsing. Pass the rejection value to console.error:

Proposed fix
-            await exitedPromise.catch( => console.error());
+            await exitedPromise.catch((error) => console.error(error));

Static analysis confirms the parser error at Line 383.

📝 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 malformed catch
callback on exitedPromise by adding a valid rejection parameter and pass it to
console.error, preserving the existing await and error-handling flow.

Source: Linters/SAST tools

Comment thread scripts/build-registry.ts
let m: RegExpExecArray | null;
while ((m = re.exec(content)) !== null) deps.add(m[1]!);
return [...deps].sort();
return [...deps].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

echo "## file list"
git ls-files | rg '(^|/)build-registry(\.test)?\.ts$|scripts/build-registry' || true

echo "## scripts/build-registry.ts outline"
ast-grep outline scripts/build-registry.ts --view compact || true

echo "## scripts/build-registry.ts relevant lines"
sed -n '1,90p' scripts/build-registry.ts

echo "## tests around registry sorting"
sed -n '100,155p' scripts/build-registry.test.ts

echo "## JS runtime behavior for array of strings subtracting"
node - <<'JS'
const deps = ['zebra', 'apple', 'Mango', 'banana'];
console.log(JSON.stringify([
  deps.map(v => {
    const values = [];
    const result = [...deps].sort((a, b) => (values.push([JSON.stringify([a,b]), a-b]), [].sort((a, b) => a - b)(v)).flat())
    return undefined;
  })
)));
console.log(JSON.stringify({
  directSubtractionDemo: deps.map((a,i) => a + ' - ' + deps[i] + ' = ' + (a - deps[i])),
  sortBefore: JSON.stringify(deps),
  sortMinusComparator: JSON.stringify([...deps].sort((a, b) => a - b)),
  naturalSort: JSON.stringify([...deps].sort()),
}))
JS

Repository: Karanjot786/TermUI

Length of output: 7130


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "## runtime behavior for string comparator and JS/TC semantics"
node - <<'JS'
const src = [
  `import { Widget } from '`@termuijs/widgets`';`,
  `import { Screen } from '`@termuijs/core`';`,
  `import { timerPoolSubscribe } from '`@termuijs/motion`';`,
  `import { Widget as W2 } from '`@termuijs/widgets`';`,
].join('\n');

const re = /from\s+['"](`@termuijs`\/[a-z-]+)['"]/g;
const deps = new Set();
let m;
while ((m = re.exec(src)) !== null) deps.add(m[1]);
const list = [...deps];

console.log(JSON.stringify({
  directSubtractionDemo: {
    a: JSON.stringify('`@termuijs/widgets` - `@termuijs/core` = ' + ('`@termuijs/widgets`' - '`@termuijs/core`')),
    comparison: JSON.stringify('`@termuijs/motion`' < '`@termuijs/widgets`')
  },
  sortWithSubtractionComparator: JSON.stringify([...list].sort((a, b) => a - b)),
  defaultStringSort: JSON.stringify([...list].sort()),
  expected: JSON.stringify(['`@termuijs/core`', '`@termuijs/motion`', '`@termuijs/widgets`']),
  inputOrder: JSON.stringify(list)
}));
JS

Repository: Karanjot786/TermUI

Length of output: 657


Use a string comparator for dependency identifiers.

Line 47 subtracts string values. This breaks TypeScript strict mode and yields NaN comparisons at runtime, so registry dependencies stay in insertion order instead of sorted order. The collectDeps test expects ["@termuijs/core", "@termuijs/motion", "@termuijs/widgets"].

Proposed fix
-  return [...deps].sort((a, b) => a - b);
+  return [...deps].sort();
📝 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
return [...deps].sort((a, b) => a - b);
return [...deps].sort();
🤖 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 `@scripts/build-registry.ts` at line 47, Update the dependency sorting in
collectDeps to use a string comparator for identifiers rather than numeric
subtraction, ensuring alphabetical ordering such as `@termuijs/core`,
`@termuijs/motion`, and `@termuijs/widgets` while preserving deduplication.

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. type:bug +10 pts. Bug fix.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant