Infinite loop getting "_dismiss changed"

I'm working on a NavigationStack based app. Somewhere I'm using:

@Environment(\.dismiss) private var dismiss

and when trying to navigate to that view it gets stuck.

I used Self._printChanges() and discovered the environment variable dismiss is changing repeatedly. Obviously I am not changing that variable explicitly. I wasn't able to reproduce this in a small project so far, but does anybody have any idea what kind of thing I could be doing that might be causing this issue?

iOS 17.0.3

Have you found a solution?

@gbuela , have you found a solution?

Weirdly enough, for me it happened because I had an array of tuples inside my View.

You don't even have to use the array, just having it in the View was enough to cause the infinite loop:

struct SomeView: View {
  ...
  var sections: [(String, String)] = [
    ("String 1", "value 1"),
    ("String 2", "value 2"),
    ("String 3", "value 3"),
    ("String 4", "value 4")
  ]

  var body: some View {
    ...
  }
}

I have a similar bug. It helped to put the data array inside an ObservableObject. The dismiss variable still seems to change 3-4 times when the view appears but after that it seems to stabilise

I just struggled with this problem for a while -- what has seemed to fix my problem was removing the @State property wrapper from variables that shouldn't have had the wrapper in the first place (Date, Timer...). Always heard that @State should only be used for simpler types but this is the first instance where it really gave me a headache... now I know, hopefully it saves someone else some time.

I am facing the same issue, no idea how to fix it.

Was anyone able to find a solution yet? Thank you

Infinite loop getting "_dismiss changed"
 
 
Q