SwiftUI subview .frame ignored on parent view appear, MacOS

When a parent view is selected for the detail pane of a NavigationSplitView subviews appear as expected but not with the dimensions set by .frame on the subview.

Toggling the flag works as expected, appearing the subview with the idealWidth. I persist the flag in a SwiftData @Model class so that on restart and first appearance of the parent view the Right View subview presence is as it was left. The problem is that the .frame size is ignored, apparently. No manner of programatic view refresh seems to trigger a resize to the preferred values, only toggling the flag.

Is there a better way to handle a collapsing subview in an HSplitView? Why is the .frame not respected?

In this example I've added the else clause so HSplitView always has two views with .frame settings but the result is the same without it.

    VStack {
      HSplitView {
        
        VStack {
          Text("left view")
        }
        .frame(
          minWidth: 100,
          idealWidth: .infinity,
          maxWidth: .infinity,
          maxHeight: .infinity
        )
            
        if documentSettings.nwIsPieChartShowing {
          VStack {
            Text("right view")
          }
          .frame(
            minWidth: 100,
            idealWidth: 200,
            maxWidth: .infinity,
            maxHeight: .infinity
          )
        }
        else {
          Text("")
            .frame(
              minWidth: 0,
              idealWidth: 0,
              maxWidth: 0,
              maxHeight: .infinity
          )
        }
      }

      HStack {
        Button("Right View",
               systemImage: { documentSettings.nwIsPieChartShowing ? "chart.pie.fill" : "chart.pie"}(),
               action: { documentSettings.nwIsPieChartShowing.toggle() }
        )
      }
    }
  }
}

MacOS Sequoia 15.3.1, Xcode 16.2

Adding .layoutPriority(1) to Text("left view") seems to have solved the problem. Still not sure if this is the best way to go so open to other ideas,

Is there a better way to handle a collapsing subview in an HSplitView? Why is the .frame not respected?

Have you checkout out inspector? Since you're using a NavigationSplitView, an inspector would present as a trailing column and by default, trailing column inspectors have their presentation state restored by the framework.

SwiftUI subview .frame ignored on parent view appear, MacOS
 
 
Q