I have had this same issue, after hearing you say about cpu maxing I checked my own program and saw that was the same case for me.
After some playing around here's what I noticed:
- Clicking the
NavigationLink
caused my app to stop responding - Clicking the
NavigationLink
caused my CPU to constantly be at 99-100% - Clicking the
NavigationLink
caused my App Memory to steadily increase in about the same increment it took to load the page in another view - Calling the destination view that was causing an error in a different parent view no longer causes an error and the destination view loads
- The
NavigationLink
doesn't work anywhere within the view, I tested in multiple places in the ViewBuilder
- The destination view was tested with a newly generated object,
JobFile()
, to rule out it being unable to locate the custom object job
from the list it originally comes from
Some notes about the destination view:
- The body of the destination view was a simple body of
Hello, World!
, so the error is probably happening upon initialization or in the NavigationLink
itself - The destination view only has 2 properties:
var body: some view
and @Binding var job: JobFile
, where JobFile
is a small, simple, and Identifiable
object - The destination view is using the default initializer, there is not a custom
init()
implemented
Parent view notes:
- The parent view originates from a
NavigationStack
- The parent view is consistently located at a 3rd level in its parent
NavigationStack
It seems there is something that may be wrong with the parent view itself, or how it is working in tandem with the navigation stack. Any help would be appreciated.
I've had similar issue. When clicking NavigationLink there was an infinite init loop. It appears to be caused by initiating a class object labeled as @State instead of @StateObject.
@State var viewModel = PortalSelectionViewModel() corrected to @StateObject var viewModel = PortalSelectionViewModel()
For me it started happening when I added
@Environment(.dismiss) var dismiss
in one of the views that also contains navigationDestination
@emovla did you use .environment or .environmentObject in "navigationDestination" ? remove that, you will find loop won't happen anymore. To complete fix this problem, use NavigationLink(destination,lable) instead of navigationDestination