I followed example "Refreshing tree data-binding".
Where was
// Force the tree to re-evaluate LoadSubsidiaries to make the change visible.
await this.tree.Reload();
And it work's fine with sync Expand delegate if call "Add" in context menu and add item.
But it throw's exception in async Expand.
Collection was modified; enumeration operation may not execute.
I think it is because in Reload() it call's Expand for all current items. And you have AddItem(RadzenTreeItem item) inside OnInitializedAsync.
In sync logic we have cycle like this:
- Rerender all items
- Call expand for all
- Gets updated item and add's it to currentItems
- OnInitializedAsync for item and Rerender
In async Expand we have async call's, which triggers Blazor to rerender if needed. It break's cycle and Rerender calls in middle of expand another element. And you have random like:
- Rerender all items
- Call expand for for first
- OnInitializedAsync for item and Rerender
- Add item to currentItems
- expand for first ended
- exception - "items was modified"
To reproduce just replace in example:
private async Task LoadSubsidiaries(TreeExpandEventArgs args) {
var company = args.Value as string;
if (Data.TryGetValue(company, out var subsidiaries)) {
await Task.Delay(100);
args.Children.Data = subsidiaries;
args.Children.HasChildren = c => Data.TryGetValue((string) c, out var _);
args.Children.Checkable = o => false;
}
}