Bug 29: Übersicht-Tab aktualisierte sich nicht selbst beim Tab-Wechsel

.task lief nur einmal pro View-Lebenszeit — SwiftUI zerstört Tab-Inhalte
auf macOS beim Wechsel nicht, die View bleibt am Leben, .task feuert
also nie erneut beim Zurückwechseln. Fix: .onAppear statt .task, feuert
bei jedem Sichtbarwerden des Tabs neu — Änderungen aus dem Experte-Tab
(z.B. eine neu angelegte Route) erscheinen jetzt automatisch, ohne
manuellen "Aktualisieren"-Klick.

59 Unit-Tests grün.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YDmUd93KxsYGr2kLTotWnG
This commit is contained in:
Kay
2026-09-15 14:02:48 +02:00
co-authored by Claude Sonnet 5
parent 18fefc76a8
commit aebba46989
3 changed files with 21 additions and 5 deletions
@@ -98,10 +98,14 @@ struct OverviewView: View {
Button { scale = min(2.0, scale + 0.15) } label: { Image(systemName: "plus.magnifyingglass") }
}
}
.task {
if viewModel.graph.nodes.isEmpty {
await viewModel.load()
}
.onAppear {
// SwiftUI keeps every tab's content alive when switching tabs on macOS (this view
// isn't torn down and recreated) `.task` only ever runs once per view lifetime,
// so it wouldn't refire just from revisiting this tab. `.onAppear` does fire again
// each time, which is what actually picks up changes made elsewhere (e.g. a route
// added in the Experte-Tab) without a manual "Aktualisieren" click. Confirmed live
// (2026-09-15): the tab didn't refresh after switching away and back.
Task { await viewModel.load() }
}
.sheet(item: $expertViewModel.editingItem) { _ in
// `selectedSchema` is always set by `editNode` right before `editingItem`, so this