Description
After committing in the worktree detail webview (openWorktreeWebview), the panel rebuilds its HTML but may still show stale information due to closure-captured state.
Root Cause
In src/worktreeWebview.ts lines 444-496:
gitStatus is captured once when the panel is created (line 444: const gitStatus = getCurrentRepo()). The commit callback reuses this same value (line 489):
// Captured at panel creation:
const gitStatus = getCurrentRepo();
// Inside commit handler:
const newAllChangedFiles = gitStatus ? getChangedFiles(gitStatus.repo) : [];
// gitStatus.repo.state is a reference type, so getChangedFiles often returns
// fresh data — but this is accidental, not intentional.
-
The info object is re-fetched via getWorktree() after commit (line 487), and the HTML is fully rebuilt. This part is correct.
-
However, filterFilesCommittedToWorktree is called against the worktree branch. After commit, the branch now contains the committed files, so they are correctly excluded from diff. The logic mostly works by accident, because repo.state is a live reference.
-
The sidebar tree (treeDataProvider.refresh()) is refreshed by the caller (extension.ts line 492), but the open webview panel does not subscribe to any data-change events — it only refreshes when the user triggers an action.
Affected Code
src/worktreeWebview.ts:444-496 — closure capturing gitStatus
src/extension.ts:486-492 — tree refresh after worktree commit callback
Suggested Solution
- Call
getCurrentRepo() inside the message handler rather than relying on the closure variable
- Optionally add a "Refresh" button in the webview toolbar area for manual refresh
- Consider an event-driven approach: when worktree data changes, emit an event that open panels can subscribe to and rebuild their HTML
Priority
Low. Current behavior is mostly correct because repo.state is a live reference. Only edge cases (e.g., worktree was deleted externally) would cause stale display.
Description
After committing in the worktree detail webview (
openWorktreeWebview), the panel rebuilds its HTML but may still show stale information due to closure-captured state.Root Cause
In
src/worktreeWebview.tslines 444-496:gitStatusis captured once when the panel is created (line 444:const gitStatus = getCurrentRepo()). The commit callback reuses this same value (line 489):The
infoobject is re-fetched viagetWorktree()after commit (line 487), and the HTML is fully rebuilt. This part is correct.However,
filterFilesCommittedToWorktreeis called against the worktree branch. After commit, the branch now contains the committed files, so they are correctly excluded from diff. The logic mostly works by accident, becauserepo.stateis a live reference.The sidebar tree (
treeDataProvider.refresh()) is refreshed by the caller (extension.tsline 492), but the open webview panel does not subscribe to any data-change events — it only refreshes when the user triggers an action.Affected Code
src/worktreeWebview.ts:444-496— closure capturinggitStatussrc/extension.ts:486-492— tree refresh after worktree commit callbackSuggested Solution
getCurrentRepo()inside the message handler rather than relying on the closure variablePriority
Low. Current behavior is mostly correct because
repo.stateis a live reference. Only edge cases (e.g., worktree was deleted externally) would cause stale display.