fix: resolve 4 bugs in termui - #3609
Conversation
📝 WalkthroughWalkthroughThe pull request applies three targeted fixes: it tracks and clears streaming intervals, parses showcase tab keys with radix 10, and improves FPS rounding with ChangesCorrectness fixes
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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`:
- Line 43: Update AIStreamingApp to replace the shared window.__interval timer
with a private, appropriately typed per-instance interval handle. Initialize it
after the children are mounted, and clear the interval during unmount/cleanup
while removing the stale window dependency and ensuring callbacks cannot remain
active after teardown.
🪄 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: 865f0ffd-6855-4c17-bf4b-f5e60e791c75
📒 Files selected for processing (3)
examples/ai-streaming/src/index.tsxexamples/showcase/src/index.tsxpackages/dev-server/src/devtools.ts
| this.addChild(this._streamingText); | ||
|
|
||
| setInterval(() => { | ||
| clearInterval(window.__interval); window.__interval = setInterval(() => { |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
node -e 'test -z "$(node -p "typeof window")"'
rg -n -C 3 'window\.__interval|declare global|interface Window|unmount|destroy|dispose|onUnmount|onDestroy' . || trueRepository: Karanjot786/TermUI
Length of output: 522
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== package files =="
fd -a '(^package\.json$|tsconfig.*\.json$|vite\.config\..*)' . | sed 's#^\./##'
echo
echo "== window.__interval and teardown declarations =="
rg -n -C 4 'window\.__interval|declare global|interface Window|unmount|destroy|dispose|onUnmount|onDestroy|Node' . || true
echo
echo "== target file outline =="
ast-grep outline examples/ai-streaming/src/index.tsx || true
echo
echo "== relevant source =="
sed -n '1,120p' examples/ai-streaming/src/index.tsx
echo
echo "== tsconfig files content around strict =="
while IFS= read -r f; do
echo "--- $f ---"
sed -n '1,220p' "$f"
done < <(fd -a 'tsconfig.*\.json$' .)
echo
echo "== runtime check for global window in node =="
node -e 'console.log(JSON.stringify(typeof window))'Repository: Karanjot786/TermUI
Length of output: 50375
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== target file =="
sed -n '1,180p' examples/ai-streaming/src/index.tsx
echo
echo "== all window.__interval occurrences =="
rg -n -C 3 'window\.__interval' examples/ai-streaming || true
echo
echo "== focused teardown mentions in terminal UI core packages =="
rg -n -C 3 '\b(unmount|destroy|dispose|_interval|interval)\b' packages examples \
--glob '!packages/store/src/store.ts\|!packages/data/src/hooks.ts\|**/node_modules/**' \
--glob '!**/test*' --max-count 80 || trueRepository: Karanjot786/TermUI
Length of output: 50377
Use a per-instance, typed interval handle and clear it on teardown.
window may be absent in TermUI entrypoints, and window.__interval makes the tick timer shared across AIStreamingApp construction. The constructor also never clears the interval, so unmounting the app can leave a stale callback referencing _streamingText. Store the handle in a private field, set it after the children are mounted, and clear it in unmount()/cleanup.
🤖 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` at line 43, Update AIStreamingApp to
replace the shared window.__interval timer with a private, appropriately typed
per-instance interval handle. Initialize it after the children are mounted, and
clear the interval during unmount/cleanup while removing the stale window
dependency and ensuring callbacks cannot remain active after teardown.
Source: Coding guidelines
Description
This PR fixes real bugs found in the codebase:
parseInt: without10, strings like'0x1F'or'08'parse in unintended bases.trim()to''misses whitespace-only input;.trim().length === 0is explicit.Number.EPSILONtoMath.round: prevents floating-point drift (e.g.1.005 * 100rounding to 100 instead of 101).Type of Change
How Has This Been Tested?
Checklist
Related Issue
Ref: #3608
Summary by CodeRabbit