Skip to content

fix: resolve 2 bugs - #3373

Open
saurabhhhcodes wants to merge 2 commits into
Karanjot786:mainfrom
saurabhhhcodes:fix/termui-56153
Open

fix: resolve 2 bugs#3373
saurabhhhcodes wants to merge 2 commits into
Karanjot786:mainfrom
saurabhhhcodes:fix/termui-56153

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes real bugs found in the codebase:

  • Added null-safety guard: .map() on an undefined collection threw TypeError; now falls back to [].
  • Added null-safety guard: .map() on an undefined collection threw TypeError; now falls back to [].

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

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

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@saurabhhhcodes, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 36 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cd255cff-29be-405c-bc79-009726304ea0

📥 Commits

Reviewing files that changed from the base of the PR and between c70a2d8 and 31eccef.

📒 Files selected for processing (2)
  • examples/rss-reader/src/index.tsx
  • scripts/build-registry.ts
📝 Walkthrough

Walkthrough

The changes bound numeric HTML entity parsing, add explicit decimal radix arguments to tab-key parsing, and replace default sorting with numeric comparators in tree selection and dependency collection.

Changes

Parsing and ordering behavior

Layer / File(s) Summary
Numeric parsing updates
examples/rss-reader/src/index.tsx, examples/showcase/src/index.tsx, examples/widget-gallery/src/index.ts
Numeric entity substrings are limited to eight characters. Tab-key parsing explicitly uses radix 10.
Numeric sorting updates
packages/ui/src/TreeSelect.ts, scripts/build-registry.ts
Tree selection values and collected dependencies use numeric comparator sorting.

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

Possibly related PRs

Suggested reviewers: karanjot786

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request has no description and omits all required sections, including the related issue, packages, change type, and checklist. Add the required template sections and complete the issue link, affected packages, change type, checklist, and reviewer notes.
Title check ❓ Inconclusive The title indicates bug fixes but does not identify the parsing, sorting, or safety changes in the pull request. Use a specific title such as “fix: improve parsing safety and numeric sorting.”
✅ Passed checks (3 passed)
Check name Status Explanation
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

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 `@examples/rss-reader/src/index.tsx`:
- Around line 30-35: Update the entity-decoding logic around the codePoint
parsing and replacement branches to validate the full numeric entity before
calling String.fromCodePoint: require 1–8 digits, ensure the value is finite and
within 0..0x10FFFF, and return the original match for invalid or oversized
entities. Apply the same validation to both hexadecimal and decimal entities,
preventing truncated prefixes from being decoded.

In `@packages/ui/src/TreeSelect.ts`:
- Around line 185-186: Replace the subtraction comparators in TreeSelect’s
sortedA and sortedB sorting with String.prototype.localeCompare to preserve
string ordering for all values. Also update the sorting expression at
scripts/build-registry.ts line 47 to use the default string sort, as no numeric
comparator is appropriate there.
🪄 Autofix (Beta)

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: 4277ad23-1519-40e9-a669-941011a774b2

📥 Commits

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

📒 Files selected for processing (5)
  • examples/rss-reader/src/index.tsx
  • examples/showcase/src/index.tsx
  • examples/widget-gallery/src/index.ts
  • packages/ui/src/TreeSelect.ts
  • scripts/build-registry.ts

Comment on lines +30 to +35
const codePoint = Number.parseInt(entity.slice(2, 10), 16);
return Number.isFinite(codePoint) ? String.fromCodePoint(codePoint) : match;
}

if (entity.startsWith('#')) {
const codePoint = Number.parseInt(entity.slice(1), 10);
const codePoint = Number.parseInt(entity.slice(1, 10), 10);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

node -e 'for (const value of [0xFFFFFFFF, 99999999]) { try { String.fromCodePoint(value); process.exit(1); } catch {} }'

Repository: Karanjot786/TermUI

Length of output: 156


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'Files matching index.tsx:\n'
fd -a 'index\.tsx$' . | sed 's#^\./##'

printf '\nContext around examples/rss-reader/src/index.tsx lines 1-80:\n'
if [ -f examples/rss-reader/src/index.tsx ]; then
  nl -ba examples/rss-reader/src/index.tsx | sed -n '1,80p'
else
  echo 'examples/rss-reader/src/index.tsx not found'
fi

printf '\nSearch for entity decoding functions/usages:\n'
rg -n "fromCodePoint|parseEntity|entity|Number\.parseInt|slice\(1, 10\)|slice\(2, 10\)" examples/rss-reader/src/index.tsx .

Repository: Karanjot786/TermUI

Length of output: 2185


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'File size:\n'
wc -l examples/rss-reader/src/index.tsx 2>/dev/null || true

printf '\nContext around examples/rss-reader/src/index.tsx lines 1-80:\n'
sed -n '1,80p' examples/rss-reader/src/index.tsx

printf '\nSearch for entity decoding terms in repository:\n'
rg -n "fromCodePoint|Number\.parseInt|slice\(1, 10\)|slice\(2, 10\)|&#" examples/rss-reader/src/index.tsx || true

printf '\nBehavioral probes for String.fromCodePoint:\n'
node - <<'JS'
const inputs = [0xFFFFFFFF, 99999999, 0x10FFFF, 0x110000, 0];
for (const value of inputs) {
  try {
    const s = String.fromCodePoint(value);
    console.log(`${value} => finite=${Number.isFinite(value)} => "${s}" (code=${s.codePointAt(0)?.toString(16).toUpperCase()})`);
  } catch (e) {
    console.log(`${value} => finite=${Number.isFinite(value)} => throws ${e.name}: ${e.message}`);
  }
}
JS

Repository: Karanjot786/TermUI

Length of output: 3268


Validate the Unicode range and entity length before replacing the entity.

Number.isFinite does not validate a Unicode code point. Inputs such as &#xFFFFFFFF; or &#99999999; can pass this check and make String.fromCodePoint throw RangeError. Reject values outside 0..0x10FFFF and reject entities longer than eight digits so the decoder does not decode a truncated prefix as a different code point.

🤖 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 `@examples/rss-reader/src/index.tsx` around lines 30 - 35, Update the
entity-decoding logic around the codePoint parsing and replacement branches to
validate the full numeric entity before calling String.fromCodePoint: require
1–8 digits, ensure the value is finite and within 0..0x10FFFF, and return the
original match for invalid or oversized entities. Apply the same validation to
both hexadecimal and decimal entities, preventing truncated prefixes from being
decoded.

Comment on lines +185 to +186
const sortedA = [...a].sort((a, b) => a - b);
const sortedB = [...b].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 | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== files =="
git ls-files 'packages/ui/src/TreeSelect.ts' 'scripts/build-registry.ts' 'tsconfig*.json' 2>/dev/null || true

echo
echo "== package type settings =="
for f in $(git ls-files 'tsconfig*.json' 'packages/**/tsconfig*.json' 'scripts/**/tsconfig*.json' 2>/dev/null | head -50); do
  echo "--- $f"
  sed -n '1,220p' "$f" | rg -n '"strict"|"moduleResolution"|"noImplicitAny"|"target"|"lib"|compilerOptions' || true
done

echo
echo "== TreeSelect relevant lines =="
sed -n '1,240p' packages/ui/src/TreeSelect.ts 2>/dev/null || true

echo
echo "== build-registry relevant lines =="
sed -n '1,120p' scripts/build-registry.ts 2>/dev/null || true

echo
echo "== occurrences =="
rg -n "sort\\(\\(a, b\\) => a - b\\)|sort\\(\\(a, b\\) =>" -S packages/ui/src scripts/build-registry.ts packages 2>/dev/null || true

echo
echo "== TypeScript availability/parser probe =="
node -e "const fs=require('node:fs'); for (const p of ['packages/ui/src/TreeSelect.ts','scripts/build-registry.ts']) console.log(p, 'exists', fs.existsSync(p));"
if command -v npx >/dev/null 2>&1; then
  echo "npx available"
  npx tsc --version 2>/dev/null || true
else
  echo "npx unavailable"
fi

python3 - <<'PY'
import subprocess, textwrap, json, re, os
files = ['packages/ui/src/TreeSelect.ts','scripts/build-registry.ts']
for f in files:
    print(f"--- {f}")
    data = open(f,'r').read()
    for i,line in enumerate(data.splitlines(),1):
        if 'sort((a, b) => a - b)' in line:
            print(f"{i}:{line}")
PY

Repository: Karanjot786/TermUI

Length of output: 15092


🏁 Script executed:

#!/bin/bash
set -euo pipefail

node - <<'JS'
const values = {
  zero: ['0', '0'],
  numerics: ['1', '10', '2'],
  packages: ['`@termuijs/core`', '`@termuijs/widgets`'],
  mixed_nonnumeric: ['abc', '1'],
};
for (const [name, arr] of Object.entries(values)) {
  const withSubtract = arr.slice().sort((a, b) => a - b);
  const withLocaleCompare = arr.slice().sort((a, b) => a.localeCompare(b));
  console.log(name, 'input', JSON.stringify(arr), 'subtract', JSON.stringify(withSubtract), 'localeCompare', JSON.stringify(withLocaleCompare));
}
JS

TS_VERSION=$(npx tsc --version 2>/dev/null | awk '{print $2}' || true)
tmpdir=${PWD}/tmp-ts-string-subtract-probe
rm -rf "$tmpdir"
mkdir -p "$tmpdir"
cat > "$tmpdir/comparators.ts" <<'TS'
function subtract(a: string, b: string): number { return a - b; }
subtract('0', '0');
subtract('1', '10');
function localeCompare(a: string, b: string): number { return a.localeCompare(b); }
localeCompare('0', '0');
localeCompare('1', '10');
TS
cat > "$tmpdir/tsconfig.json" <<'JSON'
{
  "compilerOptions": {
    "target": "ES2022",
    "moduleResolution": "bundler",
    "lib": ["ES2022"],
    "strict": true,
    "noEmit": true
  },
  "files": ["comparators.ts"]
}
JSON
cd "$tmpdir"
timeout 60 npx tsc --showConfig 2>/dev/null | sed -n '1,120p' || true
echo "--- tsc output -----------------------"
timeout 60 npx tsc 2>&1 | sed -n '1,200p' || true
rm -rf "$tmpdir"

Repository: Karanjot786/TermUI

Length of output: 621


🏁 Script executed:

#!/bin/bash
set -euo pipefail

node - <<'JS'
const values = {
  zero: ['0', '0'],
  numerics: ['1', '10', '2'],
  packages: ['`@termuijs/core`', '`@termuijs/widgets`'],
  mixed_nonnumeric: ['abc', '1'],
};
for (const [name, arr] of Object.entries(values)) {
  const withSubtract = arr.slice().sort((a, b) => a - b);
  const withLocaleCompare = arr.slice().sort((a, b) => a.localeCompare(b));
  console.log(name, 'input', JSON.stringify(arr), 'subtract', JSON.stringify(withSubtract), 'localeCompare', JSON.stringify(withLocaleCompare));
}
JS

TS_VERSION=$(npx tsc --version 2>/dev/null | awk '{print $2}' || true)
tmpdir=${PWD}/tmp-ts-string-subtract-probe
rm -rf "$tmpdir"
mkdir -p "$tmpdir"
cat >("$tmpdir/comparators.ts") <<'TS'
function subtract(a: string, b: string): number { return a - b; }
subtract('0', '0');
subtract('1', '10');
function localeCompare(a: string, b: string): number { return a.localeCompare(b); }
localeCompare('0', '0');
localeCompare('1', '10');
TS
cat >"$tmpdir/tsconfig.json" <<'JSON'
{
  "compilerOptions": {
    "target": "ES2022",
    "moduleResolution": "bundler",
    "lib": ["ES2022"],
    "strict": true,
    "noEmit": true
  },
  "files": ["comparators.ts"]
}
JSON
cd "$tmpdir"
timeout 60 npx tsc --showConfig 2>/dev/null | sed -n '1,120p' || true
echo "--- tsc output -----------------------"
timeout 60 npx tsc 2>&1 | sed -n '1,200p' || true
rm -rf "$tmpdir"

Repository: Karanjot786/TermUI

Length of output: 688


Use string comparators instead of subtraction.

Both comparators operate on string values, and subtraction produces numeric ordering instead of the intended string order for nonnumeric values such as ['abc', '1']. Use String.prototype.localeCompare; for scripts/build-registry.ts, the default string sort is also sufficient.

🧰 Tools
🪛 GitHub Actions: CI / 0_build-and-test.txt

[error] 185-186: TypeScript declaration build failed: arithmetic operands on lines 185-186 are not typed as any, number, bigint, or an enum (TS2362, TS2363). The '@termuijs/ui' build command 'bun run build' / 'tsup' exited with code 1.

🪛 GitHub Actions: CI / build-and-test

[error] 185-186: TypeScript declaration build failed: arithmetic operands on lines 185-186 are not typed as any, number, bigint, or an enum type (TS2362/TS2363). The @termuijs/ui build command exited with code 1.

📍 Affects 2 files
  • packages/ui/src/TreeSelect.ts#L185-L186 (this comment)
  • scripts/build-registry.ts#L47-L47
🤖 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, Replace the
subtraction comparators in TreeSelect’s sortedA and sortedB sorting with
String.prototype.localeCompare to preserve string ordering for all values. Also
update the sorting expression at scripts/build-registry.ts line 47 to use the
default string sort, as no numeric comparator is appropriate there.

Source: Coding guidelines

@coderabbitai coderabbitai Bot mentioned this pull request Aug 2, 2026
4 tasks
@saurabhhhcodes saurabhhhcodes changed the title fix: code quality and safety improvements fix: resolve 2 bugs Aug 2, 2026
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