BigPizzaV3/CodexPlusPlus · error

theme.css 声明数量超过限制

Error message

theme.css 声明数量超过限制

What it means

parse_safe_css enforces a global budget of 512 declarations across the whole stylesheet: after each accepted declaration it increments the counter and bails with 'theme.css 声明数量超过限制' once the count exceeds 512. This bounds the compiled @layer dreamskin-community output and prevents resource exhaustion from huge packages.

Solutions

  1. Count declarations (`grep -c ';' theme.css`-ish) and prune to ≤ 512 by deleting rules for less-important parts
  2. Merge duplicate rules and drop redundant declarations (e.g. per-side border-color where border-color suffices)
  3. Split styling across multiple theme packages if more coverage is genuinely needed

Example fix

// before: 128 rules × 8 declarations = 1024 declarations
// after: keep the 60 highest-impact rules → ~480 declarations
Defensive patterns

Strategy: validation

Validate before calling

fn declaration_count(css: &str) -> usize {
    css.split(['{', '}']).skip(1).step_by(2).map(|body| body.split(';').filter(|d| !d.trim().is_empty()).count()).sum()
}
assert!(declaration_count(&css) <= 512, "too many declarations");

Try / catch

if declaration_count(&css) > 512 {
    return Err("reduce theme.css to at most 512 declarations".into());
}
let _ = validate_safe_css(&css)?;

Prevention

When it happens

Trigger: validate_safe_css/compile_safe_css on a theme.css containing more than 512 `prop: value;` declarations in total (across all rules and pseudo-state variants).

Common situations: Generated themes enumerating every part × state × property combination; machine-generated CSS from design tools with exhaustive variable expansions; concatenated multi-theme stylesheets.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/7317c6b0197534b2. Report an issue: GitHub.

Appendix: source

Thrown at crates/codex-plus-core/src/dream_skin_package.rs:369

            let value = value.trim();
            if !property
                .bytes()
                .enumerate()
                .all(|(index, byte)| byte.is_ascii_lowercase() || (index > 0 && byte == b'-'))
                || !seen.insert(property)
            {
                bail!("theme.css CSS 属性无效或重复:{property}");
            }
            if value.is_empty()
                || value.chars().count() > 512
                || value.contains(['{', '}', '<', '>', '!', ';'])
                || !validate_property_value(property, value)
            {
                bail!("theme.css 属性值不受 Safe CSS 支持:{property}");
            }
            declarations += 1;
            if declarations > 512 {
                bail!("theme.css 声明数量超过限制");
            }
            rule_declarations.push((property, value));
        }
        if rule_declarations.is_empty() {
            bail!("theme.css 每条规则必须至少包含一个声明");
        }
        parsed.push(SafeCssRule {
            selector,
            part,
            declarations: rule_declarations,
        });
        if parsed.len() > 128 {
            bail!("theme.css 规则数量超过限制");
        }
        rest = &rest[close + 1..];
    }
    if parsed.is_empty() {
        bail!("theme.css 必须至少包含一条规则");

View on GitHub (pinned to b1ed92e5e4)