Initialize SignalR hub in OnAfterRenderAsync after first render

Moved SignalR hub connection setup from OnInitializedAsync to OnAfterRenderAsync, ensuring initialization occurs only after the component's first render. This prevents premature connection attempts and aligns with best practices for component lifecycle management.
This commit is contained in:
OlgunR
2026-04-20 10:08:24 +02:00
parent 3a1cb68cf0
commit b3f7df6801

View File

@@ -51,6 +51,11 @@
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
await RefreshDashboards(); await RefreshDashboards();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender) return;
_hubConnection = new HubConnectionBuilder() _hubConnection = new HubConnectionBuilder()
.WithUrl(HubEndpoint) .WithUrl(HubEndpoint)