Skip to content

Conversation

@omnibs
Copy link

@omnibs omnibs commented Nov 10, 2025

Intro

This is a companion PR to elm/virtual-dom#187 and elm/html#259 from Simon Lydell's lydell/elm-safe-virtual-dom.

🎗️ This PR should be merged if and only if elm/html#259 is merged. Meaning this should not be merged before that PR is merged, but it needs to be merged when that PR is merged.

Changes here mirror changes made by Simon Lydell to elm/html in elm/html#259:

  • Removes the stringProperty helper function
  • Uses attributes for the functions that relied on it, except for value
  • Retains boolProperty and documents its behavior under the new Virtual DOM

elm-css already mirrored elm/html, and this keeps that aspect of it tidy =]

Impact of not merging

If Simon's PRs are merged, avh4/elm-program-test tests will fail unless we also merge this PR.

An example failure can be seen in this gist, where we fail to find a select option based on the for attribute of the select's label.

The cause is elm-program-test builds its selectors directly with elm/html's Html.Attributes.

In the example above,elm-css will build an htmlFor property for our view, and elm/html under elm-safe-virtual-dom will build a for attribute for elm-program-test's selector.

Details

Quoting Simon:

Most functions in Html.Attributes that take a String used this helper function:

stringProperty : String -> String -> Attribute msg
stringProperty key string =
  Elm.Kernel.VirtualDom.property key (Json.string string)

For example, href:

href : String -> Attribute msg
href url =
  stringProperty "href" (Elm.Kernel.VirtualDom.noJavaScriptUri url)

In other words, lots of the Html.Attributes functions were implemented by setting properties.

This PR removes stringProperty, and instead prefers attributes over properties. Here’s href in this PR:

href : String -> Attribute msg
href url =
  Elm.Kernel.VirtualDom.attribute "href" (Elm.Kernel.VirtualDom.noJavaScriptUri url)

In short, attributes are preferred because:

  1. Attributes can be removed, while properties often cannot. Closes elm/html#228, closes elm/html#148, closes elm/virtual-dom#122, closes elm/virtual-dom#169
  2. Virtualization is way easier when most Html.Attributes functions are attributes. Closes elm/virtual-dom#144
  3. Some properties are read-only and therefore throw errors if you try to set them.
  4. Attributes are easier to diff.

I explain those points more in the properties-vs-attributes.md file (which I updated in this PR).

@omnibs omnibs changed the title Use attributes instead of properties Use attributes instead of properties (compatibility with elm-safe-virtual-dom) Nov 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant