Skip to content

fix: resolve 4 bugs in termui - #3722

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

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

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes real bugs found in the codebase:

  • Added rejection handler to Promise.all: an unhandled rejection in any input promise previously crashed silently.
  • Prevented interval leak: repeated mounts now clear the previous interval before scheduling a new one.
  • Added explicit radix to parseInt: without 10, strings like '0x1F' or '08' parse in unintended bases.
  • Filled empty catch block: silently swallowing the error hides failures; now logs for debugging.

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

Summary by CodeRabbit

  • Bug Fixes
    • Improved streaming reinitialization to prevent duplicate active timers.
    • Improved numeric tab-key handling for more consistent navigation.
    • Enhanced error reporting during reload and form operations by logging previously hidden failures.
  • Developer Experience
    • Added clearer console diagnostics to help identify errors during development and troubleshooting.

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

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR clears stale streaming timers, makes tab-key parsing explicitly base 10, and logs rejected promises in the dev server and UI form. The dev-server rejection handler has invalid syntax.

Changes

Streaming timer lifecycle

Layer / File(s) Summary
Clear the existing streaming interval
examples/ai-streaming/src/index.tsx
The constructor clears the previous interval before starting a new 50 ms streaming interval.

Numeric tab parsing

Layer / File(s) Summary
Parse tab keys in base 10
examples/showcase/src/index.tsx
The tab-key parser now passes radix 10 to parseInt.

Promise rejection logging

Layer / File(s) Summary
Log rejected promises
packages/dev-server/src/server.ts, packages/ui/src/Form.ts
The reload flow and Promise.all flow now log rejection errors. The dev-server handler contains invalid syntax.

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

Possibly related PRs

Suggested reviewers: karanjot786

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the bug fixes but omits required template sections and does not provide a linked issue using the required format. Complete all required template sections, including packages, checklist items, GSSoC participation, screenshots or notes, and a linked issue using Closes #number``.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the four bug fixes in the pull request.
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.6)
packages/dev-server/src/server.ts

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

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: 1

🤖 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 rejection handler in
packages/dev-server/src/server.ts lines 383-383 by making the catch callback
accept the rejected error and log it. In packages/ui/src/Form.ts lines 141-142,
attach a rejection handler to the Promise.all expression or handle it with
try/catch, logging the failure error. Update the relevant promise-handling code
in both sites so the TypeScript parses correctly.
🪄 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: cb2b99be-ef75-427b-a770-e7f0e99bae62

📥 Commits

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

📒 Files selected for processing (4)
  • examples/ai-streaming/src/index.tsx
  • examples/showcase/src/index.tsx
  • packages/dev-server/src/server.ts
  • packages/ui/src/Form.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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail
npx biome check packages/dev-server/src/server.ts packages/ui/src/Form.ts

Repository: Karanjot786/TermUI

Length of output: 2385


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '--- server.ts context ---\n'
nl -ba packages/dev-server/src/server.ts | sed -n '370,390p'

printf '\n--- Form.ts context ---\n'
nl -ba packages/ui/src/Form.ts | sed -n '125,150p'

printf '\n--- syntax/statistic checks ---\n'
node - <<'JS'
const { readFileSync } = require('node:fs');
const { resolveConfigSync } = require('/root/.npm/_npx/79069e5e14faec0b/node_modules/@biomejs/biome');

const files = [
  'packages/dev-server/src/server.ts',
  'packages/ui/src/Form.ts',
];

for (const file of files) {
  const src = readFileSync(file, 'utf8');
  console.log(`FILE ${file}`);
  console.log(`contains catch(( =>`: /(catch)\s*\(\s*=>/.test(src));
  console.log(`contains Promise.all and .catch nearby:`);
  const lines = src.split('\n');
  for (let i = 0; i < lines.length; i++) {
    const line = lines[i];
    if (line.includes('Promise.all') || line.trim().startsWith('.catch')) {
      console.log(`${i + 1}: ${line}`);
    }
  }
  try {
    const _ = resolveConfigSync(__dirname, {});
    console.log('biome config: success');
  } catch (err) {
    console.log('biome config: ' + String(err.message || err));
  }
  try {
    // eslint is not available, so only use the parser package if present; otherwise print unavailable.
    const { parserOptions, parseSync } = resolveConfigSync(__dirname, {vcs: {enabled: false}});
    console.log(`parse ${file}: ${parseSync(file, src, {}).diagnostic?.message ?? 'ok'}`);
  } catch (err) {
    const msg = String(err && err.message || err);
    console.log(`parse ${file}: ${msg}`);
  }
}
JS

Repository: Karanjot786/TermUI

Length of output: 247


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- server.ts context ---'
nl -ba packages/dev-server/src/server.ts | sed -n '370,390p'

printf '%s\n' ''
printf '%s\n' '--- Form.ts context ---'
nl -ba packages/ui/src/Form.ts | sed -n '125,150p'

printf '%s\n' ''
printf '%s\n' '--- syntax/statistic checks ---'
node - <<'JS'
const { readFileSync } = require('node:fs');

const files = [
  'packages/dev-server/src/server.ts',
  'packages/ui/src/Form.ts',
];

for (const file of files) {
  const src = readFileSync(file, 'utf8');
  console.log(`FILE ${file}`);
  console.log(`contains malformed catch callback: ${/\b(catch)\s*\(\s*=>/.test(src)}`);
  console.log(`lines with Promise.all or .catch:`);
  const lines = src.split('\n');
  for (let i = 0; i < lines.length; i++) {
    const line = lines[i];
    if (line.includes('Promise.all') || line.trim().startsWith('.catch')) {
      console.log(`${i + 1}: ${line}`);
    }
  }
}
JS

Repository: Karanjot786/TermUI

Length of output: 222


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- server.ts context ---'
awk 'NR==370,NR==390 {printf "%6d\t%s\n", NR, $0}' packages/dev-server/src/server.ts

printf '%s\n' ''
printf '%s\n' '--- Form.ts context ---'
awk 'NR==125,NR==150 {printf "%6d\t%s\n", NR, $0}' packages/ui/src/Form.ts

Repository: Karanjot786/TermUI

Length of output: 2188


Fix the malformed Promise rejection handlers before merging.

These changes make the TypeScript files unparsable.

  • packages/dev-server/src/server.ts#L383: change catch( => console.error()) to catch((error) => console.error(error)) or equivalent.
  • packages/ui/src/Form.ts#L142: attach .catch((err) => console.error("Promise.all failed:", err)) to the Promise.all(...) expression it rejects, or move it into try/catch.
🧰 Tools
🪛 Biome (2.5.6)

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

(parse)

📍 Affects 2 files
  • packages/dev-server/src/server.ts#L383-L383 (this comment)
  • packages/ui/src/Form.ts#L141-L142
🤖 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 rejection
handler in packages/dev-server/src/server.ts lines 383-383 by making the catch
callback accept the rejected error and log it. In packages/ui/src/Form.ts lines
141-142, attach a rejection handler to the Promise.all expression or handle it
with try/catch, logging the failure error. Update the relevant promise-handling
code in both sites so the TypeScript parses correctly.

Source: Linters/SAST tools

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