Kotlin / kotlinx.html

Kotlin DSL for HTML
Apache License 2.0
1.61k stars 132 forks source link

IllegalStateException: "Wrong current tag" on try to change `classes` when class inherits HTMLTag and CommonAttributeGroupFacadeFlowInteractivePhrasingContent #148

Open ivakub opened 4 years ago

ivakub commented 4 years ago

Initial report - https://discuss.kotlinlang.org/t/custom-components/17731/5 Code:

import kotlinx.html.*
import kotlinx.html.dom.append
import kotlin.browser.document

@ExperimentalStdlibApi
fun main() {
    document.body!!.append {
        p {
            testButton()
        }
    }
}

@HtmlTagMarker
@ExperimentalStdlibApi
fun FlowOrInteractiveOrPhrasingContent.testButton() {
    TestButton(
        consumer
    )/*.test()*/
}

class TestButton(consumer: TagConsumer<*>) :
    BUTTON(
        attributesMapOf(),
        consumer
    ), Tag {
    init {
        console.log(classes)
        classes += setOf("class")
        console.log("DONE")
    }

//    fun test() {
//        classes += setOf("class")
//    }
}

Leads to the IllegalStateException on runtime: custom-components

Dependencies:

dependencies {
    implementation(kotlin("stdlib-js"))
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.5")
    implementation("org.jetbrains:kotlin-react:16.13.0-pre.94-kotlin-1.3.70")
    implementation("org.jetbrains:kotlin-react-dom:16.13.0-pre.94-kotlin-1.3.70")
}

Project in the attachment. halos-console.zip