From d41c6938f268a2420047ee7f75a237f4769c52bf Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sat, 5 Sep 2026 23:38:06 +0200 Subject: [PATCH] Let go of a playlist before deleting it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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`. --- Yattee/Views/Playlist/UnifiedPlaylistDetailView.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Yattee/Views/Playlist/UnifiedPlaylistDetailView.swift b/Yattee/Views/Playlist/UnifiedPlaylistDetailView.swift index 1948b4cc..a5f37450 100644 --- a/Yattee/Views/Playlist/UnifiedPlaylistDetailView.swift +++ b/Yattee/Views/Playlist/UnifiedPlaylistDetailView.swift @@ -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 {