shadaj/slinky

mapping a Seq to Seq[ReactElement] breaks Slinkly

utenma opened this issue · 2 comments

in react is quite common to map an Array[any] to an Array[React Element], like this

render() {
    return (
      <div>
          {people.map((person, index) => (
              <p>Hello, {person.name} from {person.country}!</p>
          ))}
      </div>
   );
}

unfortunately, slinky breaks when trying to map a Seq[String] to a Seq[ReactElement]

like the following, it doesn't change no matter if you use ascription :*

iconNames = Seq("currency_exchange", "face")
...
  div()(
    iconNames.map(iconName => MaterialIcon(iconName, color="red")): _*
  )

Throwables.scala:18 Uncaught org.scalajs.linker.runtime.UndefinedBehaviorError: java.lang.ClassCastException: undefined is not an instance of scala.collection.immutable.Seq

however, using sequence of react elements directly without mapping works

div())(
  Seq (
    MaterialIcon("face"),
    MaterialIcon("currency_exchange"),
  )
)

image

i wonder if the problem may be caused by implicit conversions and how could a workaround be

@saulpalv hmm, this is interesting. Perhaps I missed this, but what happens if you pass in the sequence directly without : _*? Although it should work correctly in both cases.

Oh, wait, just noticed that iconNames is mutable in your example. It seems that iconNames may not have been initialized by the time you use it.