mixpanel / snabbdom-jsx-lite

Write snabbdom templates in .jsx or .tsx (JSX for TypeScript)
MIT License
10 stars 1 forks source link

Unable to set attributes on SVG Elements #1

Closed strass closed 4 years ago

strass commented 4 years ago

I'm having trouble with SVGs. This creates the nodes and the polygon even has styles on it, but the attributes don't show up (nor do they when I use props):

<svg
      attrs={{
        height: "250",
        width: "450",
      }}
    >
      <polygon
        attrs={{
          points: "225,10 100,210 350,210",
        }}
        style={{
          fill: "white",
          stroke: "black",
        }}
      />
</svg>
nojvek commented 4 years ago

Lemme take a look. The example we have uses SVG, but lemme see if I can repro it. Unless you already have an open repo with repro code.

strass commented 4 years ago

I just figured it out. options allow text but not svgs lol. works fine, my bad. one thing I've found is that attributes cant be camelcased which isnt true elsewhere

nojvek commented 4 years ago

What do you mean by “options allow text not svgs?”

Attributes not being camel cases is a html dom limitation that is imposed by browser. Snabbdom is simply making setAttribute calls.

strass commented 4 years ago

html option elements dont allow arbitrary html inside, and were rendering unicode geometric characters but not svgs when I tried to switch over. my bad

I'm pretty sure I've noticed the props and style help transform camel case into kebab, but maybe I'm misremembering

nojvek commented 4 years ago

Yeah snabbdom jsx lite doesn’t do any special string transformations. String kungfu is expensive. That’s how we’re able to do a million vnodes in 100ms at ~10ns / jsx call.

The style module sets on elem.style which is camel cased. Same as props. They are camelCased as well.