Skip to content
Discussion options

You must be logged in to vote

@Doraemoe Your root app scene is creating a brand new store in its body, so when it detects a scene change your state is replaced with a brand new store with no path, which puts SwiftUI in a bad state. I believe you'd have the same problem in vanilla SwiftUI using an observable object.

The fix is to hold onto your store in your app so that it is never recreated:

@main
struct userdefault_tcaApp: App {
  @Environment(\.scenePhase) var scenePhase
  let store = Store(initialState: RootFeature.State()) {
    RootFeature()
  }

  var body: some Scene {
    WindowGroup {
      ContentView(store: self.store)
    }
  }
}

In general you should not create new models in the body of scenes or views as…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Doraemoe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2534 on October 28, 2023 16:11.