Here is your issue:
protected override void OnInitialized()
{
DateTime now = DateTime.Now;
string nowString = now.ToString("yyyy-MM-ddTHH:mm:ss");
JS.InvokeVoidAsync("localStorage.setItem", "LastActivity", now);
}
You are using "fire and forget" with the
JS.InvokeVoidAsync
method. This is a big no-no unless you know what you are doing.
Change to:
protected override async Task OnInitializedAsync()
{
DateTime now = DateTime.Now;
string nowString = now.ToString("yyyy-MM-ddTHH:mm:ss");
await JS.InvokeVoidAsync("localStorage.setItem", "LastActivity", now);
}
You can learn more about the lifecycles here:
Blazor University - Component lifecycles[
^]