Skip to content

CdkTree asynchronously loads node children before node has been expanded #16075

Open
@jonrimmer

Description

@jonrimmer

What is the expected behavior?

When the children of a NestedTreeNode are an observable, CdkTree should not subscribe to the observable until it actually needs to display the child nodes, e.g. when the user has clicked to expand the node.

Imagine if resolving the children of a given node required an API call. If the CdkTree eagerly fetched the children of every visible node, expanding a node with 100 children would launch 100 simultaneous API requests to the API.

What is the current behavior?

CdkTree eagerly fetches the children of every visible node, so expanding a node with 100 children will launch 100 simultaneous API requests to the API.

What are the steps to reproduce?

https://stackblitz.com/edit/angular-eyf6xl

Check the console to see when subscriptions to the children observables are made. You will see that the children for each node are loaded as soon as their parent node is visible, and before the parent node is expanded.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular: 7
Material: 7
OS: macOS
TypeScript: 3.3

Is there anything else we should know?

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4A relatively minor issue that is not relevant to core functionsarea: cdk/treeperfThis issue is related to performance

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions