Skip to content

fix: resolve 4 bugs in termui - #3454

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

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

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes real bugs found in the codebase:

  • Simplified empty-string validation: comparing trim() to '' misses whitespace-only input; .trim().length === 0 is explicit.
  • Replaced global isNaN with Number.isNaN: the global version coerces its argument, so isNaN('1') returns false while Number.isNaN is strict.
  • Removed redundant boolean comparison: x === true is equivalent to x (and x === false to !x), and shorter to read.
  • Prevented interval leak: repeated mounts now clear the previous interval before scheduling a new one.

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

Summary by CodeRabbit

  • Bug Fixes
    • Prevented overlapping streaming timers to ensure text updates remain consistent.
    • Improved calculator validation for negative numeric inputs, avoiding incorrect results for non-numeric values.

@github-actions github-actions Bot added area:examples Example apps. 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 AI streaming example now clears an existing interval before starting a new timer. The calculator example now uses Number.isNaN for initial negative-number validation.

Changes

AI streaming timer cleanup

Layer / File(s) Summary
Streaming interval setup
examples/ai-streaming/src/index.tsx
The constructor clears the stored interval before creating the 50 ms streaming timer.

Calculator numeric validation

Layer / File(s) Summary
Negative-number validation
examples/calculator/src/index.tsx
safeEval converts the initial token to a number and checks it with Number.isNaN.

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

Possibly related PRs

Suggested reviewers: karanjot786

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies a bug-fix pull request and follows the required type: short description format.
Description check ✅ Passed The description explains the four fixes and testing, but it omits package details, GSSoC information, and several template checklist items.
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
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 `@examples/ai-streaming/src/index.tsx`:
- Around line 43-45: Update the AIStreamingApp constructor’s interval setup to
store the timer handle on the instance instead of window.__interval, and clear
any existing timer there. Override AIStreamingApp.unmount() to clear the
instance timer before calling super.unmount(), preventing tick() from running
after destruction.
🪄 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: d0c48177-15b2-49a8-a7bd-cf2576973469

📥 Commits

Reviewing files that changed from the base of the PR and between 6c7584e and 191bd96.

📒 Files selected for processing (2)
  • examples/ai-streaming/src/index.tsx
  • examples/calculator/src/index.tsx

Comment on lines +43 to 45
clearInterval(window.__interval); window.__interval = setInterval(() => {
this._streamingText.tick();
}, 50);

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:

#!/bin/bash
set -euo pipefail

rg -n -C 5 '\bunmount\s*\(' --glob '*.ts' --glob '*.tsx' .
rg -n -C 5 '__interval|setInterval\(|clearInterval\(' --glob '*.ts' --glob '*.tsx' .

Repository: Karanjot786/TermUI

Length of output: 50375


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== candidate file list =="
fd -a 'index\.tsx$|BaseWidget|Widget|render\.ts$' . | sed 's#^\./##' | head -200

echo
echo "== examples/ai-streaming/src/index.tsx outline and contents =="
if [ -f examples/ai-streaming/src/index.tsx ]; then
  wc -l examples/ai-streaming/src/index.tsx
  ast-grep outline examples/ai-streaming/src/index.tsx || true
  cat -n examples/ai-streaming/src/index.tsx
fi

echo
echo "== Widget base unmount definition =="
rg -n -C 8 'class .*Widget|unmount\(\)|super\.unmount\(\)' packages/widgets --glob '*.ts' --glob '*.tsx' | head -300

Repository: Karanjot786/TermUI

Length of output: 26187


Clear the streaming timer when AIStreamingApp is unmounted.

The constructor keeps the handle in window.__interval, so only a later instance can clear it. If AIStreamingApp is destroyed without another app replacing it, the 50 ms timer keeps calling this._streamingText.tick() and retains the unmounted app. Store the handle on the instance and clear it from an overridden unmount() before calling super.unmount().

🤖 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/ai-streaming/src/index.tsx` around lines 43 - 45, Update the
AIStreamingApp constructor’s interval setup to store the timer handle on the
instance instead of window.__interval, and clear any existing timer there.
Override AIStreamingApp.unmount() to clear the instance timer before calling
super.unmount(), preventing tick() from running after destruction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:examples Example apps. type:bug +10 pts. Bug fix.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant