mirror of
https://github.com/pepaskopec-blip/Graduately.git
synced 2026-10-28 15:44:34 +00:00
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:
parent
e5e8967187
commit
b6fa222659
3 changed files with 37 additions and 12 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue