I am experiencing a very similar behavior as already described in https://forum.radzen.com/t/grid-rowselect-event-stuck-in-a-loop/2380.
If a RadzenGrid which has specified the RowSelect event-callback is inside a RadzenTabs and some tabs are enclosed by AuthorizeView.Role the infinite loop occurs.
Please see the simple example code below
Please note, if the RowSelected callback is not specified or the 'Users' tab is not enclosed by AuthorizeView everything works fine and the infinite loop does not occur.
@page "/"
@using Radzen;
@using Radzen.Blazor;
@using Semafor.View.Authentication;
@namespace Semafor.View.Ambulances.Patients_
@inject AuthenticationStateProvider myAuthenticationStateProvider;
<AuthorizeView>
<NotAuthorized>
<h1>Semafor Login</h1>
<RadzenCard>
<RadzenLogin AllowRegister="false" AllowResetPassword="false" Login="@OnLogin" />
</RadzenCard>
</NotAuthorized>
<Authorized Context="Context1">
<div class="container">
<RadzenTabs>
<Tabs>
<RadzenTabsItem Text="Patients">
<div class="row">
<div class="col">
<RadzenGrid AllowPaging="true" PageSize="100" AllowSorting="true" AllowFiltering="true"
Data="@myViewModel.Patients" TItem="Patient2" Value="@myViewModel.SelectedPatient"
FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
RowSelect="@OnRowSelected">
<Columns>
<RadzenGridColumn TItem="Patient2" Property="@nameof(Patient2.FirstName)" Title="First Name" />
<RadzenGridColumn TItem="Patient2" Property="@nameof(Patient2.LastName)" Title="Last Name" />
</Columns>
</RadzenGrid>
</div>
</div>
</RadzenTabsItem>
<AuthorizeView Roles="Role1">
<RadzenTabsItem Text="Users">
</RadzenTabsItem>
</AuthorizeView>
</Tabs>
</RadzenTabs>
</div>
</Authorized>
</AuthorizeView>
@code {
public class Patient2
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
public class ViewModel
{
private List<Patient2> myPatients = new List<Patient2>() { new Patient2() { FirstName = "Peter", LastName = "Hell" } };
public ViewModel()
{
SelectedPatient = Patients.FirstOrDefault();
}
public Patient2 SelectedPatient { get; set; }
public IQueryable<Patient2> Patients => myPatients.Where(x => x.FirstName == "Peter").AsQueryable();
}
private SemaforAuthenticationStateProvider mySemaforAuthenticationStateProvider;
private ViewModel myViewModel;
protected override void OnInitialized()
{
mySemaforAuthenticationStateProvider = (SemaforAuthenticationStateProvider)myAuthenticationStateProvider;
myViewModel = new ViewModel();
}
internal void OnLogin(LoginArgs loginArgs)
{
// Just indicate the login is successful for the role Role1.
mySemaforAuthenticationStateProvider.NotifyAuthenticated(loginArgs.Username, "Role1");
}
private void OnRowSelected(Patient2 patient)
{
// Even if this callback is empty the infinite loop happens.
}
}
For the completeness here is also AuthenticationStateProvider:
public class SemaforAuthenticationStateProvider : AuthenticationStateProvider
{
public override async Task GetAuthenticationStateAsync()
{
AuthenticationState authenticationState = new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity()));
return await Task.FromResult(authenticationState);
}
public void NotifyAuthenticated(string userName, string userRole)
{
ClaimsIdentity identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, userName), new Claim(ClaimTypes.Role, userRole) }, "a");
ClaimsPrincipal user = new ClaimsPrincipal(identity);
AuthenticationState authenticationState = new AuthenticationState(user);
NotifyAuthenticationStateChanged(Task.FromResult(authenticationState));
}
}
I would like to ask for an advise how to overcome this problem.