Skip to content

Fix Stylo preference initialization before UA stylesheet parsing - #1310

Open
g1BSsQ wants to merge 2 commits into
DioxusLabs:mainfrom
g1BSsQ:ua-sheet-prefs
Open

g1BSsQ wants to merge 2 commits into
DioxusLabs:mainfrom
g1BSsQ:ua-sheet-prefs

Conversation

@g1BSsQ

@g1BSsQ g1BSsQ commented Oct 27, 2026 •

Copy link
Copy Markdown

Summary

BaseDocument::new enables Stylo prefs with style_config::set_pref! "before creating the Stylist", but the default user-agent stylesheet is parsed before that point and only once:

  • UserAgentStylesheet::default_sheet() is a LazyLock around UserAgentStylesheet::parse(DEFAULT_CSS).
  • DocumentConfig::default() calls default_sheet(), so the UA sheet is parsed before BaseDocument::new sets any pref.

As a result, every pref-gated declaration in assets/default.css is dropped at parse time, and it stays dropped for the life of the process. For example, ul, ol, menu { counter-reset: list-item; } is lost, because counter-reset/counter-increment are gated by layout.css.counters.enabled in the pinned Stylo. Author stylesheets are parsed later and are not affected, so the problem only shows up for UA rules.

Observed: the computed counter-reset of an <ol> was empty. When the prefs are set before the UA parse, it is list-item 0.

Fix

  • Move the set_pref! block out of BaseDocument::new into init_stylo_prefs(), guarded by std::sync::Once. The prefs and values are unchanged, including the writing-mode feature-gated ones.
  • Call it at the start of UserAgentStylesheet::parse, so the default sheet and any custom UA sheet are parsed with the prefs on.
  • Also call it at the start of BaseDocument::new, so documents built without a UA sheet still get the prefs.

No behaviour change for author styles. No new dependencies.

Measured impact

WPT run (cargo run -rp wpt) on a fork CI, comparing this branch against main at fe33b77 on the same runner:

  • Suites: css/css-lists, css/css-contain, css/css-writing-modes and html/rendering (2,690 tests).
  • Result: 0 newly passing, 0 newly failing.
  • The run was at 7caba8a. The later commit only removes a blank line for rustfmt.

That is expected: list markers do not read the list-item counter today, so the UA counter rules are now present but not yet consumed. This change is a prerequisite for CSS-counter-based list numbering, such as ol[reversed], <li value> and author counter-reset/counter-increment on list-item. Without it, that work would see the UA defaults missing.

WPT results

No changes in test results compared to main.

Generated by the WPT workflow.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants