From 562338d0c4de5d6b983b24c7c7d9295366416f83 Mon Sep 17 00:00:00 2001 From: Claudio Schaad Date: Sat, 4 Jul 2026 09:47:14 +0200 Subject: [PATCH] PR U-6a: MainLayout wraps @Body in an ErrorBoundary MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a Blazor built-in ErrorBoundary around @Body with a friendly FluentMessageBar + retry / home buttons. Also hook NavigationManager.LocationChanged so the boundary resets on any nav (otherwise the error state persists across NavigateTo and "Zur Startseite" still shows the failure banner). U-6 split into U-6a (this) and U-6b (per-handler try/catch to route expected exceptions to IMessageService — deferred). Co-Authored-By: Claude Opus 4.7 --- .../Components/Layout/MainLayout.razor | 42 ++++++++++++++++++- UI_IMPROVEMENT_PLAN.md | 3 +- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/Schaad.Accounting.UI/Components/Layout/MainLayout.razor b/Schaad.Accounting.UI/Components/Layout/MainLayout.razor index de1dab6..e5a5105 100644 --- a/Schaad.Accounting.UI/Components/Layout/MainLayout.razor +++ b/Schaad.Accounting.UI/Components/Layout/MainLayout.razor @@ -1,4 +1,6 @@ @inherits LayoutComponentBase +@inject NavigationManager Navigation +@implements IDisposable @@ -9,7 +11,24 @@
- @Body + + + @Body + + + + + Diese Seite konnte nicht angezeigt werden. Details stehen im Server-Log. + + + Neu versuchen + Zur Startseite + + + +
@@ -28,4 +47,23 @@ An unhandled error has occurred. Reload 🗙 - \ No newline at end of file + + +@code { + private ErrorBoundary? errorBoundary; + + protected override void OnInitialized() + { + // ErrorBoundary state persists across NavigationManager.NavigateTo, so the + // error page would linger even after the user clicked "Zur Startseite". + // Reset on any location change. + Navigation.LocationChanged += OnLocationChanged; + } + + private void OnLocationChanged(object? sender, Microsoft.AspNetCore.Components.Routing.LocationChangedEventArgs e) + => errorBoundary?.Recover(); + + private void Recover() => errorBoundary?.Recover(); + + public void Dispose() => Navigation.LocationChanged -= OnLocationChanged; +} \ No newline at end of file diff --git a/UI_IMPROVEMENT_PLAN.md b/UI_IMPROVEMENT_PLAN.md index 23e2185..a8d406c 100644 --- a/UI_IMPROVEMENT_PLAN.md +++ b/UI_IMPROVEMENT_PLAN.md @@ -165,7 +165,8 @@ Split into two PRs on delivery because the header path touches ~15 pages. ### Phase 3 — Loading and error UX consistency - **U-5** Shared `` component with a consistent skeleton visual. Adopt across every page currently using ad-hoc `@if (x is null) {

Lädt…

return; }`. -- **U-6** Wrap each page (or the layout's `@Body`) in `` with a friendly retry UI. Route `SaveTransactionAsync` / `DeleteAccountAsync` etc. exceptions to `IMessageService` instead of bubbling. +- **U-6a** Wrap `MainLayout`'s `@Body` in `` with a friendly retry UI. Reset on any `NavigationManager.LocationChanged` so the error state doesn't stick after the user clicks "Zur Startseite". +- **U-6b** Route expected `SaveTransactionAsync` / `DeleteAccountAsync` / etc. exceptions to `IMessageService` — try/catch in each of the ~15 event handlers with a shared error-formatting helper. ### Phase 4 — Feedback + polish for mutations