Skip to content

Conversation

@mbarta
Copy link
Collaborator

@mbarta mbarta commented Aug 20, 2025

Sometimes, currentDestination is accessed outside of the lifecycle of the NavigatorHost fragment.

Navigator.logEvent tries to call Navigator.getCurrentDestination.
This in turn calls NavigatorHost/Fragment.getChildFragmentManager.

When the Fragment (NavigatorHost) is not attached, it throws an IllegalStateException("Fragment ... has not been attached yet.").

I believe it should be enough to check that the Fragment is added and if it isn't, return null (which is a valid value for Navigator.getCurrentDestination).

@mbarta mbarta requested review from jayohms and jhutarek August 20, 2025 12:26
@mbarta mbarta self-assigned this Aug 20, 2025
val currentDestination: HotwireDestination?
get() = currentDialogDestination as? HotwireDestination
?: host.childFragmentManager.primaryNavigationFragment as? HotwireDestination
?: if (host.isAdded) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using the NavigatorHost.isReady() function, which is a bit more comprehensive?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point 👍

Copy link
Contributor

@jayohms jayohms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely, thank you!

@mbarta mbarta merged commit 5cb29db into main Aug 20, 2025
1 check passed
@mbarta mbarta deleted the mb/crash_fixes branch August 20, 2025 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants