Skip to content

fix: resolve 4 bugs in termui - #3609

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

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

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes real bugs found in the codebase:

  • Added explicit radix to parseInt: without 10, strings like '0x1F' or '08' parse in unintended bases.
  • Simplified empty-string validation: comparing trim() to '' misses whitespace-only input; .trim().length === 0 is explicit.
  • Added Number.EPSILON to Math.round: prevents floating-point drift (e.g. 1.005 * 100 rounding to 100 instead of 101).
  • 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: #3608

Summary by CodeRabbit

  • Bug Fixes
    • Improved streaming behavior by preventing duplicate interval timers.
    • Enhanced FPS display accuracy by avoiding rounding edge-case errors.
    • Made keyboard tab selection parsing more consistent across environments.

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

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The pull request applies three targeted fixes: it tracks and clears streaming intervals, parses showcase tab keys with radix 10, and improves FPS rounding with Number.EPSILON.

Changes

Correctness fixes

Layer / File(s) Summary
Streaming interval tracking
examples/ai-streaming/src/index.tsx
The constructor clears the existing interval and stores the newly created interval handle.
Showcase tab parsing
examples/showcase/src/index.tsx
Tab-key parsing now uses an explicit decimal radix.
FPS rounding
packages/dev-server/src/devtools.ts
FPS rounding adds Number.EPSILON before rounding to one decimal place.

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

Possibly related PRs

Suggested labels: type:bug

Suggested reviewers: karanjot786

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the fixes and testing, but it omits the package section and required checklist, GSSoC details, and issue-closing syntax. Add the missing template sections, complete the required checklist and GSSoC profile, list affected packages, and change the issue reference to Closes #3608``.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies this pull request as a fix for four TermUI bugs 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
🧪 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.

@github-actions github-actions Bot added the type:bug +10 pts. Bug fix. label Aug 6, 2026

@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`:
- 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

📥 Commits

Reviewing files that changed from the base of the PR and between 6c7584e and 453eef6.

📒 Files selected for processing (3)
  • examples/ai-streaming/src/index.tsx
  • examples/showcase/src/index.tsx
  • packages/dev-server/src/devtools.ts

this.addChild(this._streamingText);

setInterval(() => {
clearInterval(window.__interval); window.__interval = setInterval(() => {

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

node -e 'test -z "$(node -p "typeof window")"'
rg -n -C 3 'window\.__interval|declare global|interface Window|unmount|destroy|dispose|onUnmount|onDestroy' . || true

Repository: 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 || true

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

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

Labels

area:dev-server @termuijs/dev-server 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