https://kotlinlang.org logo
#compose-web
Title
# compose-web
s

salomonbrys

09/27/2021, 6:01 PM
Is it possible to understand what triggered recomposition ? I have 2 compositions in sequence and I'd like to understand why.
o

Oleksandr Karpovich [JB]

09/27/2021, 6:23 PM
Do you have code sample? I don't know about any tool to see what triggers recomposition. Usual debugging is the only thing that comes to mind
s

salomonbrys

09/27/2021, 8:23 PM
Nope. My code is fairly complex, and I'm pretty sure it's my fault. I just need to find where.
@Oleksandr Karpovich [JB] It looks like the double compoise I get is due to using "CSS classes in components". The following code generates a double composition:
Copy code
object MyStyle : StyleSheet()
fun main() {
    renderComposableInBody {
        println("Composing!")
        Style(MyStyle)
        var bool by remember { mutableStateOf(false) }
        Div({
            classes(MyStyle.css {
                backgroundColor(if (bool) Color.red else Color.blue)
            })
        }) {
            Button({
                onClick { bool = !bool }
            }) { Text("Change color!") }
        }
    }
}
While the following code only composes once:
Copy code
fun main() {
    renderComposableInBody {
        println("Composing!")
        var bool by remember { mutableStateOf(false) }
        Div({
            style {
                backgroundColor(if (bool) Color.red else Color.blue)
            }
        }) {
            Button({
                onClick { bool = !bool }
            }) { Text("Change color!") }
        }
    }
}
@Oleksandr Karpovich [JB] Here is a project demonstrating the jank: https://github.com/SalomonBrys/demo-InHeadComposeStyleSheet And here is the corresponding issue I've opened: https://github.com/JetBrains/compose-jb/issues/1207