Skip to content

bug(mat-tree): childrenAccessor is not lazily evaluated and leaf nodes are not filtered out before calling the childrenAccessor #31289

Open
@lmuraru-plenty

Description

@lmuraru-plenty

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

childrenAccessor should only be called when expanding a node.

In the current state, workarounds are needed to support a mat-tree which asynchronously fetches children. If the dataset is large enough, there will then be a proportionately large number of fetches for the children.

Reproduction

StackBlitz link: stackblitz

Notice how the tree eagerly fetches all children, including children of leaf nodes. The number on the bottom of the page indicates the number of times childrenAccessor was called.

Expected Behavior

childrenAccessor should only be called when expanding a node.

Moreover, it should also not call the childrenAccessor for nodes which are not expandable, since we already provide the when: hasChild predicate.

Actual Behavior

childrenAccessor is eagerly called for each node when the tree is created, including leaf nodes.

Environment

  • Angular: 20
  • CDK/Material: 20
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): MacOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2The issue is important to a large percentage of users, with a workaroundarea: material/tree

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions