Skip to content

css: inline a theme token already declared at root scope#149

Open
samoht wants to merge 1 commit into
mainfrom
resolve-theme-inline-declared-token
Open

css: inline a theme token already declared at root scope#149
samoht wants to merge 1 commit into
mainfrom
resolve-theme-inline-declared-token

Conversation

@samoht

@samoht samoht commented Jun 26, 2026

Copy link
Copy Markdown
Owner

This PR makes resolve_theme inline a theme token whose definition is already present in the input.

When a stylesheet already carries a token's own root-scope definition (:root,:host{--blur-xl:24px}, which is exactly what Tailwind's codegen emits for theme tokens), resolve_theme used to keep the token live and inject a second :root binding, leaving var(--blur-xl) unresolved beside two definitions. It now inlines the reference from the existing declaration and drops it, injecting a :root binding only for tokens that have no declaration of their own; the in-stylesheet value wins over the theme_defaults default, matching the cascade.

Two supporting changes make that work: the inline engine now recognises a :root,:host list (or any list with a :root branch), not just a bare :root, as a whole-tree value source, so the declared value actually reaches the references; and the theme-resolution layer is unified on bare custom-property names so the keep/declared/resolved sets compare directly instead of mixing ---prefixed and bare spellings.

Follow-up to #148.

resolve_theme kept a theme token live when the input already carried its own
root-scope definition (`:root,:host{--blur-xl:24px}`, exactly what Tailwind
emits): it added the token to the keep-set and injected a second `:root`
binding, so `var(--blur-xl)` survived unresolved beside two definitions. It now
inlines from the existing declaration and drops it, injecting a binding only for
tokens with no declaration of their own.

Two supporting changes: the inline engine recognises a `:root,:host` list (any
list with a `:root` branch), not just a bare `:root`, as a whole-tree value
source; and the theme layer is unified on bare custom-property names so the
keep/declared/resolved sets compare without mixing `--`-prefixed spellings.
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.

1 participant