question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:7
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

10reactions
msftbot[bot]commented, Oct 22, 2021

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.

4reactions
mwasson74commented, Mar 30, 2022

Is there a workaround (or at least an alternative to Virtualize) for this? I am also experiencing this issue.

I’m going to attempt to put together a fix for this and send a PR

@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…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Blazor Virtualize won't load more items
When the first call is done the Virtualize component renders some items but when I scroll down the page nothing happens. It's supposed...
Read more >
Improve rendering performance with Blazor component ...
With Blazor component virtualization, the app will load only the records in the user's window, then render more only when scrolling.
Read more >
ASP.NET Core Razor component virtualization
Virtualization is a technique for limiting UI rendering to just the parts that are ... Most of the items aren't visible due to...
Read more >
Lazy load components with Blazor - Virtualize in Action
Rendering a set of data items in a loop. Most of the items aren't visible due to scrolling. (just imagine something like endless...
Read more >
Blazor Virtualization Update in 10 Minutes or Less - YouTube
Virtualization in Blazor makes rendering long lists easy. In .NET 7, there has been a small but significant upgrade to the Virtualization ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found