feat(css): make theme tokens + dark variant Shadow-DOM friendly#506
Open
0-don wants to merge 1 commit into
Open
feat(css): make theme tokens + dark variant Shadow-DOM friendly#5060-don wants to merge 1 commit into
0-don wants to merge 1 commit into
Conversation
Consumers that embed Studio inside an open Shadow Root - e.g. as a
local-DB inspector in a host app where Tailwind's preflight would
otherwise leak globally - currently lose theme tokens and dark-mode
styling.
The root cause is that none of these selectors cross the shadow
boundary:
- `:root { ... }` matches Document.documentElement only.
- `.dark <descendant>` (legacy class) requires `.dark` on an ancestor
in the same tree; the shadow host is outside the shadow tree.
- Tailwind v4 `@custom-variant dark (&:is(.dark *))` compiles every
`dark:` utility into `.dark\:foo:is(.dark *)`, same problem.
This adds `:host` / `:host(.dark)` alongside the existing selectors:
- `:root, :host { ... }` for theme-token blocks
- `.dark, :host(.dark) { ... }` for the dark-mode block + descendant
rules (`globals.css`, `prompt-plugin.css`, and the table-cell CSS
module via `:global(:host(.dark))`).
- `@custom-variant dark (&:where(.dark *, :host(.dark) *))` so every
Tailwind `dark:` utility activates in either DOM topology.
All changes are purely additive: `:host(...)` selectors don't match
anything inside a normal Document, so non-shadow consumers are
unaffected. Shadow-DOM consumers can now drop the runtime stylesheet
rewrites that some downstream apps are currently doing to work around
this (e.g. outerbase#505).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #505.
Embedding Studio inside a Shadow Root loses theme tokens + dark mode because
:root,.dark <descendant>, and&:is(.dark *)all rely on selectors that can't cross the shadow boundary.Fix: add
:host/:host(.dark)alongside the existing selectors.Applied to
globals.css,prompt-plugin.css, andstyles.module.css(:global(.dark)-> dual).Purely additive.
:host(...)is inert in normal DOM, so non-shadow consumers are unaffected.