Skip to content

Conversation

gauss-lvs-dev
Copy link
Contributor

Fixed an issue that the order of CurrentItems could be wrong when items are expanded simultaneously.

There is a problem that the order of the nodes in RadzenTree.CurrentItems may not be correct if several nodes are to be expanded initially and the expansion takes different amounts of time.
The problem lies in RadzenTreeItem.OnInitializedAsync. Here, ‘await Tree?.ExpandItem(this)’ is called first, and then the item is added to CurrentItems. The following scenario can occur:

Example of the tree:

  • Parent
    -- Child1
    --- Child 1.1
    --- Child 1.2
    -- Child2
    --- Child 2.1
    --- Child 2.2
  1. OnInitializedAsync is called for Parent and runs until ‘await Tree?.ExpandItem(this)’. In this example, execution pauses here for a while because this call takes a long time.
  2. Meanwhile, OnInitializedAsync is called for Child1. ‘await Tree?.ExpandItem(this)’ is completed quickly in this example. Child1 is added to CurrentItems. It should actually be inserted after Parent, but Parent has not yet been added to the tree.
  3. OnInitializedAsync is eventually continued for Parent, and Parent appears at the end of CurrentItems.

The incorrect order leads to an exception as soon as, for example, a node is collapsed. In RadzenTreeItem.Toggle, the call to ‘Tree.RemoveFromCurrentItems’ relies on the correct order of the items.

The proposed solution would be to first add the items to the tree in OnInitializedAsync and only then perform the await calls that can cause timing problems.

Fixed an issue that the order of CurrentItems could be wrong when items are expanded simultaneously.
@enchev enchev merged commit d340df7 into radzenhq:master Aug 9, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants