Blazor Virtualize: ItemsProvider called repeatedly after scrolling just far enough to load more items
See original GitHub issueDescribe the bug
The initial render with ItemsProvider
works well with an EF Core data source with around 3800 items. Scrolling just enough to cause the ItemsProvider
to be called again results in it being called repeatedly. After many calls, the page becomes unresponsive. Here are a couple VS console log samples of what’s happening. You can see there’s a bit of a pattern between the 2 samples.
{ItemsProvider call count}: {ItemsProviderRequest.StartIndex} {ItemsProviderRequest.Count}
Sample 1
1: 54 15 2: 3 15 3: 6 15 4: 0 15 5: 1 26 6: 1216 20 7: 10 15 8: 23 15 9: 10 15 10: 23 15 11: 10 15 12: 23 15 13: 10 15 14: 23 15 15: 10 15 16: 23 15 17: 10 15 18: 23 15 19: 10 15 20: 23 15 21: 10 15 22: 23 15 23: 9 15 24: 0 15 25: 25 15 26: 9 15 27: 23 15
Sample 2
1: 54 15 2: 3 15 3: 7 15 4: 0 15 5: 1 37 6: 1791 23 7: 81 58
To Reproduce
Here is the code involved:
<Virtualize Context="item" ItemsProvider="LoadItems" ItemSize="100">
<ItemContent>
<CascadingValue Value="item">
<Item />
</CascadingValue>
</ItemContent>
<Placeholder>
<p>Loading</p>
</Placeholder>
</Virtualize>
@code {
[Parameter]
public IQueryable<Item> Items { get; set; }
[Parameter]
public int ItemsCount { get; set; }
private int _callCount = 0;
private async ValueTask<ItemsProviderResult<Item>> LoadItems(ItemsProviderRequest request)
{
var numItems = Math.Min(request.Count, ItemsCount - request.StartIndex);
var context = ItemsService.GetContext();
var items = await context.Items.Skip(request.StartIndex).Take(numItems).ToListAsync();
Console.WriteLine($"{_callCount}: {request.StartIndex} {request.Count}");
_callCount++;
return new ItemsProviderResult<Item>(items, ItemsCount);
}
}
Exceptions (if any)
There may or may not be some of these:
Exception thrown: ‘System.Threading.Tasks.TaskCanceledException’ in System.Private.CoreLib.dll
Further technical details
- ASP.NET Core version: 5.0.1
- The IDE (VS / VS Code/ VS4Mac) you’re running on, and it’s version: VS Mac
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:15 (7 by maintainers)
We’ve moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
Is there a workaround (or at least an alternative to Virtualize) for this? I am also experiencing this issue.
@csharpfritz did you get a fix put together for this?
@TanayParikh @mkArtakMSFT It would be neat if this could be a higher priority than it is…