Skip to content

fix: resolve 4 bugs in termui - #3477

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

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

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes real bugs found in the codebase:

  • Removed redundant boolean comparison: x === true is equivalent to x (and x === false to !x), and shorter to read.
  • Replaced global isNaN with Number.isNaN: the global version coerces its argument, so isNaN('1') returns false while Number.isNaN is strict.
  • 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.

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

Summary by CodeRabbit

  • Bug Fixes
    • Prevented duplicate weather refresh timers, keeping updates on a consistent five-second interval.
    • Added clearer error logging when form-related operations fail.
    • Improved validation for numeric selections, ensuring invalid choices are handled more reliably.

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

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The changes manage the weather refresh interval, log rejected form promises, and replace global isNaN validation with Number.isNaN for prompt selections.

Changes

Reliability and validation fixes

Layer / File(s) Summary
Weather interval management
examples/weather/src/index.tsx
The weather example clears the existing interval before creating a new five-second interval.
Form rejection logging
packages/ui/src/Form.ts
Rejected Promise.all operations now log errors with the "Promise.all failed:" prefix.
Prompt selection validation
packages/ui/src/prompts.ts
promptSelect uses Number.isNaN when validating parsed selection input.

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 changes but omits the required package section, uses Ref: instead of Closes #, and leaves required checklist sections incomplete. Add all required template sections, identify the affected packages, link the issue with Closes #3476``, and complete the required checklist and GSSoC details.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies this pull request as a bug fix and summarizes its main purpose.
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: Move the rejection handling into the submit() method’s
awaited Promise.all flow, using try/catch or try/finally to reset _isValidating
and call markDirty() on rejection; remove the standalone trailing .catch
expression after protected _renderSelf(...).
🪄 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: 9a89c0be-632d-4be2-9ac7-d1d5ca41bd9d

📥 Commits

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

📒 Files selected for processing (3)
  • examples/weather/src/index.tsx
  • packages/ui/src/Form.ts
  • packages/ui/src/prompts.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:

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

Repository: Karanjot786/TermUI

Length of output: 2385


🏁 Script executed:

#!/bin/bash
set -euo pipefail
sed -n '60,155p' packages/ui/src/Form.ts
printf '\n--- syntax check ---\n'
node --check packages/ui/src/Form.ts 2>&1 || true

Repository: Karanjot786/TermUI

Length of output: 3623


Move the rejection handler inside submit().

The .catch(err => console.error(...)) after protected _renderSelf(...) is a standalone method call, not part of the awaited Promise.all. This makes Form.ts invalid TypeScript. Attach rejection handling to the Promise.all await with try/catch or try/finally, reset _isValidating, call markDirty(), and remove the trailing expression.

🧰 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: UI build failed during 'bun run build' (tsup/esbuild): unexpected '.' at '.catch(err => console.error("Promise.all failed:", err));'. TypeScript also reports malformed syntax, including missing ')' and ';'.

🪛 GitHub Actions: CI / build-and-test

[error] 142-142: The @termuijs/ui build (tsup/esbuild) failed with a syntax error: Unexpected "." at .catch(err => console.error("Promise.all failed:", err));. TypeScript also reports declaration/statement and missing try/) errors.

🤖 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, Move the rejection handling
into the submit() method’s awaited Promise.all flow, using try/catch or
try/finally to reset _isValidating and call markDirty() on rejection; remove the
standalone trailing .catch expression after protected _renderSelf(...).

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