-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Compose Web: wrong instance remembered when several remember calls in one scope #2535
Comments
Reproduced with compose version 1.2.1 and kotlin 1.7.20. Works as expected with compose version 1.2.0 and kotlin 1.7.10. |
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. |
@bgcl Did you encounter that issue in some more complex use cases? It looks like even with 1.2.1 (and kotlin 1.7.20) there is a weird workaround: @Composable
fun Content() {
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") }
}
fun main() {
renderComposableInBody {
Content()
}
}
// or:
fun main() {
val content = @Composable {
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") }
}
renderComposableInBody {
content()
}
} So I'm wondering if you had other cases/snippets where the issue takes place. |
It probably should also work with Compose 1.2.1 and Kotlin 1.7.10, because Compose Multiplatform supports multiple Kotlin's |
@eymar I applied your workaround to my more complex use case and it does not work with k1.7.20. I'm posting the full code below although you wouldn't know how to run it live. But essentially, refactoring the whole thing into a separate composable still doesn't work with k1.7.20 but it works with k1.7.10 -- regardless of compose 1.2.0/1.2.1. (not factoring it out also does not work with k1.7.20 but works with k1.7.10 -- regardless of compose 1.2.0/1.2.1)
|
Hey @bgcl we published a new build of compose compiler plugin you may want to try with kotlin 1.7.20. // in your build.gradle.kts
compose {
kotlinCompilerPlugin.set("1.3.2.2-beta01") // it's a temporary hack. The new compiler version will likely be included in compose-multiplatform 1.2.2
} The issue should be gone. Note: 1.3.2.2-beta01 is available only with:
|
@eymar that does seem to work! thank you for unblocking me so promptly on k1.7.20 :) (sorry for the delay in confirming) |
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks. |
Clicking the
foo
button the second and subsequent times causes the code for thebar
button to be executed.Following is the
build.gradle
:The text was updated successfully, but these errors were encountered: