Pre-initialization of views?

It seems somewhere around the update to xcode 16 and swift 6, apple may have decided to change when view are initialized. My views suddenly pre-initialize before opening the view. Is this a new feature?

I have a regular VStack or a LazyVStack, with ForEach and navigationLinks inside. Those views that the navigation link takes you to are initializing as I am scrolling in the VStack. This is absurd, there is so much overhead going on in these views to be initialized. I can think of a fix which is to implement init functions in the onAppear, and keep a property to track if view already appeared. But before that I just want to make sure this is a new feature and not some mishap on my part, and if there is a way to disable it.

Thank you.

Could you please provide some context on the steps you took to debugged the issue and code snippet that would help in reproducing the issue.

Also, are you performing some operations in the onAppear closure? and are you using @State property wrapper to manage your view states.

Keep in mind that the onAppear(perform:) method is completed before the first rendered frame appears and SwiftUI makes no guarantee as to the exact time the method is called.

No I am currently not using onAppear. Just on viewmodel initialization, I do all the fetching.

Below you have two Views. HomeView is the parent view to PageTwo.

struct HomeView: View 
{ 
  init() 
  {
     print("Main View initialized") 
  } 
  var body: some View 
  { 
    NavigationStack { NavigationLink("Open") { PageTwo() } } 
  }
}
struct PageTwo: View 
{ 
  init() 
  { 
    print("Second View initialized") 
  }
  var body: some View 
  { 
    Text("")
  }
}

When HomeView appears, I get printouts of:

Main View initialized

Second View initialized

Both Views initialized even before I click Open to navigate me to the second view. This is did not happen before. I think around swift 6 update. Is this a bug or a feature? If a feature can it be disabled?

Pre-initialization of views?
 
 
Q