Compose Web: wrong instance remembered when several remember calls in one scope
See original GitHub issueClicking the foo
button the second and subsequent times causes the code for the bar
button to be executed.
fun main() {
renderComposableInBody {
val words = remember { mutableStateListOf<String>() }
words.map { P { Text(it) }}
Button(attrs = { onClick { words.add("foo") } }) { Text("foo") }
Button(attrs = { onClick { words.add("bar") } }) { Text("bar") }
}
}
Following is the build.gradle
:
plugins {
kotlin("multiplatform") version "1.7.20"
id("org.jetbrains.compose") version "latest.release"
kotlin("plugin.serialization") version "latest.release"
}
repositories {
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
google()
}
kotlin {
js(IR) {
browser()
binaries.executable()
}
sourceSets {
val jsMain by getting {
dependencies {
implementation(compose.web.core)
implementation(compose.runtime)
implementation("io.ktor:ktor-client-core:latest.release")
implementation("io.ktor:ktor-client-content-negotiation:latest.release")
implementation("io.ktor:ktor-client-js:latest.release")
implementation("io.ktor:ktor-serialization-kotlinx-json:latest.release")
}
}
}
}
Issue Analytics
- State:
- Created 10 months ago
- Comments:7
Top Results From Across the Web
Side-effects in Compose
A side-effect is a change to the state of the app that happens outside the scope of a composable function. Due to composables'...
Read more >What does Jetpack Compose remember actually do, how ...
Compose offers tools for observing changes in your app's data, which will automatically recall your functions—this is called recomposing.
Read more >Scoped recomposition in Jetpack Compose
When a recompose scope is invalidated, the compose runtime will ensure the (entire) function body gets recomposed (reexecuted) before the next ...
Read more >4.4 Bean scopes
Scopes a single bean definition to a single object instance per Spring IoC ... scope (remembering that the singleton lifecycle scope is the...
Read more >Variable scope, closure
If we call counter() multiple times, the count variable will be ... A closure is a function that remembers its outer variables and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It probably should also work with Compose 1.2.1 and Kotlin 1.7.10, because Compose Multiplatform supports multiple Kotlin’s
Thank you @eymar for the quick diagnosis and a workaround that helped unblock me! I can’t wait to complete my 100% Kotlin (client+server) app and show it off to everybody 😃
PS: My specific case also worked fine using 1.2.1 and 1.7.10, but I’ll be more conservative and stick to 1.2.0 on 1.7.10.