Debugging to find out why View is bring re-drawn

Hey all,

I have a complex View that sometimes it's getting re-created for some events that I do not understand. I put the _PrintChanges() in the View body, and here's what I got:

EditPageComponentControlHostView: @self, @identity, _pageController, _componentController, _hasContent changed.
struct EditPageComponentControlHostView: View {
    @Environment(EditPageController.self) var pageController

    @State private var componentController = EditPageComponentController()
    @State private var hasContent = false

It seems like the View is being reset since the @State hasContent has been reset. It seems like if the View's @identity has changed, SwiftUI will re-create the view hence the variable _hasChanged has been reset.

So I tried:

  1. conform EditPageComponentControlHostView to Equatable, and @identity is still changing.
  2. Set id on EditPageComponentControlHostView like this:
EditPageComponentControlHostView()
       .id("Test")

and it still changing the identity. What did I miss? Thanks!

struct ContentView: View {
  @State var text = "[This is some long text that will be cut off at the end of the text editor]"

  var body: some View {
    Text(text).opacity(0.0).padding()
      .overlay { TextEditor(text: $text) }
  }
}
Debugging to find out why View is bring re-drawn
 
 
Q