Skip to content

fix(theme): nearest theme wins for a seeded StyleScope three levels deep (3.1) - #589

Merged
lorant-one merged 2 commits into
previewfrom
fix/nested-theme-scope-tokens
Nov 23, 2026
Merged

lorant-one merged 2 commits into
previewfrom
fix/nested-theme-scope-tokens

Conversation

@lorant-one

Copy link
Copy Markdown
Member

Requested by Lorant · project thread

Fixes #558.

The bug. html[data-theme="dark"] › a data-theme="light" wrapper › a StyleScope with theme="dark" and a seed gives one element with data-theme="dark" and data-accent="custom". That element matched the light scheme block ([dark] [light] :is([data-brand],[data-accent],[data-neutral])) through its ancestors, at the same specificity as the dark block's self-match, and the light block comes later, so it read light text tokens on a dark surface.

The fix. foundations/scss/tokens/theme.scss: each scheme block gets the three-level selectors ([light] [dark] [light]… for light, [dark] [light] [dark]… for dark), on the element itself and on a scheme element inside it. That is the pattern showIn already uses, so the nearest theme wins one level deeper. Two-level cases weigh the same as before.

Test. foundations/test/nested-theme-scope.test.ts compiles the tokens and picks the winning --neutral-on-background-strong the way the cascade does (specificity, then order) for both three-level setups and the two-level ones. It fails on preview without the change and passes with it.

Checks: foundations 72/72, core build and suite pass locally except the catalog-size cap, which #587 moves.

Tavilio works around this in Tavilio#266; that workaround can go once 3.1 is out.


Generated by Claude Code

…ls deep (#558)

A StyleScope with theme="dark" and a seed inside a light section of a dark
page matched the light scheme block through its ancestors at the same
specificity, and the light block comes later. Three-level selectors, as
showIn already has, let the nearest theme win.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016gNJtx8NozwfTMFAJUwVuh
@lorant-one lorant-one self-assigned this Nov 23, 2026
@lorant-one
lorant-one merged commit 59bbb11 into preview Nov 23, 2026
9 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 24, 2026
27 tasks done
@lorant-one lorant-one added the approved label Nov 24, 2026 — with Claude
@lorant-one
lorant-one deleted the fix/nested-theme-scope-tokens branch November 29, 2026 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants