Skip to content

Commit ef57357

Browse files
committed
fix: prevent coroutine failure when view closes during update (sindrets#528)
Add closing signal check at the start of update_files to prevent race condition where gitsigns staging triggers refresh while view is closing.
1 parent 045881c commit ef57357

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

lua/diffview/scene/views/diff/diff_view.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,16 @@ DiffView.update_files = debounce.debounce_trailing(
326326
---@param self DiffView
327327
---@param callback fun(err?: string[])
328328
async.wrap(function(self, callback)
329+
-- Never update if the view is closing (prevents coroutine failure from race conditions).
330+
if self.closing:check() then
331+
callback({ "The update was cancelled." })
332+
return
333+
end
334+
329335
await(async.scheduler())
330336

331337
-- Never update unless the view is in focus
332-
if self.tabpage ~= api.nvim_get_current_tabpage() then
338+
if self.closing:check() or self.tabpage ~= api.nvim_get_current_tabpage() then
333339
callback({ "The update was cancelled." })
334340
return
335341
end
@@ -363,8 +369,8 @@ DiffView.update_files = debounce.debounce_trailing(
363369
return
364370
end
365371

366-
-- Stop the update if the view is no longer in focus.
367-
if self.tabpage ~= api.nvim_get_current_tabpage() then
372+
-- Stop the update if the view is closing or no longer in focus.
373+
if self.closing:check() or self.tabpage ~= api.nvim_get_current_tabpage() then
368374
callback({ "The update was cancelled." })
369375
return
370376
end

0 commit comments

Comments
 (0)