Skip to content

fix: resolve 4 bugs in termui - #3612

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

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

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Aug 6, 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.
  • Simplified empty-string validation: comparing trim() to '' misses whitespace-only input; .trim().length === 0 is explicit.
  • Added rejection handler to Promise.all: an unhandled rejection in any input promise previously crashed silently.
  • 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: #3611

Summary by CodeRabbit

  • Bug Fixes
    • Improved streaming behavior by preventing overlapping update timers.
    • Chat content now handles whitespace-only lines correctly.
    • Form submission failures are reported more clearly in the console.
    • Improved switch animation stability, preventing minor positioning issues at certain values.

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

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The changes update interval cleanup, whitespace-only paragraph parsing, Promise rejection logging, and floating-point rounding in switch animation positioning.

Changes

Example behavior fixes

Layer / File(s) Summary
Example runtime and parsing updates
examples/ai-streaming/src/index.tsx, examples/chat-app/src/index.tsx
The streaming example clears the existing interval before creating a new one. The chat parser treats whitespace-only lines as empty paragraphs.

UI behavior fixes

Layer / File(s) Summary
UI error and rendering updates
packages/ui/src/Form.ts, packages/ui/src/Switch.ts
Form operations log rejected Promise.all calls. Switch knob positioning adds Number.EPSILON before rounding.

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 changes and testing, but it omits the required package section and uses Ref: #3611`` instead of Closes #. Add the package list, use the required Closes #3611`` issue reference, and complete the required checklist sections.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the four bug fixes 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.6)
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

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

117-117: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add a regression test for the rounding boundaries.

The existing test only verifies that rendering stays within the widget width. Add an assertion for knob positions near the 0.5 and 1.5 rounding thresholds to verify the Number.EPSILON fix.

🤖 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/Switch.ts` at line 117, Add a regression test covering the
rounding boundaries used by knobPos in Switch rendering: verify values just
below and above 0.5 and 1.5 produce the expected rounded knob positions,
including the Number.EPSILON adjustment. Keep the existing width-boundary
assertion and target the test for the Switch rendering behavior.
🤖 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: Fix the validation flow around Promise.all so the
rejection handler is attached to await Promise.all(validationPromises) rather
than left as a standalone .catch expression. On rejection, reset _isValidating,
call markDirty(), and return before processing results; remove the detached
handler so Form.ts parses correctly.

---

Nitpick comments:
In `@packages/ui/src/Switch.ts`:
- Line 117: Add a regression test covering the rounding boundaries used by
knobPos in Switch rendering: verify values just below and above 0.5 and 1.5
produce the expected rounded knob positions, including the Number.EPSILON
adjustment. Keep the existing width-boundary assertion and target the test for
the Switch rendering behavior.
🪄 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: ec1cefb4-63bc-4cfd-93ea-b30abbb34e6e

📥 Commits

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

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

Attach the rejection handler to Promise.all.

Line 142 is a standalone .catch(...) expression, so the file does not parse. The handler is also detached from the Promise.all call at Line 83.

Move the error handling to a try/catch around await Promise.all(validationPromises) or chain it directly to that promise. On rejection, reset _isValidating, call markDirty(), and return before processing results.

🧰 Tools
🪛 Biome (2.5.6)

[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: @termuijs/ui build failed during tsup/esbuild and TypeScript declaration generation. Unexpected '.' at the start of '.catch(err => console.error("Promise.all failed:", err));', causing syntax errors and exit code 1.

🪛 GitHub Actions: CI / build-and-test

[error] 142-142: The @termuijs/ui build failed during tsup/esbuild parsing due to an unexpected '.' at the start of '.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, Fix the validation flow
around Promise.all so the rejection handler is attached to await
Promise.all(validationPromises) rather than left as a standalone .catch
expression. On rejection, reset _isValidating, call markDirty(), and return
before processing results; remove the detached handler so Form.ts parses
correctly.

Source: Linters/SAST tools

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