NavigationStack return to root crash in preview, works in Simulator

I am running into a crash issue with what seems like a super simple project. This all works in Preview up until the home button is pressed in the Info view. It flashes back to the Colors list, then crashes. Interestingly, it works in the Similar with no issues. This is on an M2 Pro MacBook Pro running Ventura/Xcode 13.3.1. I haven’t upgraded yet because I have read enough horror stories about Sonoma, especially with respect to Parallels Desktop, which I need to keep running for a little longer.
My question is, is this a problem in my code that I am missing, or a bug that I just need to work around and accept for now? And, is there anything in the crash dump that might be helpful? I have looked through it and I can’t find anything that defines WHY I got a crash, but it might as well be in Klingon as far as my comprehension of what I am reading. 🙂

AppEntry.swift

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import SwiftUI
@main
struct AppEntry: App {
@StateObject var router = Router()
var body: some Scene {
WindowGroup {
NavigationStack(path: $router.path) {
ContentView()
}
.environmentObject(router)
}
}
}
class Router: ObservableObject {
@Published var path:NavigationPath = NavigationPath()
func back() {
path.removeLast()
}
func reset() {
path = NavigationPath()
}
}
</code>
<code>import SwiftUI @main struct AppEntry: App { @StateObject var router = Router() var body: some Scene { WindowGroup { NavigationStack(path: $router.path) { ContentView() } .environmentObject(router) } } } class Router: ObservableObject { @Published var path:NavigationPath = NavigationPath() func back() { path.removeLast() } func reset() { path = NavigationPath() } } </code>
import SwiftUI

@main
struct AppEntry: App {
    @StateObject var router = Router()
    var body: some Scene {
        WindowGroup {
            NavigationStack(path: $router.path) {
                ContentView()
            }
            .environmentObject(router)
        }
    }
}

class Router: ObservableObject {
    @Published var path:NavigationPath = NavigationPath()
    
    func back() {
        path.removeLast()
    }
    func reset() {
        path = NavigationPath()
    }
}

ContentView.swift

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import SwiftUI
struct ContentView: View {
@EnvironmentObject var router: Router
private var colors: [Color] = [.indigo, .yellow, .green, .orange, .brown]
var body: some View {
List(colors, id: .self) { color in
NavigationLink(color.description, value: color)
}
.listStyle(.plain)
.navigationTitle("Colors")
.navigationDestination(for: Color.self) { color in
ColorView(color: color)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
NavigationStack {
ContentView()
.environmentObject(Router())
}
}
}
</code>
<code>import SwiftUI struct ContentView: View { @EnvironmentObject var router: Router private var colors: [Color] = [.indigo, .yellow, .green, .orange, .brown] var body: some View { List(colors, id: .self) { color in NavigationLink(color.description, value: color) } .listStyle(.plain) .navigationTitle("Colors") .navigationDestination(for: Color.self) { color in ColorView(color: color) } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { NavigationStack { ContentView() .environmentObject(Router()) } } } </code>
import SwiftUI

struct ContentView: View {
    @EnvironmentObject var router: Router
    private var colors: [Color] = [.indigo, .yellow, .green, .orange, .brown]
    var body: some View {
            List(colors, id: .self) { color in
                NavigationLink(color.description, value: color)
            }
            .listStyle(.plain)
            .navigationTitle("Colors")
            .navigationDestination(for: Color.self) { color in
                ColorView(color: color)
            }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        NavigationStack {
            ContentView()
                .environmentObject(Router())
        }
    }
}

ColorView.swift

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import SwiftUI
struct ColorView: View {
@EnvironmentObject var router: Router
var color: Color
var body: some View {
color
.navigationTitle(color.description.capitalized)
.toolbar {
NavigationLink("info", value: true)
}
.navigationDestination(for: Bool.self) { bool in
TextView()
}
}
}
struct ColorView_Previews: PreviewProvider {
static var previews: some View {
NavigationStack {
ColorView(color: .green)
.environmentObject(Router())
}
}
}
</code>
<code>import SwiftUI struct ColorView: View { @EnvironmentObject var router: Router var color: Color var body: some View { color .navigationTitle(color.description.capitalized) .toolbar { NavigationLink("info", value: true) } .navigationDestination(for: Bool.self) { bool in TextView() } } } struct ColorView_Previews: PreviewProvider { static var previews: some View { NavigationStack { ColorView(color: .green) .environmentObject(Router()) } } } </code>
import SwiftUI

struct ColorView: View {
    @EnvironmentObject var router: Router
    var color: Color
    var body: some View {
        color
        .navigationTitle(color.description.capitalized)
        .toolbar {
            NavigationLink("info", value: true)
        }
        .navigationDestination(for: Bool.self) { bool in
            TextView()
        }
    }
}

struct ColorView_Previews: PreviewProvider {
    static var previews: some View {
        NavigationStack {
            ColorView(color: .green)
                .environmentObject(Router())
        }
    }
}

TextView.swift

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import SwiftUI
struct TextView: View {
@EnvironmentObject var router: Router
var body: some View {
VStack {
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
.frame(alignment: .leading)
.padding()
}
Spacer()
.navigationTitle("info")
.toolbar {
Button ("home") {
router.reset()
}
}
}
}
struct TextView_Previews: PreviewProvider {
static var previews: some View {
NavigationStack {
TextView()
.environmentObject(Router())
}
}
}
</code>
<code>import SwiftUI struct TextView: View { @EnvironmentObject var router: Router var body: some View { VStack { Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.") .frame(alignment: .leading) .padding() } Spacer() .navigationTitle("info") .toolbar { Button ("home") { router.reset() } } } } struct TextView_Previews: PreviewProvider { static var previews: some View { NavigationStack { TextView() .environmentObject(Router()) } } } </code>
import SwiftUI

struct TextView: View {
    @EnvironmentObject var router: Router
    var body: some View {
        VStack {
            Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
                .frame(alignment: .leading)
                .padding()
        }
        Spacer()
        .navigationTitle("info")
        .toolbar {
            Button ("home") {
                router.reset()
            }
        }
        
    }
}

struct TextView_Previews: PreviewProvider {
    static var previews: some View {
        NavigationStack {
            TextView()
                .environmentObject(Router())
        }
    }
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật