Repository navigation
fix(app): keep side panel terminals alive across panel and thread switches - #7726
danteregis wants to merge 1 commit into
Conversation
|
Thanks for the pull request, @danteregis. It was closed automatically because it does not meet the requirements below yet. This is an automated check, not a review of the change. Contributor approval. bb reviews pull requests only from approved contributors, and you are not on the list yet. Join the #contributors channel in Discord (https://discord.gg/kvBU6tJhcJ), post a link to your pull request, and explain what it changes and why. A maintainer then adds you to the list and reopens the pull request. See CONTRIBUTING.md for details. |
|
Thanks for the fix and the analysis in #7724. PR #7801 continues this change: its first commit is this PR's commit, with you as its author. A review and a browser test of this PR found three items, which #7801 fixes:
The PR body of #7801 has the before and after measurements.
|
Human comments
What was wrong
The secondary panel renders content only for its active tab. So a terminal unmounts when the user switches to another panel tab, such as Browser, or to another thread.
ThreadTerminalViewdisposes its xterm instance and itsTerminalWebSocketTransporton unmount. On return it builds both again, connects withsinceSeq=0, and the server replays up to 512 KB of history. The user waits for the reconnect and watches the replay scroll by. Details and permalinks are in #7724.What changed
apps/app/src/components/thread/terminal/terminal-runtime-cache.ts. It is a small LRU of parked terminal runtimes, keyed by terminal id. It keeps at most 8. Parking a 9th disposes the oldest. It has no imports.ThreadTerminalView.tsx:keepAliveprop,falseby default.ThreadTerminalContentpassestrue. Onboarding keeps today's behavior.mountThreadTerminalnow builds a runtime: the xterm instance, its addons, the transport, and a wrapper element.liveRef.liveRefis updated in a layout effect, so a reused runtime never calls the setters of a view that has unmounted.keepAlive, a running session and noexitedmessage is parked: its element is removed, the selection is cleared, andtransport.setVisible(false)is called. Otherwise it is disposed as before.exited, or an error with codeterminal_exited,terminal_not_foundorterminal_not_running.terminal-cache-owner.ts: evicts the parked runtime when a session goes missing or closes as exited.false. The server then does not let that client govern PTY flow control. The parked xterm keeps parsing output and acknowledging it, so it is current when it comes back.How you verified
terminal-runtime-cache.test.ts: take, park, LRU eviction and evict.ThreadTerminalView.keepalive.test.tsx: unmount and remount reuse one transport and the same xterm element, and callsetVisible(false)on park. Anexitedmessage while parked disposes the runtime.keepAlive={false}still disposes. An unmount before the async mount finishes creates nothing.terminal-cache-owner.test.ts: close and missing-session eviction.main'sThreadTerminalView.tsxrestored, the keep-alive reuse test fails. With this change, all 4 tests in that file pass.pnpm exec turbo run typecheck --filter=@bb/apppasses.src/components/thread/terminal,src/hooks/cache-ownersandbundle-budget.test.ts: 241 tests.oxfmt --checkandoxlintare clean on the changed files.pnpm exec turbo run build --filter=@bb/apppasses, including the React Compiler check.desktop-v0.49.0, was built and installed in a 0.49.0 desktop setup connected to a remote server. Returning to a terminal from the Browser tab and from another thread was instant, with no replay, and live output kept arriving while the terminal was hidden. This port tomainhas passed the automated checks only. It has not been run in the app.Fixes #7724