fix: clear terminal buffers when switching between projects#26318
Open
lyy-pineapple wants to merge 2 commits into
Open
fix: clear terminal buffers when switching between projects#26318lyy-pineapple wants to merge 2 commits into
lyy-pineapple wants to merge 2 commits into
Conversation
When switching to a different directory/project, stale terminal buffers persisted from a previous session were being restored, causing old terminal output to appear mixed with new output. This adds a trimAll() call on the new workspace when the directory changes, ensuring fresh terminal state on project switch. Fixes anomalyco#26316
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Author
|
@adamdotdevin Can you help review this? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #26316
Type of change
What does this PR do?
When switching between projects (directories) in the web UI, stale terminal buffers persisted from a previous session were being restored, causing old terminal output to appear mixed with new output.
The root cause:
packages/app/src/context/terminal.tsxcallstrimAll()on the previous workspace when navigating away, but does NOT clear stale buffers on the new workspace. When the terminal component mounts, it restores from persisted buffer data that belongs to an old PTY session, displaying garbage before the new PTY connection delivers fresh content.The fix adds a
workspace().trimAll()call whennext.dir !== prev.dir, clearing persisted terminal buffers on the destination workspace when switching to a different directory. This is a targeted 3-line change in the existingcreateEffectthat already handles workspace transitions.How did you verify your code works?
opencode web, opened terminal in Project A, executed commandstrimAll()function correctly stripsbuffer,cursor, andscrollYwhile preserving terminal identity (id,title,titleNumber)Screenshots / recordings
N/A — no UI component changes, only state management logic.
Checklist