Skip to content

Rerender crashes when updating Tree’s data. #44

Description

@gregorias

Description

In a tree component, when I set the data property to a signal value and update it, no changes happen.

This behaviour is associated with an error thrown in

The error is: "...ek/.local/share/nvim/lazy/nui.nvim/lua/nui/tree/init.lua:450: attempt to index field 'linenr' (a nil value)" and it comes from Nui’s tree component.

It might be that NuiComponents incorrectly modifies the _ property and removes the linenr property.

Repro

local n = require("nui-components")

local my_menu = function(items_signal)
  return n.tree({
    flex = 1,
    border_label = " Options ",
    data = items_signal.items:map(function(items_val)
			local nodes = {}
			for _, item in pairs(items_val) do
				table.insert(nodes, n.node({ text = item }))
			end
			return nodes
    end),
    prepare_node = function(node, line, component)
      line:append(node.text)
      return line
    end,
  })
end

local my_dashboard = function()
  local renderer = n.create_renderer({
    width = 60,
    height = 12,
  })
  local base_items = { "a", "ab", "abc" }
  local items_signal = n.create_signal({ items = base_items })
  local menu_component = my_menu(items_signal)

  local body = function()
    return n.rows(
      menu_component,
      n.text_input({
        autofocus = true,
        max_lines = 1,
        on_change = function(value)
          local new_items = {}
          for _, item in pairs(items_signal.items:get_value()) do
            if item:find(value) then
              table.insert(new_items, item)
            end
          end
          items_signal.items = new_items
        end,
      })
    )
  end

  renderer:render(body)
end

my_dashboard()

Current Behavior

When writing filter text, the tree component remains unchanged.

Expected Behavior

When writing filter text, the tree component updates with new entries.

NuiComponents version

1.5.2

Neovim version

0.10

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions