JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.92k stars 1.16k forks source link

Entire app fails because of the `LazyColumn` with `v1.5.0-beta01` #3463

Open JamshedAlamQaderi opened 1 year ago

JamshedAlamQaderi commented 1 year ago

Describe the bug I'm trying to create a scrollable column. When i've tried with LazyColumn then it crashes the app with below error into browser when loading.

IllegalArgumentException {message: 'Failed requirement.', cause: undefined, name: 'IllegalArgumentException', stack: 'IllegalArgumentException: Failed requirement.\n    …d (http://localhost:8080/fmadmin-web.js:49611:17)'}cause: undefinedmessage: "Failed requirement."name: "IllegalArgumentException"stack: "IllegalArgumentException: Failed requirement.\n    at BringIntoViewResponderNode.get_current [as get_current_76jhw1_k$] (http://localhost:8080/fmadmin-web.js:3024:13)\n    at _get_localParent__9fzpok (http://localhost:8080/fmadmin-web.js:212209:18)\n    at protoOf.get_parent_hy4reb_k$ (http://localhost:8080/fmadmin-web.js:212239:26)\n    at syncAggregateChildKindSet (http://localhost:8080/fmadmin-web.js:164695:19)\n    at protoOf.updateFrom_rn6bgr_k$ (http://localhost:8080/fmadmin-web.js:165165:7)\n    at protoOf.set_modifier_cidbkm_k$ (http://localhost:8080/fmadmin-web.js:159452:18)\n    at ComposeUiNode$Companion$SetModifier$lambda (http://localhost:8080/fmadmin-web.js:155501:16)\n    at http://localhost:8080/fmadmin-web.js:46948:7\n    at http://localhost:8080/fmadmin-web.js:47321:13\n    at applyChangesInLocked (http://localhost:8080/fmadmin-web.js:49611:17)"[[Prototype]]: RuntimeExceptionconstructor: ƒ IllegalArgumentException()[[Prototype]]: Exception

I'm using this code for LazyColumn

@OptIn(ExperimentalResourceApi::class)
@Composable
fun DrawerContent() {
    val avatarPicture = resource("jamshed_pic.jpg").rememberImageBitmap()
    Column(modifier = Modifier.fillMaxSize()) {
        Column(
            modifier = Modifier.fillMaxWidth().padding(top = 20.dp),
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            Avatar(avatarPicture.orEmpty())
            Spacer(Modifier.height(10.dp))
            Text("Jamshed Alam Qaderi", style = MaterialTheme.typography.bodyLarge)
            Spacer(Modifier.height(5.dp))
            Text("alamj406@gmail.com", style = MaterialTheme.typography.bodySmall)
            Spacer(Modifier.height(10.dp))
            Divider()
        }
        Spacer(Modifier.height(10.dp))
        LazyColumn {
            items(DrawerListItems) { state ->
                when (state) {
                    is DrawerListState.Header -> DrawerItemHeader(state.title)
                    is DrawerListState.Item -> DrawerItem(state.icon, state.type.text)
                }
            }
        }
    }
}

Affected platforms Select one of the platforms below:

If the bug is Android-only, report it in the Jetpack Compose tracker

Versions

To Reproduce Steps and/or the code snippet to reproduce the behavior:

  1. Use the kotlin.version to 1.9.0 and compose.version to 1.5.0-beta01
  2. Use the below code in the web module
    @OptIn(ExperimentalComposeUiApi::class)
    fun main() {
    onWasmReady {
        CanvasBasedWindow("FM Admin") {
            LazyColumn {
                items(DrawerListItems) { state ->
                    when (state) {
                        is DrawerListState.Header -> DrawerItemHeader(state.title)
                        is DrawerListState.Item -> DrawerItem(state.icon, state.type.text)
                    }
                }
            }
        }
    }
    }
  3. Then run it using ./gradlew :web:jsBrowserRun
  4. You'll see nothing is rendering and an error in the console

Expected behavior LazyColumn was working with 1.4.0 but idk what happens with LazyColumn in 1.5.0-beta01

Screenshots

Screenshot 2023-08-06 at 11 19 58 AM

Additional context Thank you all for bringing the awesome leading edge technology. I always wanted to make multiplatform apps using kotlin...

eymar commented 1 year ago

Thanks! It's a known issue. It will be fixed in k/js: https://youtrack.jetbrains.com/issue/KT-60635/K-JS-Class-internal-methods-may-clash-with-child-methods-from-other-module-that-have-the-same-name

As a workaround you can add kotlin.incremental.js.ir=false to your gradle.properties

eymar commented 1 year ago

We'll add a workaround on Compose side: https://github.com/JetBrains/compose-multiplatform-core/pull/734 So it should start working without kotlin.incremental.js.ir=false in the next compose builds.

JamshedAlamQaderi commented 1 year ago

Thanks. I'm gonna give it a try

JamshedAlamQaderi commented 1 year ago

Thank you @eymar it worked. Also waiting for the build to use IR compiler

sureshmaidaragi1919 commented 2 months ago

Any update on this issue?

okushnikov commented 3 weeks ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.