kotlinx.html
kotlinx.html copied to clipboard
Output stream dies if attributes are added after Tag's content
I was getting stuck with nothing being output when using this block:
label("bmd-label-floating") {
+labelName
htmlFor = name
}
Then I realised that when streaming a response all the attributes have to come first. Not sure what should happen, but instead of breaking the output stream and terminating I would really prefer an exception to be thrown.
Thankfully this works, I'll just have to remember to be more strict with the order:
label("bmd-label-floating") {
htmlFor = name
+labelName
}
Could you please show me exact example? I can reproduce it neither with createHtml
nor appendHtml
. It throws IllegalStateException
This might be a Ktor issue, I'll try an produce a case for you.
Hey there, resurrecting this issue to point out I've had the same issue, using ktor. Simplest repro:
routing {
get("/") {
call.respondHtml { renderHomePage() }
}
}
internal fun HTML.renderHomePage() {
body {
span {
+"refresh"
onClick = "javascript:location.reload();"
}
}
}
If you set onClick
before setting the text, as Chris suggests, then the issue is gone.