https://kotlinlang.org logo
#compose
Title
# compose
f

Francois Morvillier

03/23/2022, 3:21 PM
Hi, is there a way to find out what triggered a recomposition?
r

Ronald Wolvers

03/23/2022, 5:27 PM
Not that I'm aware of, but - as far as I'm aware - there is only a limited number of predetermined points where a recomposition can happen at all. Generally anywhere a
LiveData
is used and has its value updated (or a
StateFlow
) or
remember[...]()
is called for a primitive or something else like a coroutine scope. I haven't myself come across other cases so far, which of course is not to say that there aren't many more
One option would be to pass a logger into the Composable I suppose, but to have a tool of some sort would be much nicer. If I come across something like it, I'll let you know, @Francois Morvillier! Very interesting question 🤔. If you find something and would let me know as well, I would appreciate it a lot!
m

myanmarking

03/23/2022, 8:15 PM
You can also use the compiler reports plugin and check the compsables you suspect shouldnt be recomposing. Generally, you find unstable arguments or non skippable composables which is most probably the cause
m

Michal Klimczak

03/23/2022, 8:39 PM
In practice, the easiest solution is usually the most brutal - remove composables until you find the culprit :)
6 Views