[PR #2246] [MERGED] Fixed timing problem in RadzenTreeItem OnInitializedAsync #3153

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

📋 Pull Request Information

Original PR: https://github.com/radzenhq/radzen-blazor/pull/2246
Author: @gauss-lvs-dev
Created: 8/7/2025
Status: Merged
Merged: 8/9/2025
Merged by: @enchev

Base: masterHead: treeitem-fix


📝 Commits (1)

  • 5f8f98a Fixed timing problem in RadzenTreeItem OnInitializedAsync

📊 Changes

1 file changed (+14 additions, -14 deletions)

View changed files

📝 Radzen.Blazor/RadzenTreeItem.razor.cs (+14 -14)

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/radzenhq/radzen-blazor/pull/2246 **Author:** [@gauss-lvs-dev](https://github.com/gauss-lvs-dev) **Created:** 8/7/2025 **Status:** ✅ Merged **Merged:** 8/9/2025 **Merged by:** [@enchev](https://github.com/enchev) **Base:** `master` ← **Head:** `treeitem-fix` --- ### 📝 Commits (1) - [`5f8f98a`](https://github.com/radzenhq/radzen-blazor/commit/5f8f98a26c56b3ac60dcabd32036906f4a354a0e) Fixed timing problem in RadzenTreeItem OnInitializedAsync ### 📊 Changes **1 file changed** (+14 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `Radzen.Blazor/RadzenTreeItem.razor.cs` (+14 -14) </details> ### 📄 Description 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#3153