Repository navigation
fix: clean up editor/terminal state when removing a worktree - #532
Merged
nwparker merged 1 commit intoApr 13, 2026
Merged
Conversation
nwparker
force-pushed
the
fix/remove-worktree-state-cleanup
branch
from
April 13, 2026 04:53
9bf6b3d to
f5b9501
Compare
removeWorktree already cleaned up openFiles, terminal layouts, browser tabs, and several worktree-keyed maps, but four state properties leaked indefinitely after a worktree was deleted: - editorDrafts — unsaved draft content keyed by file ID - markdownViewMode — rich/source toggle keyed by file ID - expandedDirs — file explorer expansion state keyed by worktree ID - activeTabIdByWorktree — remembered terminal tab keyed by worktree ID Over a long session with many worktree create/delete cycles these accumulated entries consume memory and can never be reclaimed because the corresponding file and worktree IDs no longer exist in openFiles or worktreesByRepo. The fix collects the file IDs of the removed worktree's open files and deletes their editorDrafts and markdownViewMode entries, then removes the worktree's expandedDirs and activeTabIdByWorktree entries. A shallow copy is only created when there are actually entries to remove, preserving the no-op identity check that existing tests rely on. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
nwparker
force-pushed
the
fix/remove-worktree-state-cleanup
branch
from
April 13, 2026 05:15
f5b9501 to
c269f90
Compare
brennanb2025
added a commit
that referenced
this pull request
Apr 19, 2026
Adds Playwright coverage for two high-regression areas identified from the last 200 PRs: - worktree-lifecycle.spec.ts: guards removeWorktree cleanup (#532), worktree switch with right sidebar open (#598/#628/#726), and cross-worktree tab isolation (#542/#554). - tab-close-navigation.spec.ts: guards visual-neighbor activation on editor/diff close (#693) and Landing fallback when the last visible surface closes (#677).
3 tasks done
enrick-dev
pushed a commit
to enrick-dev/orca
that referenced
this pull request
Oct 15, 2026
…i#532) removeWorktree already cleaned up openFiles, terminal layouts, browser tabs, and several worktree-keyed maps, but four state properties leaked indefinitely after a worktree was deleted: - editorDrafts — unsaved draft content keyed by file ID - markdownViewMode — rich/source toggle keyed by file ID - expandedDirs — file explorer expansion state keyed by worktree ID - activeTabIdByWorktree — remembered terminal tab keyed by worktree ID Over a long session with many worktree create/delete cycles these accumulated entries consume memory and can never be reclaimed because the corresponding file and worktree IDs no longer exist in openFiles or worktreesByRepo. The fix collects the file IDs of the removed worktree's open files and deletes their editorDrafts and markdownViewMode entries, then removes the worktree's expandedDirs and activeTabIdByWorktree entries. A shallow copy is only created when there are actually entries to remove, preserving the no-op identity check that existing tests rely on. Co-authored-by: Test User <test@example.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
removeWorktreewhere four state properties were never cleaned up after a worktree deletioneditorDrafts(unsaved content keyed by file ID),markdownViewMode(rich/source toggle),expandedDirs(file explorer state), andactiveTabIdByWorktree(remembered terminal tab) all accumulated orphaned entries indefinitelyopenFilesorworktreesByRepoChanges
src/renderer/src/store/slices/worktrees.ts— In theremoveWorktreeset()callback:editorDraftsandmarkdownViewModeentriesexpandedDirsandactiveTabIdByWorktreeentriessrc/renderer/src/store/slices/worktrees.test.ts— Added 5 new tests:editorDraftsfor files in the removed worktreemarkdownViewModefor files in the removed worktreeexpandedDirsfor the removed worktreeactiveTabIdByWorktreefor the removed worktreeTest plan
pnpm typecheckpasses with no new errorspnpm lintpasses with 0 errorsNo visual change — this is a pure state management bug fix.
🤖 Generated with Claude Code