Fix Mac crash when opening a book from search.

Defer NavigationStack path updates until after the practice tab is active so SwiftUI does not trap in boundPathChange.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
pepaskopec-blip 2026-09-22 12:42:04 +02:00
commit b6fa222659
3 changed files with 37 additions and 12 deletions

View file

@ -51,13 +51,7 @@ final class AppModel: ObservableObject {
tab = .practice
practicePath = []
default:
tab = .practice
if practicePath.last == r { return }
if practicePath.isEmpty {
practicePath = r.stack
} else {
practicePath.append(r)
}
applyPracticeRoute(r, replace: practicePath.isEmpty)
}
}
@ -75,8 +69,25 @@ final class AppModel: ObservableObject {
tab = .practice
practicePath = []
default:
tab = .practice
practicePath = r.stack
// Switching tabs and assigning a deep NavigationStack path in the
// same turn crashes SwiftUI on macOS (boundPathChange / unexpectedError).
applyPracticeRoute(r, replace: true)
}
}
/// Sets the practice tab path safely, especially when jumping from Search.
private func applyPracticeRoute(_ r: Route, replace: Bool) {
let stack = replace ? r.stack : (practicePath + [r])
if !replace, practicePath.last == r { return }
let switching = tab != .practice
tab = .practice
if switching || replace {
practicePath = []
DispatchQueue.main.async { [weak self] in
self?.practicePath = stack
}
} else {
practicePath = stack
}
}