Skip to content

Commit d949af7

Browse files
committed
fix(#1804): do not refresh watched nodes that have been destroyed (deleted)
1 parent e0cfbbb commit d949af7

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed

lua/nvim-tree/explorer/node.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ function M.node_destroy(node)
121121

122122
if node.watcher then
123123
node.watcher:destroy()
124+
node.watcher = nil
124125
end
125126
end
126127

lua/nvim-tree/explorer/watch.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ function M.create_watcher(node)
5151
local function callback(watcher)
5252
log.line("watcher", "node event scheduled refresh %s", watcher.context)
5353
utils.debounce(watcher.context, M.debounce_delay, function()
54+
if watcher.destroyed then
55+
return
56+
end
5457
if node.link_to then
5558
log.line("watcher", "node event executing refresh '%s' -> '%s'", node.link_to, node.absolute_path)
5659
else

lua/nvim-tree/git/init.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ function M.load_project_status(cwd)
150150
local callback = function(w)
151151
log.line("watcher", "git event scheduled '%s'", w.project_root)
152152
utils.debounce("git:watcher:" .. w.project_root, M.config.filesystem_watchers.debounce_delay, function()
153+
if w.destroyed then
154+
return
155+
end
153156
reload_tree_at(w.project_root)
154157
end)
155158
end

lua/nvim-tree/watcher.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ function Event:destroy(message)
9999
end
100100

101101
Event._events[self._path] = nil
102+
103+
self.destroyed = true
102104
end
103105

104106
function Watcher:new(path, files, callback, data)
@@ -139,6 +141,8 @@ function Watcher:destroy()
139141
self._event:remove(self._listener)
140142

141143
utils.array_remove(Watcher._watchers, self)
144+
145+
self.destroyed = true
142146
end
143147

144148
M.Watcher = Watcher

0 commit comments

Comments
 (0)