MrPowerGamerBR
10/10/2025, 2:12 AMkotlin-browser bindings for Web Components have changed quite a bit, and now I'm not able to get a custom element to workMrPowerGamerBR
10/10/2025, 3:32 AMimport web.components.ShadowRootInit
import web.components.ShadowRootMode
import web.components.customElements
import web.components.open
import web.dom.TagName
import web.html.HTMLElement
fun main() {
println("Howdy!")
customElements.define(TagName("test-element"), TestElement::class.js)
println("Registered element!")
}
@JsExport
@JsName("TestElement")
class TestElement : HTMLElement, web.components.CustomElement {
companion object {
@JsStatic
fun observedAttributes(): List<String> {
return listOf()
}
}
init {
println("Initialized!")
this.attachShadow(ShadowRootInit(mode = ShadowRootMode.open))
this.shadowRoot!!.innerHTML = "test"
}
override val connectedCallback = {
println("connected")
}
}
It does not throw any error when registering the component, but none of the debug print messages of the custom element are logged (only the Howdy! and Registered element! are printed) nor the callback is called
Kotlin 2.2.20 + kotlin-browser:2025.10.4Artem Kobzar
10/10/2025, 8:38 AMtest-element tag?turansky
10/10/2025, 11:57 AMCustomElementReference to avoid redundant @JsExport side effects (if you used @JsExport as workaroundturansky
10/10/2025, 12:02 PMfun main() {
println("Howdy!")
customElements.define(TagName("test-element"), TestElement)
println("Registered element!")
}
class TestElement : HTMLElement, web.components.CustomElement {
init {
println("Initialized!")
this.attachShadow(ShadowRootInit(mode = ShadowRootMode.open))
this.shadowRoot!!.innerHTML = "test"
}
override val connectedCallback = {
println("connected")
}
companion object : CustomElementReference(TestElement::class.js)
}MrPowerGamerBR
10/10/2025, 4:18 PM<html>
<head>
<script src="WebComponentsTest.js"></script>
</head>
<body>
<test-component></test-component>
</body>
</html>turansky
10/10/2025, 4:20 PMtarget = "es2015" ?MrPowerGamerBR
10/10/2025, 4:26 PMpackage com.mrpowergamerbr.webcomponentstest
import web.components.CustomElementReference
import web.components.ShadowRootInit
import web.components.ShadowRootMode
import web.components.customElements
import web.components.open
import web.dom.TagName
import web.html.HTMLElement
fun main() {
println("Howdy!")
customElements.define(TagName("test-element"), TestElement::class.js)
println("Registered element!")
}
class TestElement : HTMLElement, web.components.CustomElement {
init {
println("Initialized!")
this.attachShadow(ShadowRootInit(mode = ShadowRootMode.open))
this.shadowRoot!!.innerHTML = "test"
}
override val connectedCallback = {
println("connected")
}
companion object : CustomElementReference<TestElement>(TestElement::class.js)
}
but it still didn't work ๐, only the Howdy! and Registered element! shows up
here's the build script
import org.jetbrains.kotlin.gradle.dsl.JsModuleKind
plugins {
kotlin("multiplatform") version "2.2.20"
}
repositories {
mavenCentral()
}
kotlin {
js {
browser()
binaries.executable()
compilerOptions {
// Enable ES6
target = "es2015"
useEsClasses = true
this.moduleKind.set(JsModuleKind.MODULE_ES)
}
}
sourceSets {
jsMain {
dependencies {
implementation("org.jetbrains.kotlin-wrappers:kotlin-js:2025.10.4")
implementation("org.jetbrains.kotlin-wrappers:kotlin-browser:2025.10.4")
}
}
}
}turansky
10/10/2025, 4:45 PMturansky
10/10/2025, 4:45 PMturansky
10/10/2025, 4:58 PM@JsExport we don't receive right constructor - bug
2. For some reason Kotlin/JS remove connectedCallback field - bug (see screenshot)
3. Kotlin/JS generate invalid constructor if no () call on parent class
a. : HTMLElement - invalid constructor generated
b. : HTMLElement() - valid constructor generated
@MrPowerGamerBR could you please report them?turansky
10/10/2025, 4:59 PMMrPowerGamerBR
10/10/2025, 5:05 PMMrPowerGamerBR
10/10/2025, 5:07 PMturansky
10/10/2025, 5:49 PMthat would be a Kotlin/JS bug report right?Yes
turansky
10/10/2025, 5:50 PMAlso should I create a separate for each of the bugs?It's better to do separate issues
turansky
10/10/2025, 5:51 PMMrPowerGamerBR
10/10/2025, 7:21 PMMrPowerGamerBR
10/10/2025, 7:25 PMMrPowerGamerBR
10/10/2025, 7:31 PMMrPowerGamerBR
10/10/2025, 7:34 PMturansky
10/10/2025, 7:45 PMArjan van Wieringen
10/11/2025, 9:28 AMturansky
10/11/2025, 9:03 PMconnectedCallback and other callbacks if you are interested ๐MrPowerGamerBR
10/12/2025, 5:44 PM