Skip to content

bug(docs): fix theme aliases that reference descendant-scoped palette tokens #25

Description

@Hebilicious

Problem

In the Colors example at 94bf4d8, palette.another is emitted under .Another, while the dark-theme aliases are emitted on :root:

:root {
  @media (prefers-color-scheme: dark) {
    --primary: var(--palette-another-yellow);
    --secondary: var(--palette-another-cyan);
  }
}

.Another {
  --palette-another-yellow: oklch(96.798% 0.21101 109.76924);
  --palette-another-cyan: oklch(90.54% 0.15455 194.76896);
}

This requires .Another to match the root element, or the source properties to be independently available there. It does not work merely by placing .Another on a descendant.

Custom-property references are substituted when the alias is computed, before inheritance. Defining the source on a descendant cannot repair an invalid alias inherited from the root. See the CSS Custom Properties specification.

Minimal browser regression fixture

The following removes the media-query condition to isolate the scoping problem:

<style>
  :root { --primary: var(--palette-another-yellow); }
  .Another { --palette-another-yellow: yellow; }
  .probe { color: var(--primary, red); }
</style>
<div class="Another probe">Expected palette color only after fixing the scopes</div>

The descendant receives the fallback red, not yellow. Applying .Another to <html> instead makes the source available where the alias is computed. Add browser assertions for both placements; this report is based on source/specification analysis, not a completed browser test run.

Proposed correction

Choose and document a coherent example:

  • Define palette tokens globally, then override semantic aliases by theme; or
  • Emit both source tokens and aliases in the same selector context; or
  • Explicitly require a root theme class and illustrate :root.Another with matching HTML.

Acceptance criteria

  • Correct the canonical README example and regenerate the package README, docs, and agent-facing outputs through the existing pipeline.
  • Explain where theme classes must be placed and how alias inheritance works.
  • Add browser-level getComputedStyle() tests for root and descendant theme classes, including an active dark-mode condition.
  • Keep palette scoping as a supported feature; do not globally prohibit references that are valid in an explicitly documented DOM arrangement.

A conservative scope-diagnostic feature is separate follow-up work; this issue fixes the concrete documentation example.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions