Skip to content

fix: resolve 4 bugs in termui - #3470

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

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

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.
  • Prevented interval leak: repeated mounts now clear the previous interval before scheduling a new one.
  • Added rejection handler to Promise.all: an unhandled rejection in any input promise previously crashed silently.
  • 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: #3469

Summary by CodeRabbit

  • Bug Fixes
    • Improved hexadecimal entity parsing for more predictable handling of long values.
    • Fixed weather updates so only one polling timer runs at a time.
    • Added error reporting when form-related asynchronous operations fail.
    • Corrected multi-select ordering for options with multi-digit positions, such as 2 and 10.

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

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

RSS hexadecimal parsing

Layer / File(s) Summary
Hexadecimal entity parsing
examples/rss-reader/src/index.tsx
Hexadecimal entity decoding now parses at most eight characters before conversion.

Weather polling lifecycle

Layer / File(s) Summary
Polling interval cleanup
examples/weather/src/index.tsx
The polling setup clears the stored interval before creating a new five-second interval.

Form promise error handling

Layer / File(s) Summary
Promise rejection logging
packages/ui/src/Form.ts
Rejected Promise.all operations are logged with console.error.

MultiSelect ordering

Layer / File(s) Summary
Numeric selected-option sorting
packages/ui/src/MultiSelect.ts
Selected option indices now sort numerically before mapping to options.

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

Possibly related PRs

Suggested reviewers: karanjot786, tomeshwari-02

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the fixes but omits required package, GSSoC, screenshots, reviewer notes, and checklist details, and does not use the required issue-closing format. Complete all required template sections and change the issue reference to the required closing format, such as Closes #3469``.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies a bug-fix pull request that addresses 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 💡 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/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

🧹 Nitpick comments (1)
packages/ui/src/MultiSelect.ts (1)

33-33: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a regression test for multi-digit indexes.

The numeric comparator is correct, but MultiSelect.test.ts:104-114 only covers indexes 0 through 2. A lexicographic sort would also pass that test. Add a case with at least 11 options, select index 10 before index 9, and assert that selectedOptions returns option 9 before option 10.

🤖 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/MultiSelect.ts` at line 33, Add a regression case in
MultiSelect.test.ts covering at least 11 options: select index 10 before index
9, then assert selectedOptions returns option 9 followed by option 10. Keep the
existing tests unchanged and target the selectedOptions behavior of MultiSelect.
🤖 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-31: Update the entity decoding logic around codePoint to parse
the full captured hexadecimal digit string, reject entities with more than eight
digits, and reject values above 0x10FFFF before calling String.fromCodePoint;
preserve returning match for invalid entities.

In `@packages/ui/src/Form.ts`:
- Around line 141-142: Remove the stray catch after the Form class closes so
Form.ts compiles. If rejection handling is required, attach it to the
Promise.all(validationPromises) flow inside submit(), reset _isValidating, call
markDirty(), and then return.

---

Nitpick comments:
In `@packages/ui/src/MultiSelect.ts`:
- Line 33: Add a regression case in MultiSelect.test.ts covering at least 11
options: select index 10 before index 9, then assert selectedOptions returns
option 9 followed by option 10. Keep the existing tests unchanged and target the
selectedOptions behavior of MultiSelect.
🪄 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: 6c9fe756-9071-4c39-99b1-d5caac173e5e

📥 Commits

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

📒 Files selected for processing (4)
  • examples/rss-reader/src/index.tsx
  • examples/weather/src/index.tsx
  • packages/ui/src/Form.ts
  • packages/ui/src/MultiSelect.ts

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

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:

node - <<'EOF'
for (const entity of ['`#x00000041FF`', '`#xFFFFFFFF`']) {
  const codePoint = Number.parseInt(entity.slice(2, 10), 16);
  try {
    console.log(entity, codePoint, String.fromCodePoint(codePoint));
  } catch (error) {
    console.log(entity, codePoint, error.name);
  }
}
EOF

Repository: Karanjot786/TermUI

Length of output: 207


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "File location and relevant lines:"
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

echo
echo "Search for decode helpers and usages:"
rg -n "decode|fromCodePoint|parseInt\\(|&`#x`|fromCharCode|value" examples/rss-reader/src packages -S 2>/dev/null | head -200 || true

echo
echo "Check for error boundaries/error handling in example and app:"
rg -n "ErrorBoundary|try|catch|fallback|error" examples/rss-reader/src -S 2>/dev/null || true

Repository: Karanjot786/TermUI

Length of output: 230


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "File location and relevant lines:"
if [ -f examples/rss-reader/src/index.tsx ]; then
  awk '{printf "%6d\t%s\n", NR, $0}' examples/rss-reader/src/index.tsx | sed -n '1,80p'
else
  echo "examples/rss-reader/src/index.tsx not found"
fi

echo
echo "Search for decode helpers and usages:"
rg -n "decode|fromCodePoint|parseInt\\(|&`#x`|fromCharCode|value" examples/rss-reader/src packages -S 2>/dev/null | head -200 || true

echo
echo "Check for error boundaries/error handling in example and app:"
rg -n "ErrorBoundary|try|catch|fallback|error" examples/rss-reader/src -S 2>/dev/null || true

Repository: Karanjot786/TermUI

Length of output: 25847


Validate the complete entity before conversion.

entity.slice(2, 10) silently discards hexadecimal digits after the eighth. For example, &#x00000041FF; is decoded as A. Also, &#xFFFFFFFF; produces a finite number outside the valid Unicode range, so String.fromCodePoint throws RangeError.

Use the full captured digit string for parseInt, reject sequences longer than eight digits, and reject values greater than 0x10FFFF before calling String.fromCodePoint.

🤖 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 - 31, Update the entity
decoding logic around codePoint to parse the full captured hexadecimal digit
string, reject entities with more than eight digits, and reject values above
0x10FFFF before calling String.fromCodePoint; preserve returning match for
invalid entities.

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '78,146p' packages/ui/src/Form.ts
rg -n -C 3 'Promise\.all|\.catch|_isValidating|markDirty' packages/ui/src/Form.ts

Repository: Karanjot786/TermUI

Length of output: 5634


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '1,146p' packages/ui/src/Form.ts

python3 - <<'PY'
from pathlib import Path
text = Path("packages/ui/src/Form.ts").read_text()
try:
    import black
except Exception as e:
    print(f"black unavailable: {type(e).__name__}: {e}")
    print("Unable to run black parser check.")
else:
    try:
        black.format_str(text, mode=black.Mode())
        print("black parse check: ok")
    except Exception as e:
        print("black parse check: failed")
        print(e)
PY

Repository: Karanjot786/TermUI

Length of output: 6748


Remove the stray .catch after Form closes.

The final }\n.catch(...) outside the class body is invalid TypeScript, so packages/ui/src/Form.ts cannot compile. If rejection handling is needed, attach it to the Promise.all(validationPromises) call inside submit(), then reset _isValidating and call markDirty() before returning.

🧰 Tools
🪛 Biome (2.5.5)

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

(parse)

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

[error] 142-142: tsup/esbuild build failed: Unexpected "." at .catch(err => console.error("Promise.all failed:", err));. The @termuijs/ui build command exited with code 1.

🪛 GitHub Actions: CI / build-and-test

[error] 142-142: The @termuijs/ui build failed during tsup/esbuild compilation بسبب an unexpected '.' in .catch(err => console.error("Promise.all failed:", err));.

🤖 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, Remove the stray catch after
the Form class closes so Form.ts compiles. If rejection handling is required,
attach it to the Promise.all(validationPromises) flow inside submit(), reset
_isValidating, call markDirty(), and then return.

Source: Linters/SAST tools

@saurabhhhcodes saurabhhhcodes mentioned this pull request Aug 4, 2026
4 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Aug 4, 2026
4 tasks
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