.navigationTitle causes hang when creating a new item on a separate page, then navigating back to a TabView with PageTabViewStyle that is displaying that data on iOS 18.2

After a lot of testing and diagnosing, I found that when going to a item creation page, creating an item, navigating back to a TabView with a tabViewStyle of PageTabViewStyle and a navigationTitle that is displaying that data, and all inside of a NavigationStack, the app hangs. I have tested this on iOS 18.2, on both a simulator and a physical iPhone 16 Pro Max, and it always hangs, not crashing. However, when run on My Mac (Designed for iPad) and the iPad simulator, it doesn't crash.

This could just be a really niche problem, but it might be the result of some other issue that could cause other problems.

I have created a minimal reproducible example, stemming from the iOS App template, with SwiftUI and SwiftData.

ContentView.swift

import SwiftUI
import SwiftData


struct ContentView: View {
    @Environment(\.modelContext) private var modelContext
    @Query private var items: [Item]
    
    var body: some View {
        NavigationStack {
            TabView {
                ForEach(items) { item in
                    Text(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))
                }
            }
            .tabViewStyle(PageTabViewStyle(indexDisplayMode: .automatic))
            .toolbar {
                ToolbarItem(placement: .navigationBarTrailing) {
                    NavigationLink {
                        Button(action: {
                            modelContext.insert(Item(timestamp: Date()))
                        }) {
                            Text("Create Item")
                        }
                    } label: {
                        Text("Creation Page")
                    }
                }
            }
            // When added, crashes the app
            .navigationTitle("Crash")
        }
    }
}

TestingApp.swift (unchanged)

import SwiftUI
import SwiftData

@main
struct TestingApp: App {
    var sharedModelContainer: ModelContainer = {
        let schema = Schema([
            Item.self,
        ])
        let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false)

        do {
            return try ModelContainer(for: schema, configurations: [modelConfiguration])
        } catch {
            fatalError("Could not create ModelContainer: \(error)")
        }
    }()

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
        .modelContainer(sharedModelContainer)
    }
}

Item.swift (unchanged)

import Foundation
import SwiftData

@Model
final class Item {
    var timestamp: Date
    
    init(timestamp: Date) {
        self.timestamp = timestamp
    }
}

I couldn't reproduce this. You should raise a bug then post the FB number here.

https://feedbackassistant.apple.com/

Same here

wow just stumbled on this hard wall today, on iOS 18.6 simulator where I had a recursive navlink for folder browser. spent almost half a day on this

the code was something like

import SwiftUI

struct Folder: Identifiable {
    let id = UUID()
    let name: String
    var subfolders: [Folder] = []
    var files: [String] = []
}

struct FolderView: View {
    let folder: Folder
    
    var body: some View {
        List {
            ForEach(folder.subfolders) { sub in
                NavigationLink(destination: FolderView(folder: sub)) {
                    Text(sub.name)
                }
            }
            ForEach(folder.files, id: \.self) { file in
                Text(file)
            }
        }
    }
}

struct MainView: View {
    @State var selectedTab = 0
    let folder = Folder(name: "Root")
    
    var body: some View {
        TabView(selection: $selectedTab) {
            Text("List View")
                // UNCOMMENT TO TRIGGER BUG:
                // .navigationTitle("List")
                .tag(0)
            
            FolderView(folder: folder)
                // UNCOMMENT TO TRIGGER BUG:
                // .navigationTitle("Files")
                .tag(1)
        }
        .tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
    }
}

struct ContentView: View {
    var body: some View {
        TabView {
            NavigationStack {
                MainView()
                    // UNCOMMENT TO TRIGGER BUG:
                    // .navigationTitle("Main")
            }.tabItem { Text("Tab 1") }
            
            NavigationStack {
                Text("Empty View")
            }.tabItem { Text("Tab 2") }
        }
    }
}

#Preview { ContentView() }

The issue doesnt happen if one uses separate navStack without nesting for each item in the nested tabView with pageStyle in my case, but that means it will feel as if we are having 2 separate screens while swiping to next page

this issue occurs only when navtitle is .large or implicitly .large, doesn't matter if one is using custom back button or hiding the back button.

.navigationTitle causes hang when creating a new item on a separate page, then navigating back to a TabView with PageTabViewStyle that is displaying that data on iOS 18.2
 
 
Q