fix: resolve 4 bugs in termui - #3454
Conversation
📝 WalkthroughWalkthroughThe AI streaming example now clears an existing interval before starting a new timer. The calculator example now uses ChangesAI streaming timer cleanup
Calculator numeric validation
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
examples/ai-streaming/src/index.tsxexamples/calculator/src/index.tsx
| clearInterval(window.__interval); window.__interval = setInterval(() => { | ||
| this._streamingText.tick(); | ||
| }, 50); |
There was a problem hiding this comment.
🩺 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 -300Repository: 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.
Description
This PR fixes real bugs found in the codebase:
trim()to''misses whitespace-only input;.trim().length === 0is explicit.isNaNwithNumber.isNaN: the global version coerces its argument, soisNaN('1')returns false whileNumber.isNaNis strict.x === trueis equivalent tox(andx === falseto!x), and shorter to read.Type of Change
How Has This Been Tested?
Checklist
Related Issue
Ref: #3453
Summary by CodeRabbit