Refactor theme change handler for safe async updates

Refactored OnThemeChanged in MainLayout.razor to use InvokeAsync for proper synchronization of UI updates and async logic, preventing threading issues. Also added a blank line after app.Run() in Program.cs (no functional impact).
This commit is contained in:
OlgunR
2026-05-11 13:36:44 +02:00
parent 1112fa215c
commit a6a17991bb
2 changed files with 7 additions and 6 deletions

View File

@@ -50,13 +50,14 @@
await ApplyDxDarkOverrideAsync(); await ApplyDxDarkOverrideAsync();
} }
private async void OnThemeChanged() private void OnThemeChanged()
{ {
StateHasChanged(); InvokeAsync(async () =>
if (_isInteractive)
{ {
await ApplyDxDarkOverrideAsync(); StateHasChanged();
} if (_isInteractive)
await ApplyDxDarkOverrideAsync();
});
} }
private async Task ApplyDxDarkOverrideAsync() private async Task ApplyDxDarkOverrideAsync()

View File

@@ -44,4 +44,4 @@ app.UseAntiforgery();
app.MapRazorComponents<App>() app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode(); .AddInteractiveServerRenderMode();
app.Run(); app.Run();