Tlaster / PreCompose

Compose Multiplatform Navigation && State Management

Home Page:https://tlaster.github.io/PreCompose/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Android] Scene with backStackEntry called multiple times

ronjunevaldoz opened this issue · comments

I suspect that the scene with back stack entry is being loop by the total number of scenes?

scene(route = "/screens/home") {
}
scene(route = "/screens/settings") {
}
scene(route = "/screens/menu") {
}
scene(route = "/${Routes.ADD_EDIT_TASK}/{taskId}") { backStackEntry -> 
   println("scene called")
   // only experience the issue when below line is included
   backStackEntry.path<String>("taskId")?.let { taskId ->
      // empty implementation
   }
}

Output with backStackEntry.path<String>("taskId")?.let { taskId ->

scene called
scene called
scene called
scene called

Output without backStackEntry.path<String>("taskId")?.let { taskId ->

scene called

As I understand it, it's normal for a composable function to be called many times (I usually assume the composable function is called 10000 times). So if the call doesn't have a performance impact, I think it's ok overall.
And the back stack entry is constructed only when navigating to the new scene, and precompose does not loop the back stack entry.

Hey @ronjunevaldoz the issue seems to occur because BackStackEntry is seem as unstable, so when a scene interacts with it will cause a recomposition.

@Tlaster I've opened a PR #162 that tries to mitigate the issue in the least intrusive way possible.

Close as fixed.