MudSelect rerenders content every time, resulting in bad performance
See original GitHub issueBug type
Component
Component name
MudSelect
What happened?
I would like to make a country selector for a registration form using MudSelect. I have a countries.json with all country names, iso codes and flag base64 images.
I m rendering the dropdown with this code:
<MudSelect Label="Country" Variant="Variant.Text" OffsetY="true" @bind-Value="registrationRequestDto.CountryAlpha3Code" For="@(() => registrationRequestDto.CountryAlpha3Code)"> @foreach (var country in countries) { <MudSelectItem Value="country.IsoAlpha3"> @* <img src="data:image/png;base64,@country.Flag" height="14" class="mr-2" />*@ @country.Name </MudSelectItem> } </MudSelect>
I have commented out the flag image part, and set them all to null, but the dropdown is still very slow.
Every time I open the dropdown or close it (either by clicking on an element, or clicking outside the dropdown) the foreach runs, and it creates 200+ MudSelectItems. This results in the UI totally freezing up for 1 second.
Expected behavior
I expected it to create the listitems once, and use it whenever I open the dropdown.
This might be a general Blazor issue \ question, but I think I have the best chance for help here.
Reproduction link
https://try.mudblazor.com/snippet/wOQFlucQyPhgdvTA
Reproduction steps
- Click on dropdown
- Notice the 1second delay
Relevant log output
No response
Version (bug)
5.1.5
Version (working)
No response
What browsers are you seeing the problem on?
Chrome
On what operating system are you experiencing the issue?
Windows
Pull Request
- I would like to do a Pull Request
Code of Conduct
- I agree to follow this project’s Code of Conduct
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (2 by maintainers)
Top Related StackOverflow Question
You can remove the empty space by putting
MudSelectin<div style="height:65px;overflow-y:hidden;"> ... </div>. See https://try.mudblazor.com/snippet/QammubwEBhQtuWUo and https://docs.microsoft.com/en-us/aspnet/core/blazor/components/virtualization?view=aspnetcore-5.0Thank you for the feature request.
Indeed you’re right. I am running it in WASM. I have tried the multi select now in WASM mode on mudblazor.com and I see a small hiccup there as well when clicking on one of the options in the dropdown. However, it’s only around a 190ms delay, which is only noticeable if you look for it.
But on my site for some reason, it’s around 900ms