NavigationSplitView 2-column loses state when minimized on iPad

Hello! I've noticed that when I am using NavigationSplitView and I minimize the app on iPadOS and then resume, if I am using a 2 column setup it loses state upon resume. This does not appear to happen on with a 3 column setup though. I'm wondering if others have run into this and if anyone has figured out a way around it. It seems like it's a bug and I should file a bug for it, but wanted to check with more people first.

Here's some example code, run it, select your number of columns, then minimize the app, count to 3 (because why not!) and open the app and you'll notice that $selection is now nil.

import SwiftUI



struct Item: Identifiable, Hashable {

  var id: Int

  var name: String

  var description: String

}



struct ContentView: View {



  @State var selection: Item?



  var items: [Item] = [

    .init(id: 1, name: "One", description: "Is the loneliest number"),

    .init(id: 2, name: "Two", description: "Two can be as bad as one"),

    .init(id: 3, name: "Three", description: "Three Dog Night")

  ]



  var body: some View {

    TabView {

      NavigationSplitView {

        List(items, selection: $selection) { item in

          NavigationLink(value: item) {

            Text(item.name)

          }

        }

      } content: {

        if let selection {

          Text(selection.name).font(.title)

          Text(selection.description)

        } else {

          EmptyView()

        }

      } detail: {

        VStack {

          Text("Detail here")

        }

      }

      .tabItem {

        Label("3 Columns", systemImage: "rectangle.split.3x1")

      }



      NavigationSplitView {

        List(items, selection: $selection) { item in

          NavigationLink(value: item) {

            Text(item.name)

          }

        }

      } detail: {

        if let selection {

          Text(selection.name).font(.title)

          Text(selection.description)

        } else {

          EmptyView()

        }

      }

      .tabItem {

        Label("2 Columns", systemImage: "rectangle.split.2x1")

      }

    }

  }

}



struct ContentView_Previews: PreviewProvider {

  static var previews: some View {

    ContentView()

  }

}

I can confirm the exact same behaviour (Xcode 14.3 (14E222b) on macOS 13.3.1 (22E261)). My sample code is this:

import SwiftUI

enum ListEntry: String, Identifiable {
	var id: String { rawValue }
	case banana
	case kiwi
	case orange
}

struct ContentView: View {
	var elements: [ListEntry] = [.banana, .kiwi, .orange]

	@State var selection: String? = nil

	var body: some View {
		NavigationSplitView {
			List(elements, selection: $selection) { e in
				Text("\(e.rawValue)")
			}.onChange(of: selection) { newValue in
				print("newValue = \(newValue ?? "<nil>")")
			}
//		} content: {
//			Text("Content")
		} detail: {
			Text("Selection \(selection ?? "<nil>")")
		}
	}
}

struct ContentView_Previews: PreviewProvider {
	static var previews: some View {
		ContentView().previewInterfaceOrientation(.landscapeLeft)
	}
}

Did you come up with a solution / workaround?

NavigationSplitView 2-column loses state when minimized on iPad
 
 
Q