https://kotlinlang.org logo
#compose
Title
# compose
r

rocketraman

01/07/2022, 9:13 AM
Is this a compose compiler bug? Using #compose-web, this inside a composable does the expected thing:
Copy code
@Composable
fun ElementScope<HTMLElement>.BlockChildLink(
  span: BlockChildSpan,
  markDefs: List<MarkDef>,
  content: @Composable ElementScope<HTMLElement>.() -> Unit
) {
  val link = span.marks.linkOrNull(markDefs)
  if (link != null) {
    A(href = link.href) {
      content()
    }
  } else content()
}
but this always results in empty content if the link is null i.e. the
content()
to the right of the elvis operator is ignored:
Copy code
@Composable
fun ElementScope<HTMLElement>.BlockChildLink(
  span: BlockChildSpan,
  markDefs: List<MarkDef>,
  content: @Composable ElementScope<HTMLElement>.() -> Unit
) {
  span.marks.linkOrNull(markDefs)?.let { link ->
    A(href = link.href) {
      content()
    }
  } ?: content()
}
e

ephemient

01/07/2022, 11:06 AM