Skip to content

Empty CSS custom property values are silently dropped #351

@quantizor

Description

@quantizor

Description

Stylis silently drops CSS declarations where a custom property has an empty value (--prop: ;). Per the CSS spec, --custom-property: ; is valid — it sets the property to the guaranteed-invalid value. This pattern is used in scroll-driven animations and other modern CSS techniques.

Reproduction

import { compile, serialize, stringify } from 'stylis';

// Empty value — dropped entirely
console.log(serialize(compile('.foo { --x: ; }'), stringify));
// Output: "" (empty string)

// In keyframes — entire frame dropped
console.log(serialize(compile('@keyframes foo { from { --x: red; } to { --x: ; } }'), stringify));
// Output: "@keyframes foo{from{--x:red;}}" (the `to` frame is missing)

// Non-empty value — works fine
console.log(serialize(compile('.foo { --x: initial; }'), stringify));
// Output: ".foo{--x:initial;}"

Expected

.foo{--x: ;}
@keyframes foo{from{--x:red;}to{--x: ;}}

Actual

(empty)
@keyframes foo{from{--x:red;}}

Environment

stylis 4.3.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions