Guard Home JS interop during prerender disposal

This commit is contained in:
2026-02-26 09:04:50 +01:00
parent 2d0df7948c
commit 96238a9341

View File

@@ -69,6 +69,7 @@ public partial class Home
private Guid? EditingCharacterId { get; set; }
private Guid? EditingSkillId { get; set; }
private bool StateRefreshInProgress { get; set; }
private bool HasInteractiveRenderStarted { get; set; }
private DotNetObjectReference<Home>? DotNetRef { get; set; }
[Inject]
@@ -104,6 +105,8 @@ public partial class Home
protected override async Task OnAfterRenderAsync(bool firstRender)
{
HasInteractiveRenderStarted = true;
if (!firstRender)
{
return;
@@ -901,6 +904,11 @@ public partial class Home
private async Task StopStateEventsAsync()
{
if (!HasInteractiveRenderStarted)
{
return;
}
try
{
await JS.InvokeVoidAsync("rpgRollerApi.stopStateEvents");
@@ -908,6 +916,9 @@ public partial class Home
catch (JSDisconnectedException)
{
}
catch (InvalidOperationException ex) when (IsStaticRenderInteropException(ex))
{
}
}
public async ValueTask DisposeAsync()
@@ -916,6 +927,11 @@ public partial class Home
DotNetRef?.Dispose();
}
private static bool IsStaticRenderInteropException(InvalidOperationException exception)
{
return exception.Message.Contains("statically rendered", StringComparison.OrdinalIgnoreCase);
}
private async Task<T> RequestAsync<T>(string method, string path, object? payload = null)
{
var response = await JS.InvokeAsync<JsApiResponse>("rpgRollerApi.request", method, path, payload);