Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

129
Vistas
Can't insert a <polygon> inside an <svg> by printing its html with {@html} in Svelte

This is my parent component:

<script>
    import ObjOne from './ObjOne.svelte'
</script>

<svg width="182px" height="146px" viewBox="0 0 182 146">
    <ObjOne></ObjOne>
</svg>

And this is ObjOne:

<script>
  let html = '<polygon id="Path" fill="#999999" points="109.9999 146.25 109.9999 98.75 182.4999 98.75 182.4999 146.25" />'
</script>

{@html html}

The polygon doesn't render, unless I put the <polygon> directly in the component's body, as you can see in the REPL. Is there any workaround? I need to dynamically insert elements in an <svg>. I tried with version and xmlns properties on the <svg> but it didn't help.

REPL: https://svelte.dev/repl/14b354d830184a8d994cae6d223e4c85?version=3.49.0

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

This is a known issue with how @html generates elements in SVG. In this case the compiler does not have enough context to know that the element is supposed to be an SVG element, so it will end up with the wrong namespace (HTML).

As a workaround you could add a dummy group:

<g>{@html html}</g>
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda