lustre-labs / lustre

A Gleam web framework for building HTML templates, single page applications, and real-time server components.
https://hexdocs.pm/lustre
MIT License
1.21k stars 78 forks source link

Some properties cannot be applied to svg element #202

Closed patwid closed 1 day ago

patwid commented 1 month ago

The example below, results in a runtime error:

Uncaught TypeError: Cannot set property width of #<SVGSVGElement> which has only a getter
    at createElementNode (foo.mjs:1459:18)
    at morph (foo.mjs:1410:23)
    at #tick (foo.mjs:1798:5)
    at foo.mjs:1715:23
import gleam/io
import lustre
import lustre/attribute
import lustre/element
import lustre/element/svg

pub fn main() {
  let app = lustre.element(svg.svg([attribute.width(42), attribute.height(42)], []))
  let assert Ok(_) = lustre.start(app, "#app", Nil)

  Nil
}

As a workaround, specifying the width and height as attributes (rather than properties) seems to work as expected:

import gleam/io
import lustre
import lustre/attribute
import lustre/element
import lustre/element/svg

pub fn main() {
  let app = lustre.element(svg.svg([attribute.attribute("width", "42"), attribute.attribute("height" "42")], []))
  let assert Ok(_) = lustre.start(app, "#app", Nil)

  Nil
}

This may actually be a duplicate of #197 . Feel free to close this issue, if that is the case.

hayleigh-dot-dev commented 4 weeks ago

I think the fix is a documentation one that mentions that width and height set the property and not the attribute, and for use with svg users should manually create the attributes they need.