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

hasRoot / isRoot crashes app #96

Open
emartinson opened this issue Sep 18, 2022 · 1 comment
Open

hasRoot / isRoot crashes app #96

emartinson opened this issue Sep 18, 2022 · 1 comment

Comments

@emartinson
Copy link

emartinson commented Sep 18, 2022

Hi! I've adapted example app to handle deeplink, but app crashes when trying to get current coordinator:

final class AppCoordinator: NavigationCoordinatable {
    var stack: Stinsen.NavigationStack<AppCoordinator>

    @Root var unauthenticated = makeUnauthenticated
    @Root var authenticated = makeAuthenticated

    init() {
        let user = User() // obtaining user from persistent store
        stack = NavigationStack(initial: \AppCoordinator.authenticated, user) // this is also handled by auth state listeners
    }
    
     func makeUnauthenticated() -> NavigationViewCoordinator<UnauthenticatedCoordinator> {
        NavigationViewCoordinator(UnauthenticatedCoordinator())
    }

    func makeAuthenticated(param user: User) -> NavigationViewCoordinator<MainCoordinator> {
        NavigationViewCoordinator(MainCoordinator(user: user)) // MainCoordinator is a simple navigaion view coordinator
    }

    func handleDynamicLink(_ url: URL) {
        guard let coordinator = self.hasRoot(\.authenticated) else { // <-- Crashes here.  self.isRoot(\.authenticated) causes the same crash
            return
        }
    }
}

Crash in NavigationCoordinatable.swift, line 661, col 21

Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

Printing description of route:
<ReferenceWritableKeyPath<AppCoordinator, Transition<AppCoordinator, RootSwitch, User, NavigationViewCoordinator>>: 0x280687280>
Printing description of inputItem: nil

((input: App.User, comparator: ())?) inputItem = nil
Printing description of self:
<AppCoordinator: 0x283d59500>

Screenshot 2022-09-18 at 13 27 54

App and coordination logic works perfectly, but this check on AppCoordinator level causes the crash.

It looks that unwraping
var root: NavigationRoot!
from NavigationStack (NavigationStack.swift, line 29) causes the crash. What is the reason for this crash and how to solve it?

Stinsen (2.0.7)
MacOS 12.6, XCode 14 Release, iOS 15-16

@emartinson
Copy link
Author

Hi, any updates here? Maybe there are other ways to check if we're currently presenting this screen? Or mark some routes as exclusive (may be showed only once at a time)

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

1 participant