Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recomposition happens when Compose code comes from a dependency module #4967

Open
bitspittle opened this issue Jun 14, 2024 · 2 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@bitspittle
Copy link

Please check out this project which demonstrates the issue:

https://github.com/DennisTsar/bug-reports/tree/kotlin/compose/recomposition-1

Copying the README from that project here:


Compose 1.6.0+ Recomposition Issue

  • Run ./gradlew app:jvmRun -DmainClass=MainKt or ./gradlew app:jsBrowserDevelopmentRun and enter text into the
    textfield. Observe that the first CustomRow does not recompose on button click, but the second does.
  • If contents of lib are moved to app, the issue goes away
  • JVM behavior has occurred since at least Compose 1.5.12/Kotlin 1.9.22
  • JS behavior began with Compose 1.6.0/Kotlin 1.9.22
  • Still present on both targets with Compose 1.6.11 & Kotlin 2.0.0
@bitspittle bitspittle added bug Something isn't working submitted labels Jun 14, 2024
@Schahen Schahen removed the submitted label Jun 14, 2024
@Schahen Schahen assigned shishkin-pavel and unassigned MatkovIvan Jun 14, 2024
@bitspittle
Copy link
Author

bitspittle commented Jun 17, 2024

Just to emphasize how problematic this bug potentially is, I added the following code to my local project (a web project built using Kobweb):

var msg by remember { mutableStateOf("") }
TextInput(msg, onTextChanged = { msg = it }, ...)

// Sibling element which should NOT be affected by text input changes
Row(horizontalArrangement = Arrangement.spacedBy(10.px)) {
    var recomposeCount by remember { mutableStateOf(0) }
    recomposeCount++
    Text("Recompose count: $recomposeCount (should stay at 1)")
}

I expected one extra recomposition per character I typed into my text box, which would already have been a little bad, but instead I got a case of infinite, non-ending recompositions! This would have been invisible waste if I hadn't surfaced them via a text element:

recompose-out-of-control.mp4

Once I added the @Immutable annotation to the empty RowScope interface (as the repro project suggests as a possible fix), the recompositions stopped.

This is clearly not intended behavior; Compose should not be getting confused about the immutability of an empty interface.

@m-sasha
Copy link
Contributor

m-sasha commented Jun 19, 2024

Does it behave differently on Android?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants