Instatic icon indicating copy to clipboard operation
Instatic copied to clipboard

Site Import (convert mode): nested CSS rules are silently dropped

Open Amay66 opened this issue 1 month ago • 0 comments

Version: 0.0.21 (Docker image ghcr.io/corebunch/instatic)

What happens

Importing a stylesheet in the default "convert to editable style rules" mode ignores every rule that is nested inside another rule (native CSS nesting). The top-level rule is created with only its own declarations, the nested children vanish, and no warning is reported. Output of Etch / Automatic.css uses nesting heavily (&:hover, &[data-x], nested .child, nested @media), so a converted import ends up with empty or incomplete rules.

Reproduction

cssToStyleRules() from src/core/siteImport/cssToStyleRules.ts, bundled and run in Chromium 155 (the function relies on the engine's CSSStyleSheet):

.btn-header__media { &[data-icon-size='s'] { width: 1rem; } &[data-icon-size='m'] { width: 2rem; } }
.card { color: red; &:hover { color: blue; } .title { margin: 0; } @media (min-width: 40rem) { padding: 1px; } }
.plain { color: green; }
.plain:hover { color: lime; }

Result (rules, warnings):

.btn-header__media   styles = {}
.card                styles = {"color":"red"}      contexts = []
.plain               styles = {"color":"green"}
.plain:hover         styles = {"color":"lime"}
warnings: none

Flat rules are fine. In the nested input, .btn-header__media ends up empty and .card:hover, .card .title and the nested @media are missing, with nothing in warnings.

Where

cssRules is only walked for the sheet itself (cssToStyleRules, top-level loop) and inside @media / @container / @supports blocks (processConditionInner). A plain CSSStyleRule is processed through its own .style; I found no place that visits its nested cssRules.

Expected

Either of:

  1. flatten nested rules into the registry while converting (&:hover becomes .card:hover, .title becomes .card .title, nested conditions keep their context), or
  2. emit a warning per dropped nested rule and surface it in the wizard, recommending "Keep as stylesheet".

The docs list what cannot be modeled (@layer, conditional local @import, arbitrary external @import); nesting is not on that list.

Workaround

"Keep as stylesheet" imports the file verbatim as a site file and nested CSS works there (the published userStyles bundle is served untouched and parsed by the browser).

Amay66 avatar Oct 16 '26 08:10 Amay66