Skip to content

3.1: a dark StyleScope with a seeded scheme inside a light wrapper on a dark page gets light text tokens #558

Open

Description

@lorant-one

Found while moving Tavilio to 3.0. Tavilio works around it in Tavilio#266.

Setup: html[data-theme="dark"] > a wrapper with data-theme="light" > a StyleScope with theme="dark" and an accentSeed. That gives one element with both data-theme="dark" and data-accent="custom".

Result: that element gets the light theme's text tokens.

Cause: the light block in tokens.css includes :is(dark) :is(light) :is([data-brand],[data-accent],[data-neutral]).

  • The scope matches it through its ancestors.
  • It has the same specificity (0,3,0) as the dark block's :is(light) :is(dark):is([data-…]).
  • It comes later in the sheet, so it wins.

Who hits it: any StyleScope that pins a theme and seeds a scheme inside a light-on-dark page. One example is a product site with its own light wrapper, viewed on a device in dark mode.

Fix direction: a nested-theme scope should resolve to its nearest data-theme. The theme-invert script (scripts/theme-invert.cjs) and themeSelector() should emit selectors where the closer theme wins. Two ways to get there:

  • make the self-match (:is(dark):is([data-…])) more specific than the ancestor match, or
  • order the generated blocks so the self-match comes last.

Add a theme-contrast test for this case.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions