Repository navigation
Closed
Description
Description
After commit 6b351e5 ("fix: lazy-loaded plugins not fully activating"), event.lua re-fires the original autocmd via nvim_exec_autocmds once the plugin is loaded. However, the re-fired event does not forward the original ev.data and does not check whether the buffer is still valid.
This causes two classes of errors:
attempt to index field 'data' (a nil value)— Any autocmd callback that readsevent.data(e.g.,LspAttachexpectsevent.data.client_id) crashes becausedatais not forwarded.Invalid buffer id: N— If the buffer that triggered the original event has been wiped before the re-fire,nvim_exec_autocmdserrors on the stale buffer id.
Current code (event.lua:84-88)
if #other_events > 0 then
util.autocmd(other_events, function(ev)
loader.process_spec(pack_spec)
vim.api.nvim_exec_autocmds(ev.event, { buffer = ev.buf, modeline = false })
end, { group = state.lazy_group, once = true, pattern = normalized_event.pattern })
endSuggested fix
if #other_events > 0 then
util.autocmd(other_events, function(ev)
loader.process_spec(pack_spec)
if vim.api.nvim_buf_is_valid(ev.buf) then
vim.api.nvim_exec_autocmds(ev.event, { buffer = ev.buf, data = ev.data, modeline = false })
end
end, { group = state.lazy_group, once = true, pattern = normalized_event.pattern })
endTwo changes:
- Forward
data = ev.dataso downstream callbacks receive the original event data. - Guard with
nvim_buf_is_valid(ev.buf)to skip re-fire for wiped buffers.
Reproduction
Minimal init.lua:
vim.pack.add({ 'https://github.com/zuqini/zpack.nvim' })
require('zpack').setup({
-- Any plugin that lazy-loads on LspAttach
{
'https://github.com/someone/example-plugin',
event = 'LspAttach',
},
})
-- Callback that depends on event.data
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(event)
-- This crashes: event.data is nil when re-fired by zpack
local client_id = event.data.client_id
print('attached client:', client_id)
end,
})Steps:
- Open a file with an LSP server configured (e.g.,
nvim test.lua). - Wait for the LSP to attach — this triggers the lazy-load of the plugin.
- zpack loads the plugin, then re-fires
LspAttachwithoutdata.
Errors observed:
Error Lua callback: .../lsp-config.lua:129: attempt to index field 'data' (a nil value)
Error .../zpack/lazy_trigger/event.lua:87: Invalid buffer id: 1
Environment
Metadata
Metadata
Assignees
Labels
No labels
Activity
fix: forward ev.data, validate buffer, chain dependencies, and dedupl…
fix: forward ev.data, validate buffer, chain dependencies, and dedupl…
zuqini commentedon Apr 9, 2026
Thank you for reporting the issue. #10 should address this along with some other edge-case behaviors with event-triggers. Please let me know if you're still seeing issues
MomePP commentedon Apr 9, 2026
Thanks for the quick fix, I've tested, no longer get any errors on startup. 👏
fix(nvim/focus): load on BufEnter/WinEnter so startup window gets foc…