Description
openWorktreeWebview() in src/worktreeWebview.ts creates a new webview panel on every invocation (line 450-455) with no deduplication:
const panel = vscode.window.createWebviewPanel(
'quickPrWorktreeDetail',
`Worktree: ${info.branchName}`,
{ viewColumn: vscode.ViewColumn.Active, preserveFocus: true },
{ enableScripts: true, localResourceRoots: [], retainContextWhenHidden: true },
);
This leads to:
- Duplicate tabs — clicking "Open" on the same worktree multiple times creates multiple identical panels
- Stale data in old panels — if the user commits in panel A, panel B still shows old data with no notification
- Race conditions — simultaneous commits from two panels for the same worktree:
- Files may be copied twice
- Commit messages may overwrite each other
worktrees.json may experience concurrent write conflicts (though Node.js single-threaded nature mitigates this somewhat)
Affected Code
src/worktreeWebview.ts:450-455 — unconditional panel creation
src/worktreeManager.ts — updateWorktree / addWorktree have no locking
Suggested Solution
- Panel reuse — maintain a
Map<string, vscode.WebviewPanel> keyed by worktreeId. If a panel already exists for this worktree, call panel.reveal() instead of creating a new one
- Clean up on dispose — remove the mapping when
panel.onDidDispose fires
- Always refresh on reveal — before revealing an existing panel, re-fetch worktree data and rebuild the HTML
- (Optional) Operation lock — add a simple mutex per worktree ID to prevent concurrent commit/finalize/delete operations
Priority
Low. Real-world users rarely open multiple panels for the same worktree, but when it happens the bugs are hard to diagnose.
Description
openWorktreeWebview()insrc/worktreeWebview.tscreates a new webview panel on every invocation (line 450-455) with no deduplication:This leads to:
worktrees.jsonmay experience concurrent write conflicts (though Node.js single-threaded nature mitigates this somewhat)Affected Code
src/worktreeWebview.ts:450-455— unconditional panel creationsrc/worktreeManager.ts—updateWorktree/addWorktreehave no lockingSuggested Solution
Map<string, vscode.WebviewPanel>keyed byworktreeId. If a panel already exists for this worktree, callpanel.reveal()instead of creating a new onepanel.onDidDisposefiresPriority
Low. Real-world users rarely open multiple panels for the same worktree, but when it happens the bugs are hard to diagnose.