Skip to content

Blazor Virtualize: ItemsProvider called repeatedly after scrolling just far enough to load more items #28653

@mrlife

Description

@mrlife

Describe 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    PerfPillar: Technical Debtaffected-fewThis issue impacts only small number of customersarea-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.feature-blazor-virtualizationThis issue is related to the Blazor Virtualize componentseverity-majorThis label is used by an internal tool

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions