[PR #2246] Fixed timing problem in RadzenTreeItem OnInitializedAsync #3156

Open
opened 2026-01-29 18:22:10 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/radzenhq/radzen-blazor/pull/2246

State: closed
Merged: Yes


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.

**Original Pull Request:** https://github.com/radzenhq/radzen-blazor/pull/2246 **State:** closed **Merged:** Yes --- 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.
claunia added the pull-request label 2026-01-29 18:22:10 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#3156