Skip to content
Bug reportDec 6, 2026· 0:26· 8 views

Lit styleMap: custom property with $ in name is dropped on initial render, set on update

0:26 total

Comments · 0

Be the first to comment.

Bug reportby SceneRecap AI

mediumlit-html styleMap directive: initial render serialization of custom property names into the style attribute (no CSS escaping, e.g. CSS.escape) compared with the update path using style.setProperty.
os: macOSdpr: 1issue: github.com/lit/lit/issues/5446locale: en-USbrowser: Chromium 151.0.7922.34library: lit@3 (lit-html 3.3.3)viewport: 1280x720

Repro steps

  1. 1.Render an element with styleMap({ '--$bar-fill-ratio': '0.5' }) next to a control using styleMap({ '--bar-fill-ratio': '0.5' }).
  2. 2.Read getPropertyValue('--$bar-fill-ratio') on the bug element after the initial render.
  3. 3.Click 'Re-render with value 0.8 (triggers styleMap update path)'.
  4. 4.Read getPropertyValue('--$bar-fill-ratio') again after the update.

Expected

styleMap sets '--$bar-fill-ratio' on the initial render, so getPropertyValue returns "0.5" and the bar fills to 0.5. This matches the control '--bar-fill-ratio'. Initial render and update target the same custom property.

Actual

On initial render getPropertyValue('--$bar-fill-ratio') returns "" and the bug bar shows '0 / 1'. The declaration '--$bar-fill-ratio: 0.5;' is written unescaped to the style attribute and the CSS parser drops it. After the re-render, the update path calls style.setProperty('--$bar-fill-ratio', '0.8'). That call is accepted, and the value reads "0.8".

Evidence

visualBug panel shows '0 / 1' and getPropertyValue('--$bar-fill-ratio') returns "". The note says it was dropped by the CSS parser on initial render and should be "0.5".
visualControl panel ('--bar-fill-ratio') works: the bar shows 0.5 and getPropertyValue returns "0.5", parsed correctly.
visualThe explanation box says styleMap writes '--$bar-fill-ratio: 0.5;' to the style attribute and that '$' is not a valid CSS ident character.
visualThe bug panel stays empty through the initial render state.
visualThe re-render button appears highlighted, which suggests it was pressed.
visualAfter the update, the bug panel shows 0.8 and getPropertyValue('--$bar-fill-ratio') returns "0.8". The note says the setProperty path works (permissive CSSOM) and the initial render was broken.
visualControl panel works after the update: it shows 0.8 and is noted as correct on both initial render and update.
visualThe explanation says the update path calls style.setProperty('--$bar-fill-ratio', '0.8'), and that the first render and later updates do not target the same custom property.
Issue markdown (copy-paste ready)
## Summary
styleMap does not escape custom CSS property names on initial render. A name like `--$bar-fill-ratio` is written raw into the `style` attribute and dropped by the CSS parser. Later updates use `style.setProperty`, which accepts the name. Initial render and updates therefore behave differently.

## Environment
- lit@3 (lit-html 3.3.3)
- Chromium 151.0.7922.34, macOS, 1280x720
- Related: github.com/lit/lit/issues/5446

## Steps to reproduce
1. Render `styleMap({ '--$bar-fill-ratio': '0.5' })` next to a control `styleMap({ '--bar-fill-ratio': '0.5' })` (1.0s).
2. Read `getPropertyValue('--$bar-fill-ratio')` (1.0s).
3. Click **Re-render with value 0.8 (triggers styleMap update path)** (10.8s).
4. Read the value again (13.0s).

## Expected
The initial render sets `--$bar-fill-ratio` to `0.5`, the same as the control. Initial render and update target the same property.

## Actual
- At 1.0s the bug panel reads `""` and the bar shows `0 / 1`. The declaration `--$bar-fill-ratio: 0.5;` is dropped because `$` is not a valid CSS ident character.
- At 13.0s, after the update, the value reads `"0.8"` because `style.setProperty('--$bar-fill-ratio', '0.8')` is accepted by the CSSOM.

## Control
The `--bar-fill-ratio` control works on both paths: it reads `"0.5"` at 1.0s and `"0.8"` at 13.0s.

## Suggested area
The styleMap initial render path that serializes property names into the style attribute. Consider escaping custom property names, for example with `CSS.escape`, or using `setProperty` on first render so both paths agree.

*Recorded with SceneRecap.*

This report was written by SceneRecap from a screen recording. Try SceneRecap free

Turn a screen recording into a bug report like this one.

Repro steps, expected vs actual and the console and network evidence, each with a timestamp. On every plan, Free included.

Try SceneRecap free →
Lit styleMap: custom property with $ in name is dropped on initial render, set on update · SceneRecap