WebReflection / lighterhtml

The hyperHTML strength & experience without its complexity 🎉
https://medium.com/@WebReflection/lit-html-vs-hyperhtml-vs-lighterhtml-c084abfe1285
ISC License
735 stars 20 forks source link

[svg] InUseAttributeError: Attribute already in use #22

Closed nitely closed 5 years ago

nitely commented 5 years ago

I get this error when setting a dynamic class in children elements:

import {render, svg} from '//unpkg.com/lighterhtml?module';

const someClass = "foobar"
todo(document.body);
function todo(node, items = []) {
  let texts = ['a', 'b']
  const child = () => svg`
  <svg width="200" height="200">
    <g class="foo">
    ${texts.map((t, i) => svg`
      <rect x=${20 * i} y="35" width=10 height=10 class=${t}></rect>
    </g>`)}
  </svg>`
  render(node, child)
}
WebReflection commented 5 years ago

you have a typo in your code ... you cannot close </g> there, and you also don't need svg to create <svg> nodes, 'cause those are created out of HTML.

import {render, html, svg} from '//unpkg.com/lighterhtml?module';

const someClass = "foobar"
todo(document.body);
function todo(node, items = []) {
  let texts = ['a', 'b']
  const child = () => html`
  <svg width="200" height="200">
    <g class="foo">
    ${texts.map((t, i) => svg`
      <rect x=${20 * i} y="35" width=10 height=10 class=${t}></rect>
    `)}
    </g>
  </svg>`
  render(node, child)
}

does it work now?

nitely commented 5 years ago

Sorry about that. No, still, same error. The original code had no typo.

Edit: Ah, seems like you fixed it. Thanks!

WebReflection commented 5 years ago

mind checking if using https://raw.githubusercontent.com/WebReflection/lighterhtml/master/index.js and const {render, html, svg} = lighterhtml would work?