Skip to content

fix: resolve 4 bugs in termui - #3414

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

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

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes real bugs found in the codebase:

  • 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.
  • Simplified empty-string validation: comparing trim() to '' misses whitespace-only input; .trim().length === 0 is explicit.
  • Added Number.EPSILON to Math.round: prevents floating-point drift (e.g. 1.005 * 100 rounding to 100 instead of 101).

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

Summary by CodeRabbit

  • Bug Fixes
    • Prevented duplicate streaming update timers from running simultaneously.
    • Added error logging when form-related asynchronous operations fail.

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

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The streaming example now clears an existing interval before creating another. The form promise chain now logs rejected Promise.all operations with console.error.

Changes

Streaming timer lifecycle

Layer / File(s) Summary
Reset streaming interval
examples/ai-streaming/src/index.tsx
The constructor clears the stored interval before assigning a new timer.

Form promise error handling

Layer / File(s) Summary
Log promise failures
packages/ui/src/Form.ts
A catch handler logs Promise.all failures with console.error.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Suggested reviewers: karanjot786

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description explains the four fixes and includes change type, testing, checklist, and an issue reference.
Title check ✅ Passed The title accurately identifies a fix for four TermUI bugs 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/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/ui/src/Form.ts`:
- Around line 141-142: Remove the dangling .catch after the Form class. In
Form.submit(), handle rejection from await Promise.all(validationPromises)
within the method and use finally to reset _isValidating and call markDirty()
when validation handling is required.
🪄 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: 9366e070-4724-453e-aef7-78fa23507838

📥 Commits

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

📒 Files selected for processing (2)
  • examples/ai-streaming/src/index.tsx
  • packages/ui/src/Form.ts

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:

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

bunx biome check packages/ui/src/Form.ts
rg -n -C 8 'Promise\.all|Promise\.all failed|\.catch' packages/ui/src/Form.ts

Repository: Karanjot786/TermUI

Length of output: 198


🏁 Script executed:

<scratchpad_start>
[task review_file_1/1 verify_comment_1/2]
[observations]
- Initial execution failed because `bunx` is not available in the sandbox.
[analysis]
- Need inspect `packages/ui/src/Form.ts` around the reported lines and surrounding method.
[pending]
- Determine source syntax shape around `Promise.all` and `.catch`.
- Determine whether parsing concern and validation-state cleanup concern hold.
[actions]
- Read relevant sections of `packages/ui/src/Form.ts`.
- Use a read-only static parser/TypeScript compiler diagnostic if available.
[done]
[scratchpad_end] -->

Repository: Karanjot786/TermUI

Length of output: 250


🏁 Script executed:

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

echo "== file exists and size =="
wc -l packages/ui/src/Form.ts

echo "== relevant submit section =="
sed -n '60,155p' packages/ui/src/Form.ts

echo "== search validators/promises =="
rg -n -C 4 'isValidating|submit|Promise\.all|\.catch|markDirty' packages/ui/src/Form.ts

echo "== static parser diagnostics if typescript available =="
if command -v tsc >/dev/null 2>&1; then
  tsc --noEmit --strict packages/ui/src/Form.ts || true
else
  echo "tsc not available"
fi
if command -v node >/dev/null 2>&1; then
  node - <<'JS' || true
const {parse} = require('`@typescript-eslint/parser`');
const fs = require('node:fs');
try {
  parse(fs.readFileSync('packages/ui/src/Form.ts','utf8'), {ecmaVersion: 2024, sourceType: 'module'});
  console.log('typescript-eslint parser: ok');
} catch (e) {
  console.log(e && e.message);
}
JS
fi

Repository: Karanjot786/TermUI

Length of output: 8398


Remove the dangling .catch after Form.

packages/ui/src/Form.ts:142 is outside the Form class body and is not attached to an expression, so the file is invalid TypeScript. If validation rejection handling is needed, wrap the await Promise.all(validationPromises) call inside submit() and reset _isValidating / call markDirty() in a finally block.

🧰 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: The @termuijs/ui build failed during 'tsup' because '.catch(err => console.error("Promise.all failed:", err));' is syntactically unexpected. TypeScript also reports missing try, closing parenthesis, and semicolon tokens.

🪛 GitHub Actions: CI / build-and-test

[error] 142-142: The @termuijs/ui build command 'tsup' failed due to an unexpected '.' in '.catch(err => console.error("Promise.all failed:", err));'. TypeScript also reported declaration/statement and syntax errors on this line.

🤖 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 dangling .catch
after the Form class. In Form.submit(), handle rejection from await
Promise.all(validationPromises) within the method and use finally to reset
_isValidating and call markDirty() when validation handling is required.

Sources: Coding guidelines, Linters/SAST tools

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