Skip to content

feat(css): make theme tokens + dark variant Shadow-DOM friendly#506

Open
0-don wants to merge 1 commit into
outerbase:developfrom
0-don:feat/shadow-dom-friendly-css
Open

feat(css): make theme tokens + dark variant Shadow-DOM friendly#506
0-don wants to merge 1 commit into
outerbase:developfrom
0-don:feat/shadow-dom-friendly-css

Conversation

@0-don
Copy link
Copy Markdown

@0-don 0-don commented May 17, 2026

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.

- @custom-variant dark (&:is(.dark *));
+ @custom-variant dark (&:where(.dark *, :host(.dark) *));

- :root { ... }
+ :root, :host { ... }

- .dark { ... }
+ .dark, :host(.dark) { ... }

Applied to globals.css, prompt-plugin.css, and styles.module.css (:global(.dark) -> dual).

Purely additive. :host(...) is inert in normal DOM, so non-shadow consumers are unaffected.

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).
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.

feat: ship an embeddable Studio React component (shadow-DOM friendly)

1 participant