RadzenTabs: handle JSDisconnectedException during tab selection

Wrap the JS interop calls in SelectTab, SelectTabOnClient and
OnAfterRenderAsync with try/catch (JSDisconnectedException) so a
dropping SignalR circuit no longer throws an uncaught exception and
leaves multiple tabs visually active. Matches the existing pattern
used by RadzenToc/RadzenChart.

Fixes #2558

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Vladimir Enchev
2026-05-29 08:29:38 +03:00
parent 89403ce516
commit df1dfa7133

View File

@@ -216,7 +216,13 @@ namespace Radzen.Blazor
await SelectedIndexChanged.InvokeAsync(selectedIndex);
await Element.FocusAsync(preventScroll: true);
try
{
await Element.FocusAsync(preventScroll: true);
}
catch (JSDisconnectedException)
{
}
}
StateHasChanged();
@@ -290,7 +296,13 @@ namespace Radzen.Blazor
if (JSRuntime != null && RenderMode == TabRenderMode.Client && previousSelectedIndex != selectedIndex)
{
previousSelectedIndex = selectedIndex;
await JSRuntime.InvokeVoidAsync("Radzen.selectTab", $"{GetId()}-tabpanel-{selectedIndex}", selectedIndex);
try
{
await JSRuntime.InvokeVoidAsync("Radzen.selectTab", $"{GetId()}-tabpanel-{selectedIndex}", selectedIndex);
}
catch (JSDisconnectedException)
{
}
}
await base.OnAfterRenderAsync(firstRender);
@@ -321,14 +333,26 @@ namespace Radzen.Blazor
previousSelectedIndex = selectedIndex;
SetFocusedIndex();
await JSRuntime.InvokeVoidAsync("Radzen.selectTab", $"{GetId()}-tabpanel-{selectedIndex}", selectedIndex);
try
{
await JSRuntime.InvokeVoidAsync("Radzen.selectTab", $"{GetId()}-tabpanel-{selectedIndex}", selectedIndex);
}
catch (JSDisconnectedException)
{
}
shouldRender = false;
await Change.InvokeAsync(selectedIndex);
await SelectedIndexChanged.InvokeAsync(selectedIndex);
shouldRender = true;
await Element.FocusAsync(preventScroll: true);
try
{
await Element.FocusAsync(preventScroll: true);
}
catch (JSDisconnectedException)
{
}
}
}