Let go of a playlist before deleting it

Deleting a local playlist from its own detail view took the app down every
time: the model is gone the moment the context saves, dismissal is animated
so the view renders at least once more, and the summary line under the
title reads the playlist's total duration. Reading a deleted model traps in
SwiftData with "context is missing", which is a fatal error rather than a
nil.

The state is cleared before the deletion now, so the renders that follow
have nothing to reach for. Everything else the view shows about a local
playlist is a copy — the rows are `Video` values built at load time — so
letting the model go costs the dismissal nothing.

Predates the accounts revamp; the same three lines are on `main`.
This commit is contained in:
Arkadiusz Fal
2026-09-05 23:38:06 +02:00
parent 5abd314c88
commit d41c6938f2

View File

@@ -282,6 +282,11 @@ struct UnifiedPlaylistDetailView: View {
) {
Button(String(localized: "common.delete"), role: .destructive) {
if let localPlaylist {
// Let go of the model *before* deleting it: dismissal is
// animated, so this view renders at least once more, and
// reading a deleted model — the duration in the subtitle is
// enough — traps in SwiftData with "context is missing".
self.localPlaylist = nil
dataManager?.deletePlaylist(localPlaylist)
dismiss()
} else {