kotlinx.html icon indicating copy to clipboard operation
kotlinx.html copied to clipboard

Output stream dies if attributes are added after Tag's content

Open chrisjenx opened this issue 6 years ago • 3 comments

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
}

chrisjenx avatar May 12 '18 23:05 chrisjenx

Could you please show me exact example? I can reproduce it neither with createHtml nor appendHtml. It throws IllegalStateException

cy6erGn0m avatar May 14 '18 10:05 cy6erGn0m

This might be a Ktor issue, I'll try an produce a case for you.

chrisjenx avatar May 18 '18 17:05 chrisjenx

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.

rock3r avatar Jun 24 '20 08:06 rock3r