Skip to content

Worktree detail webview does not refresh state after commit #14

@SunYanbox

Description

@SunYanbox

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:

  1. 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.
  1. The info object is re-fetched via getWorktree() after commit (line 487), and the HTML is fully rebuilt. This part is correct.

  2. 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.

  3. 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

  1. Call getCurrentRepo() inside the message handler rather than relying on the closure variable
  2. Optionally add a "Refresh" button in the webview toolbar area for manual refresh
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions