From d6f6d0ceba534cd904773b26aaba6c8e5d40fec4 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 3 Jul 2026 14:23:22 +0200 Subject: [PATCH] Bounce WORKTREES model updates onto the UI thread refreshWorktrees now writes Model.Worktrees in an onUIThreadUnlessRepoChanged bounce. loadWorktrees becomes a pure loader that returns the worktrees instead of writing them, since it's shared with refreshBranches; refreshWorktrees bounces the result, and the branches call site writes it directly for now (that write moves into refreshBranches's own bounce when that scope is migrated). Co-Authored-By: Claude Sonnet 5 --- pkg/gui/controllers/helpers/refresh_helper.go | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index 2076e45ee..d1c1091da 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -719,7 +719,10 @@ func (self *RefreshHelper) refreshBranches(refreshWorktrees bool, keepBranchSele self.rebuildPullRequestsMap() if refreshWorktrees { - self.loadWorktrees() + // TODO: this synchronous worker write goes away when refreshBranches is + // itself migrated to bouncing; for now it matches the rest of this + // not-yet-bounced function. + self.c.Model().Worktrees = self.loadWorktrees() self.refreshView(self.c.Contexts().Worktrees) } @@ -959,18 +962,24 @@ func (self *RefreshHelper) refreshRemotes() error { return nil } -func (self *RefreshHelper) loadWorktrees() { +func (self *RefreshHelper) loadWorktrees() []*models.Worktree { worktrees, err := self.c.Git().Loaders.Worktrees.GetWorktrees() if err != nil { self.c.Log.Error(err) - self.c.Model().Worktrees = []*models.Worktree{} - } else { - self.c.Model().Worktrees = worktrees + return []*models.Worktree{} } + return worktrees } func (self *RefreshHelper) refreshWorktrees() { - self.loadWorktrees() + generation := self.c.State().GetRepoGeneration() + + worktrees := self.loadWorktrees() + + self.onUIThreadUnlessRepoChanged(generation, func() error { + self.c.Model().Worktrees = worktrees + return nil + }) // need to refresh branches because the branches view shows worktrees against // branches