I see that whenever recomposition happens because of changing uiState, the function reference is also a different instance from previous one which causes more recomposition for Composable which should not be recomposed.
z
Zoltan Demant
05/13/2025, 8:57 AM
Afaik, this happens because your function references the viewmodel, which is considered unstable. You could test adding @Stable to your viewmodel to verify what Im saying, Im pretty sure it wouldnt result in new functions everytime that way.
👍 1
a
aishwaryabhishek3
05/13/2025, 10:13 AM
@Zoltan Demant I marked viewModel as stable but the issue persists, the only way seems to be to wrap the fun ref in a remember 😕 .
sad panda 1
o
Olivier Patry
05/13/2025, 4:56 PM
I used to store the function references before entering the Compose world (before
setContent
) and then pass these variables down to my screens to solve this.
Copy code
class Activity... {
private val viewModel by viewModels()
fun onCreate(...) {
val foo = viewModel::foo
setContent {
MyTheme {
Surface {
MyScreen(viewModel, foo)
}
}
}
}
}
👀 1
s
shikasd
05/17/2025, 5:29 PM
Two instances of function references are not the same specifically because function reference can be to a local function and that can go wrong very fast
That being said, with strong skipping this no longer should be a problem, not sure why it recomposes here