I've tried different ways to prevent this from happening.
After changing to render-mode="Server" I was able to prevent rendering twice on the first load.
But now when I refresh the page it still doubles the amount of elements.
Here is what I've got
<div id="component-wrapper" class="row">
@if (Items != null)
{
@foreach (var item in Items )
{
<ItemComponent Item="@item" />
}
}
</div>
@code {
[Inject]
private IItemService ItemService { get; set; }
List<ItemViewModel> Items { get; set; }
protected override async Task OnInitializedAsync()
{
Items = await ItemService.GetItemsAsync();
base.OnInitialized();
}
}
I've read over the Stateful reconnection after prerendering section and it doesn't seem to work for me.
Itemscontains everything twice and thusforeachdoubles up onItemComponent? Is so check 'GetItemsAsync. ' Also note that when the Blazor Server SPA first loads it calls the page twice - the first time to statically render the page on the server, then a second time when the client side Blazor code calls back to the Blazor Hub to get a fully wired up page. - MrC aka Shaun Curtis