Not related to rendermode
I have a Blazor .NET 8 application with a parent component (Edit.razor
) that contains an EditForm
and a child component (ButtonTest
) within it. The parent component’s OnInitializedAsync method calls an async method (GetModel
) to retrieve data. However, I’ve noticed that the OnInitializedAsync
method of the child component (ButtonTest
) is being called twice.
Here’s a simplified version of my code:
Edit.razor:
@page "/Edit"
@rendermode @(new InteractiveServerRenderMode(false))
@if (Model != null)
{
<EditForm Model="@Model">
<ButtonTest></ButtonTest>
</EditForm>
}
@code {
private string Model { get; set; } = string.Empty;
protected override async Task OnInitializedAsync()
{
Model = await GetModel();
await base.OnInitializedAsync();
}
private async Task<string> GetModel()
{
await Task.Delay(1);
return "Hello world";
}
}
ButtonTest.razor:
<h3>ButtonTest</h3>
@code {
protected override Task OnInitializedAsync()
{
return base.OnInitializedAsync();
}
}
In this setup, when GetModel
is called within the OnInitializedAsync
of the parent component, the OnInitializedAsync
method of the child component (ButtonTest
) is triggered twice.
I’m curious about why this is happening and how I can prevent it. Any insights or suggestions would be greatly appreciated. Thank you!