Fixed timing problem in RadzenTreeItem OnInitializedAsync #2246
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
-- Child1
--- Child 1.1
--- Child 1.2
-- Child2
--- Child 2.1
--- Child 2.2
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.