Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StateObject causes crashes with Stinsen #81

Open
Kondamon opened this issue Jul 17, 2022 · 6 comments
Open

StateObject causes crashes with Stinsen #81

Kondamon opened this issue Jul 17, 2022 · 6 comments

Comments

@Kondamon
Copy link

We have implemented StateObject into an app, as shown in the example below and we receive a lot of issues with the Coordinator such as crashes. The problems start to arise as soon as the StateObject is changed (due to updates). During debugging I have found out that the RouterStore holds a lot of Coordinators twice or three times and I guess this is the reason for the issues. However, I was not able to yet to create a minimal example for easier debugging of this issue.

struct TestApp: App {
    @StateObject var manager = Manager()
   
    var body: some Scene {
        WindowGroup {
            NavigationViewCoordinator(
                MainCoordinator()
            )
            .view()
            .environmentObject(manager)
        }
    }
}
@Kondamon Kondamon changed the title StateObjects causes multiple issues with Stinsen StateObject causes multiple issues with Stinsen Jul 17, 2022
@Kondamon Kondamon changed the title StateObject causes multiple issues with Stinsen StateObject causes crashes with Stinsen Jul 17, 2022
@onl1ner
Copy link

onl1ner commented Aug 19, 2022

Hello, @Kondamon!

I'm facing with the exact same issue, after EnvironmentObject updates whenever I try to route to other screen app crashes. Did you find a solution to this problem?

@Kondamon
Copy link
Author

@onl1ner, I didn‘t resolve the issue. Used another framework.

@onl1ner
Copy link

onl1ner commented Aug 20, 2022

Oh, I see, @rundfunk47 could you please help with this issue?

@rundfunk47
Copy link
Owner

rundfunk47 commented Aug 21, 2022

I would recommend against using RouterStore. It will probably be removed in the next version. Instead, I'd recommend you to use whatever dependency injection framework or method you already use throughout your app and put the coordinators there.

Stinsen is not a dependency injection framework and RouterStore comes pretty close to that.

With that being said, I should give it a look 👀

@LePips
Copy link
Collaborator

LePips commented Dec 23, 2022

A StateObject should not live at the App level, it will trigger a redraw of the view for new changes and is just generally inadvisable. This is probably throwing the RouterStore into a weird state.

@fahmi-dzulqarnain
Copy link

fahmi-dzulqarnain commented Jan 11, 2023

Facing the same issue when trying to implement background scene phase

@Environment(\.scenePhase) private var scenePhase

var body: some Scene {
        WindowGroup {
            MainCoordinator()
                .view()
                .onChange(of: scenePhase) { currentPhase in
                    guard currentPhase == .background else {
                        return
                    }
                    
                    print("App run in background")
                }
        }
}
    

Is this issue still doesn't have a solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants