Skip to content

Use nesting instead of scoped css - #3939

Merged
jokasimr merged 2 commits into
mainfrom
fix-scope-css
Aug 5, 2026
Merged

jokasimr merged 2 commits into
mainfrom
fix-scope-css

Conversation

@jokasimr

@jokasimr jokasimr commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Fixes the browser incompatibility issue that Celine discovered today.

@jokasimr

jokasimr commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor Author

I've checked and it looks good now in both the old and the new version of firefox.

This still makes the html representations render correctly in MKDocs, which was the original issue that triggered the changes to the stylesheets.

@SimonHeybrock SimonHeybrock left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the desugaring and it's equivalent: inside @scope the implied :scope counts as a pseudo-class (0,1,0), so specificity is unchanged, :scope.sc-wrap → &.sc-wrap is the right translation, and hoisting the .dg-root declarations out of :scope {} is correct. The regex minifier in resources.py is selector-agnostic, so nothing breaks there. No objection to merging.

But: why any 2023-era feature at all? The wrapper does no cascade work here -- the !important declarations do. Written flat, .sc-root .foo { ... } is exactly equivalent and parses in every browser ever shipped. The floors we're choosing between:

Chrome Firefox Safari
@scope 118 128 17.4
nesting, relaxed syntax 120 117 17.2
flat descendant selectors all all all

Relaxed syntax is required because many nested selectors start with a type (ul.sc-sections, pre.sc-var-data, input.dg-header-in, dl.sc-attrs). In Chrome 112-119 and Safari 16.5-17.1 those rules are dropped while the class-only ones survive -- partially styled, which is the exact broken-layout mode this stylesheet exists to prevent. Firefox ESR 115, still common on institutional Linux, supports neither feature.

So this trades one narrow broken window for another. Flat selectors close the category for good, at the cost of repeating an 8-character prefix in a file we touch twice a year. Since the whole motivation is "someone's browser is too old", I'd take that trade.

If you'd rather keep the nesting, two small asks:

  • A comment in both files noting the prefix-by-nesting is deliberate and why @scope is unusable, otherwise this gets modernized back in a year.
  • The tested Firefox version in the PR description -- "old and new version of firefox" doesn't pin down what's actually covered.

@SimonHeybrock

Copy link
Copy Markdown
Member

Opened #3941 with the prefix-selector variant so it can be compared side by side -- whichever you prefer, the other should be closed.

@jokasimr

jokasimr commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

I don't think it is necessary to go through another round of changes and testing to make sure we support browsers from before 2023. That just does not seem meaningful.

If you prefer that version feel free to implement it and merge what you prefer.

@jokasimr

jokasimr commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor Author

I changed my opinion. The change is simple and the peace of mind knowing the docs are not broken anywhere is worth it 👍

@jokasimr
jokasimr merged commit e29f10f into main Aug 5, 2026
4 checks passed
@jokasimr
jokasimr deleted the fix-scope-css branch August 5, 2026 08:26
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