why is onAppear called twice on group in ZStack?

Is this a bug or why does "white" get printed to console twice but "black" only once in the below code? If I take out the Text() call then it works like I expect (both onAppear modifiers only called once).


import SwiftUI


struct ContentView: View {

var body: some View {

ZStack {

Group {

Rectangle().fill(Color.black)

}

.onAppear() {print("black")}


Group {

Rectangle().fill(Color.white)

Text("black on white").foregroundColor(.black)

}

.onAppear() { print("white")}

}

}

}


struct ContentView_Previews: PreviewProvider {

static var previews: some View {

ContentView()

}

}

I'm having the same problem. Any solution?
Bug in SwiftUI lifecycle — Apple acknowledged it in a ticket I put out but that's as far as I've gotten.
I'm having the same exact issue. Since Jimmy filed a ticket all we can do now is wait until they fix it.
@JimmyCricket do you have a FB number? I really hope this is fixed soon, I’d like to beta test with more users but I’d be hitting the API too often.
I was having this exact same issue - just installed XCode beta 4 and it's gone away. Worked for anyone else?

I would recommend using the following .task modifier:

Text("Smth") 
        .task(id: "some ID") {
            fetchData()
        }
why is onAppear called twice on group in ZStack?
 
 
Q