Skip to content
This repository was archived by the owner on Feb 6, 2026. It is now read-only.

fix: diff failed to view because tabs showed old branch#124

Merged
matt2e merged 4 commits intomainfrom
matt2e/cant-view-diffs
Feb 6, 2026
Merged

fix: diff failed to view because tabs showed old branch#124
matt2e merged 4 commits intomainfrom
matt2e/cant-view-diffs

Conversation

@matt2e
Copy link
Collaborator

@matt2e matt2e commented Feb 6, 2026

Summary

Fixes a bug where clicking "View Diff" on branch cards could fail or show incorrect diffs due to callbacks capturing stale references to the branch object.

Changes

  • Explicitly captures branch properties (projectId, worktreePath, baseBranch, branchName, id) at render time using Svelte's {@const} declarations, ensuring callbacks always reference the correct values even if the branch list updates
  • Inlines the callback logic directly in the template rather than delegating to separate handler functions, making the data flow clearer and avoiding closure issues
  • Removes debug logging statements

matt2e and others added 4 commits February 6, 2026 15:07
When viewing diffs from the branch list, the branch properties are now
explicitly captured using @const blocks in the Svelte template. This
prevents potential closure issues where the wrong branch's information
might be used if the branches array is mutated during user interaction.

Changes:
- Extract branch properties (id, projectId, worktreePath, baseBranch, branchName) as const values in template
- Inline the view diff handlers directly in template with explicit captures
- Add console logging to track which branch is being referenced
- Include repo path in error messages for better debugging

This ensures that clicking "View Diff" on a branch always uses the
correct branch's worktree path and branch names, even if other branches
are being deleted or modified concurrently.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Remove console.log and console.error statements that were added for debugging purposes.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
When tabs are restored from persistent storage, validate that worktree
paths still exist before recreating the tabs. This prevents errors when
trying to view diffs from branches that were deleted outside the app.

The fix checks each worktree path during tab restoration and:
- Skips tabs with non-existent worktree paths
- Logs a warning about skipped tabs
- Adjusts the active tab index if needed
- Saves the cleaned-up tabs back to storage

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
When a user deletes a branch from the branch list, any open tabs viewing
that branch's worktree are now automatically closed. This prevents users
from interacting with stale tabs that reference deleted worktrees.

The fix works by:
- Capturing the worktreePath before deletion
- After successful deletion, finding all tabs with matching repoPath
- Closing each matching tab using the existing closeTab() function

This complements the existing app-startup cleanup that filters out tabs
with non-existent worktree paths, providing immediate cleanup during the
current session rather than waiting until next app restart.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@matt2e matt2e changed the title fix: diff failed to view because it used wrong branch fix: diff failed to view because tabs showed old branch Feb 6, 2026
@matt2e matt2e merged commit 0ced8a9 into main Feb 6, 2026
1 check passed
@matt2e matt2e deleted the matt2e/cant-view-diffs branch February 6, 2026 04:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant