Mauth icon indicating copy to clipboard operation
Mauth copied to clipboard

bug: double navigation and navigation crashes

Open ssalggnikool opened this issue 4 months ago • 4 comments

issue

spam clicking a button that navigates to a different screen can cause the navigation to occur multiple times

if the navigation in question is navigator::pop, it will crash the app if you navigate backwards at the root of the navigation

https://github.com/user-attachments/assets/ab3b348a-fb25-4ba9-9c50-340f3e71c275

in this video i'm spam clicking the settings button, observe how I have to click back many times because settings has been pushed many times

then i spam click the back button, which results in a crash

solution

wrap all navigations in dropUnlessResumed (this is recommended by google and it is what i am doing to resolve it in Navic)

it is very tedious to wrap everything in dropUnlessResumed and i don't want to make a massive change like that in every single file so i will leave this up to discussion for a better solution if needed

ssalggnikool avatar Jul 07 '26 03:07 ssalggnikool

Ugh I forgot Navigation3 doesn't do this automatically.

X1nto avatar Jul 07 '26 08:07 X1nto

@ssalggnikool dropUnlessResumed fixes double back but not double navigation in general, what did you use in Navic for that?

X1nto avatar Jul 08 '26 10:07 X1nto

Apparently dropUnlessResumed will only work if you use it directly within the screen's composable, not within the entry provider:

https://slack-chats.kotlinlang.org/t/18829110/hey-guys-i-m-trying-to-wrap-my-head-around-the-new-dropunles

the above is not for navigation3, but the same thing could probably be the case here, not sure

this is the only thing I am doing differently in navic, so that could be why it's working there, but this doesn't really make any sense to me as the lifecycle owner should resolve to the same owner regardless of if you're inside of the entry provider or not. as an alternative you could check if the last back stack entry is not equal to the new entry you are pushing, and only push if that's the case, that is what I was doing before I learned dropUnlessResumed was a thing and it worked fine

ssalggnikool avatar Jul 08 '26 16:07 ssalggnikool

I might just implement time debouncing at this point.

X1nto avatar Jul 11 '26 21:07 X1nto