styleMap has a different behavior on the update
Author: Lookwe69Created Mar 4, 2025Updated Jun 30, 2026
Which package(s) are affected?
Lit Core (lit / lit-html / lit-element / reactive-element)
Description
The second render is not the same even if style key doesn't change.
html`<p style=${styleMap({[`--cell-color-id-${CSS.escape('my id')}`]: 'red'})}>
This example will render style="--cell-color-id-my\ id: red;" on first render, and style="--cell-color-id-my\\\ id: red;" on second.
I think the problem is that the first render set the variable without escaping. The second render escape the variable resulting in a duplication
Reproduction
Workaround
Instead of use CSS.escape, we can't replace unsupported char with another such as '_'. Problem, i must think of every single char that must be replaced and It can causes issue with uniq => 'my id' and 'my_id' are equals.
Is this a regression?
No or unsure. This never worked, or I haven't tried before.
Affected versions
3.2.1
Browser/OS/Node environment
Browser : Chrome 132.0.6834.83
Source: lit/lit