Skip to content

Use root class prefixes instead of @scope - #3941

Closed
SimonHeybrock wants to merge 1 commit into
mainfrom
flat-css-selectors
Closed

SimonHeybrock wants to merge 1 commit into
mainfrom
flat-css-selectors

Conversation

@SimonHeybrock

Copy link
Copy Markdown
Member

Alternative to #3939, which replaces @scope with CSS nesting. Same goal, one fewer dependency on a recent CSS feature.

The repr stylesheets are embedded in pages we do not control, so they have to parse in whatever browser and HTML post-processor the host site uses. Support floors for the three ways of expressing containment:

Chrome Firefox Safari
@scope 118 128 17.4
nesting (relaxed syntax) 120 117 17.2
selector prefix all all all

Nesting needs the relaxed syntax because many selectors start with a type (ul.sc-sections, pre.sc-var-data, input.dg-header-in, dl.sc-attrs). Where that is unsupported, those rules are dropped while the class-only ones survive, leaving a partially styled repr, which is the failure mode the stylesheet exists to prevent. Firefox ESR 115, still common on institutional Linux, supports neither feature.

The containment mechanism does no cascade work here. mkdocs Material's competing rules carry no !important (.md-typeset ul:not([hidden]){display:flow-root}; there are six !important declarations in the whole Material stylesheet, none of which match a scipp element), so what fixes #3921 is our !important declarations. A selector prefix yields the same specificity @scope and nesting do, so all three behave identically where they parse.

Declarations are byte-identical to main; only selectors change.

Test plan

  • Declaration sets diffed against main: identical for both files.
  • DataArray, Dataset, DataGroup and show() output regenerated and inspected; minifier in resources.py produces balanced, comment-free CSS.
  • Built an mkdocs Material 9.7.7 site with a DataGroup repr embedded; the inline <style> survives the build verbatim.
  • Visual check of the rendered docs.

The repr stylesheets are embedded in pages we do not control, so they must
parse in whatever browser the host site is viewed with. @scope requires
Firefox 128+ and Safari 17.4+; below that the entire block is dropped and the
repr renders unstyled.

Prefixing every selector with .sc-root / .dg-root gives identical specificity
and cascade behavior without depending on a recent CSS feature. Declarations
are unchanged: the !important declarations, not the containment mechanism, are
what keeps host themes from overriding the layout.
@SimonHeybrock

Copy link
Copy Markdown
Member Author

Closed after f2f discussion: #3939 was already manually verified and 2023 browser features are probably fine to use.

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.

Scipp html repr breaks when surrounding page has CSS rules that interfere (mkdocs).

1 participant