Open mahmed1987 opened 10 months ago
Hi, I tried to research this case. This is what I found out. You are right fun SearchRoute() should be skipable.
restartable skippable scheme("[androidx.compose.ui.UiComposable]") fun SearchRoute(
stable modifier: Modifier? = @static Companion
stable onBackClick: Function0<Unit>
stable onInterestsClick: Function0<Unit>
stable onTopicClick: Function1<String, Unit>
bookmarksViewModel: BookmarksViewModel? = @dynamic hiltViewModel(null, $composer, 0, 0b0001)
interestsViewModel: InterestsViewModel? = @dynamic hiltViewModel(null, $composer, 0, 0b0001)
unstable searchViewModel: SearchViewModel? = @dynamic hiltViewModel(null, $composer, 0, 0b0001)
forYouViewModel: ForYouViewModel? = @dynamic hiltViewModel(null, $composer, 0, 0b0001)
But Layout Insperector shows that on every search SearchRoute run twice:
I wrapped the function like that:
The SearchRoute runs ones
I fink SearchRouteInternal runs several times because we use
in it.
hey @AntonButov .
This is something to do with the passed lambdas , which are hooked onto method references , yet their usage is causing unnecessary recompositions .
I made a small project to demonstrate this here .
For some reason , despite using method references , instead of lambdas , we are getting state changes
You will find that despite absolutely no state change , the the target composable marked skippable , the Composable always recomposes .
Is there an existing issue for this?
Is there a StackOverflow question about this issue?
What happened?
I am not sure if this is a bug or not but as per basic Compose tenets , a composable will NOT recompose if its state remains unchanged from the first time it was composed .
I have attached a breakpoint and confirmed that when SearchRoute recomposes , none of its arguments have changed.
I am aware that this composable's callsite does gets recomposed multiple times , but I am unsure as to why does this cause its child composable (SearchRoute) to recompose .
This is strange specially because we are not passing unstable lambdas in SearchRoute , rather are relying on method references (which correctly remain the same upon recomposition).
Take a look at both these screenshots , and observe all references are similar. One screenshot was taken on first time around , and the second is of the recomposition
Relevant logcat output
No response
Code of Conduct