Skip to content

fix(xterm): dispose Terminal on unmount - #2067

Merged
openai0229 merged 3 commits into
OtterMind:mainfrom
Aias00:fix/2059-xterm-dispose
Jul 24, 2026
Merged

fix(xterm): dispose Terminal on unmount#2067
openai0229 merged 3 commits into
OtterMind:mainfrom
Aias00:fix/2059-xterm-dispose

Conversation

@Aias00

@Aias00 Aias00 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Related issue

Closes #2059

Summary

The Xterm mount useEffect called initXterm() which creates a new Terminal(), loads a FitAddon, registers xterm.onData(...), and calls xterm.open(...). The cleanup only removed the window resize listener — it never called xterm.dispose(), so every mount/unmount leaked a full Terminal instance (DOM, renderer, buffers, internal timers), plus the onData disposable and the FitAddon. Added xtermRef.current?.dispose() to the cleanup (dispose() also disposes loaded addons and event listeners), and reset the refs.

Affected surfaces

  • Frontend / Web
  • Backend / API / Storage
  • Database plugin / Driver
  • JCEF / Desktop packaging
  • CI / Build / Release
  • Documentation only

Verification

  • Commands and results:
    • npx tsc --noEmit -p chat2db-community-client/tsconfig.json — no errors for Xterm/index.tsx.
    • npx eslint src/components/Xterm/index.tsx — no errors.
  • Manual verification: On unmount, xterm.dispose() is now called, tearing down the Terminal, the loaded FitAddon, and the onData listener.
  • UI evidence: N/A

Risk and compatibility

  • Public API or stored data: N/A.
  • Database or driver compatibility: N/A.
  • Network, privacy, or security: N/A.
  • Community / Local / Pro boundary: N/A.
  • Backward compatibility: Only adds cleanup on unmount; mount/render behavior unchanged.

Reviewer map

  • Start here: components/Xterm/index.tsx — the useEffect([], ) cleanup now calls xtermRef.current?.dispose() and resets xtermRef/fitAddonRef to null.
  • Failure condition: Terminal instances still leak across mount/unmount.
  • Rollback or disable path: Revert this single commit.

Contributor declaration

  • I linked the Issue that defines this change.
  • I tested the affected behavior and reported the actual results above.
  • I did not include credentials, private data, or generated build output.
  • I disclosed substantial AI assistance below, or this PR contains no substantial AI-generated code.

AI assistance: The fix, verification, and PR description were produced with Claude Code assistance.

The mount effect created a Terminal, loaded a FitAddon, registered an
onData handler, and opened it, but cleanup only removed the resize
listener. Every unmount leaked a full Terminal instance (DOM, renderer,
buffers, timers). Dispose the terminal in cleanup; dispose also tears
down the loaded addon and onData listener.

Fixes OtterMind#2059

Co-Authored-By: Claude <noreply@anthropic.com>
@Aias00
Aias00 requested a review from openai0229 as a code owner July 24, 2026 14:56
Copilot AI review requested due to automatic review settings July 24, 2026 14:56

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@openai0229 openai0229 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the terminal disposal cleanup on unmount. LGTM.

@openai0229
openai0229 merged commit 936dcb4 into OtterMind:main Jul 24, 2026
15 of 16 checks passed
@openai0229 openai0229 moved this from In Review to Done in Chat2DB Community Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Xterm Terminal instance is never disposed on unmount

3 participants