Survive deleted-and-saved @Models on the started-run navigation path
TestFlight 2.3 (125) "crashed when watch ended an exercise": the
isDeleted guard from 85e1582 only covers the delete→save window. Once
the deletion is saved the model unregisters — isDeleted reads false
again, modelContext goes nil, and any persisted-property read still
traps (_InitialBackingData.getValue). StartedWorkoutNavigator retained
the run's @Model in @State for the whole workout, so an observer
remove/re-add churn (e.g. iCloud reachability flapping) invalidated it
underneath the pushed screen, and the watch's completion push triggered
the rebuild that read it.
Two layers: the fromLive/SplitDetailView guards now also require a
non-nil modelContext, and StartedWorkoutNavigator pushes a plain id
route, re-fetching the entity fresh on every destination build — a
re-imported run resolves to its live instance; a gone run shows a
placeholder instead of trapping.
Claude-Session: https://claude.ai/code/session_01PVNBVKp5bcq52X722uMjwT
This commit is contained in:
@@ -32,9 +32,13 @@ struct SplitDetailView: View {
|
||||
// A closure-based `NavigationLink` builds this destination eagerly for every
|
||||
// row in the parent list, including during the update that fires when a split
|
||||
// is deleted — and reading any persisted property (even `id`) on a deleted
|
||||
// `@Model` traps. An empty id maps to no live split, so `body` shows the
|
||||
// "Split Unavailable" state and dismisses; the row is on its way out anyway.
|
||||
_splitID = State(initialValue: split.isDeleted ? "" : split.id)
|
||||
// `@Model` traps. `isDeleted` alone misses a deletion that has already been
|
||||
// saved (the model unregisters: `isDeleted` false again, `modelContext` nil,
|
||||
// reads still trap), so check both. An empty id maps to no live split, so
|
||||
// `body` shows the "Split Unavailable" state and dismisses; the row is on its
|
||||
// way out anyway.
|
||||
let live = !split.isDeleted && split.modelContext != nil
|
||||
_splitID = State(initialValue: live ? split.id : "")
|
||||
}
|
||||
|
||||
private var split: Split? {
|
||||
|
||||
Reference in New Issue
Block a user