Skip to content

Blazor Virtualize 22-25 items #25915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hannespreishuber opened this issue Sep 15, 2020 · 9 comments
Closed

Blazor Virtualize 22-25 items #25915

hannespreishuber opened this issue Sep 15, 2020 · 9 comments
Assignees
Labels
affected-few This issue impacts only small number of customers area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed feature-blazor-virtualization This issue is related to the Blazor Virtualize component severity-minor This label is used by an internal tool
Milestone

Comments

@hannespreishuber
Copy link

hannespreishuber commented Sep 15, 2020

extended Weatherservice to 500 records, added a ID property named Counter (incremented)
Changed fetchdata.razor

 <Virtualize Items="forecasts" Context="forecast">
                <ItemContent>
                    <tr @key="forecast.Counter">
                        <td>@forecast.Counter</td>
                        <td>@forecast.Date.ToShortDateString()</td>
                        <td>@forecast.TemperatureC</td>
                        <td>@forecast.TemperatureF</td>
                        <td>@forecast.Summary</td>
                    </tr>
                </ItemContent>
                <Placeholder>
                    <tr>
                        <td>Loading...</td>
                    </tr>
                </Placeholder>
            </Virtualize>

shows only 22-25 rows in Browser

  • ASP.NET Core version 5 5.0.100-rc.1.20452.10

  • Version 16.8.0 Preview 3.0

@GarettCooper
Copy link

I'm experiencing a similar issue. My chat log consistenly shows the last 24 messages, removing older messages when new ones are added to the virtualized items. I can make the number of messages change when I resize the div, but that sometimes results in elements overlapping each other and not appearing in the correct positions. I haven't tried implementing my own ItemsProvider to resolve the issue.

Screenshots

image

image

@pranavkm pranavkm added the area-blazor Includes: Blazor, Razor Components label Sep 15, 2020
@hannespreishuber hannespreishuber changed the title Balzor Virtualize 22-25 items Blazor Virtualize 22-25 items Sep 16, 2020
@mkArtakMSFT
Copy link
Member

Thank you for filing this issue. In order for us to investigate this issue, please provide a minimalistic repro project (ideally a GitHub repo) that illustrates the problem.

@mkArtakMSFT mkArtakMSFT added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Sep 16, 2020
@hannespreishuber
Copy link
Author

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Sep 16, 2020
@mkArtakMSFT mkArtakMSFT added investigate and removed Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. labels Sep 17, 2020
@mkArtakMSFT mkArtakMSFT added this to the 5.0.0 milestone Sep 17, 2020
@SteveSandersonMS SteveSandersonMS self-assigned this Sep 21, 2020
@SteveSandersonMS
Copy link
Member

SteveSandersonMS commented Sep 24, 2020

@GarettCooper I think your issue is different and may be due to some unwanted interactions between CSS and <Virtualize>. If you could file a new issue with minimal repro steps we can take a look.

In fact looking at your screenshots, it appears that the items in your list aren't of a fixed equal height. The <Virtualize> component in 5.0 requires items to be the same height as each other, because otherwise it can't compute where in the list you are if the user scrolls suddenly right into the middle of the list.

We are tracking support for variable-sized items in a future release at #26099. In the meantime, instead of using <Virtualize>, if your items do have to vary in height then you should look at implementing your own separate infinite-scroll style behavior.

@SteveSandersonMS
Copy link
Member

SteveSandersonMS commented Sep 24, 2020

@hannespreishuber Thanks for the repro information. I was able to observe this issue and have tracked down the underlying cause.

The issue happens when <Virtualize> recomputes its estimate for the item height, and it happens to be so similar to the default value that it thinks no re-rendering is needed. Then it doesn't refresh while the user is scrolling because it's no longer listening for events.

Workaround

If you want to work around this in your own code, it's reasonably easy. You just need to pass an accurate ItemSize parameter to the <Virtualize> component so it will use your value instead of its default initial value of 50px. When I ran your code, I used the browser dev tools to see that the actual item height is 48.89 pixels:

image

So then I supplied this information to <Virtualize>:

<Virtualize Items="forecasts" Context="forecast" ItemSize="48.89f">
    <tr @key="forecast.Counter">
        ... etc ...
    </tr>
</Virtualize>

... and now it behaves correctly and doesn't get stuck.

If you don't like relying on arbitrary-seeming values like 48.89, then it's probably best to use CSS to force the items to be a specific known height. For example in your .css file you could set .my-table td { height: 50px; } or similar, and then you know to pass ItemSize="50".

Fixing it in the framework

I have prepared a fix for <Virtualize> that lets it detect when a refresh is needed purely due to changes in the item size estimate. However I don't know yet whether we will include this fix in the 5.0 release because the bar for including changes now is quite high and this issue has an easy workaround. I'll post an update here later when we have a decision about that.

@hannespreishuber
Copy link
Author

If you don't like relying on arbitrary-seeming values like 48.89, then it's probably best to use CSS to force the items to be a specific known height. For example in your .css file you could set .my-table td { height: 50px; } or similar, and then you know to pass ItemSize="50".

Thanks - I can live with that workaround, as I want to support blazor to reach the best tool, missing size is unexpected behavior. Needs a remark in docu and/or a warning in Visual Studio of missing size attribute on compile.

@GarettCooper
Copy link

@SteveSandersonMS Thanks for letting me know, the height issue did occur to me but I couldn't find any documentation confirming or denying that Virtualize only supported items with consistent heights. When I saw Virtualize in the blog post I was hoping for a silver bullet, but I guess I'll have to look in to writing my own solution.

@mkArtakMSFT mkArtakMSFT added the bug This issue describes a behavior which is not expected - a bug. label Sep 24, 2020
@ghost
Copy link

ghost commented Sep 24, 2020

Thanks for contacting us.
We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@SteveSandersonMS SteveSandersonMS added affected-few This issue impacts only small number of customers severity-minor This label is used by an internal tool labels Oct 7, 2020 — with ASP.NET Core Issue Ranking
@ghost
Copy link

ghost commented Oct 9, 2020

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affected-few This issue impacts only small number of customers area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed feature-blazor-virtualization This issue is related to the Blazor Virtualize component severity-minor This label is used by an internal tool
Projects
None yet
Development

No branches or pull requests

5 participants