Skip to content

feat: support scoping the dark: variant to a root selector in tailwindCompiler - #1608

Merged
chrisschnaars merged 1 commit into
nextfrom
chrisschnaars/tailwind-dark-mode-root-selector
Sep 3, 2026
Merged

chrisschnaars merged 1 commit into
nextfrom
chrisschnaars/tailwind-dark-mode-root-selector

Conversation

@chrisschnaars

Copy link
Copy Markdown
Contributor

Summary

  • tailwindCompiler/TailwindStyle accept a new darkModeRootSelector option. When supplied, the generated dark: custom-variant is scoped to that root's own [darkModeDataAttribute], self or descendant, instead of matching the attribute on any ancestor.
  • Omitted (the default), behavior is byte-for-byte unchanged from today.
  • Mirrors when-color-mode-dark($root) (styles/mixins/when-color-mode-dark.scss, added in feat: update dark mode mixinΒ #1596) β€” same rationale: a page can have two independent data-color-mode scopes (e.g. readme's SuperHub admin shell vs. the hub content it's previewing), and the current ancestor-matching selector can't tell them apart. No default root selector is provided, for the same reason when-color-mode-dark doesn't have one β€” see that mixin's doc comment, and the new doc comment on tailwindCompiler's darkModeRootSelector param, for the full reasoning.

Test plan

  • __tests__/utils/tailwind-compiler.test.ts (new) β€” unit-tests the generated @custom-variant dark (...) string directly (spies on tailwindcss.compile since the real compile pipeline needs this package's production string-import loaders, which aren't wired into vitest β€” same reason the existing TailwindStyle.test.tsx mocks tailwindCompiler rather than exercising real output)
  • __tests__/components/TailwindStyle.test.tsx β€” new case confirming darkModeRootSelector threads through to tailwindCompiler
  • npx vitest run on both files β€” 9/9 passing
  • npx eslint β€” clean
  • npx tsc --noEmit β€” no new errors

πŸ€– Generated with Claude Code

…dCompiler

Mirrors when-color-mode-dark($root) (added in #1596) for Tailwind-styled
MDX content: the dark: custom-variant currently matches
[darkModeDataAttribute=dark] on any ancestor, which bleeds when a page has
two independent data-color-mode scopes (e.g. readme's SuperHub admin shell
vs. the hub content it's previewing). darkModeRootSelector, when supplied,
scopes dark: to that root's own attribute instead. Omitted, behavior is
unchanged.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge, with no concrete changed-code-triggered failures identified.

The documented single-root selector is propagated consistently, its generated CSS preserves the prior default behavior, and the new behavior is covered at both the compiler and component boundaries.

Important Files Changed

Filename Overview
utils/tailwind-compiler.ts Adds the optional root selector to dark-variant generation while retaining the previous unscoped selector when omitted.
components/TailwindStyle/index.tsx Exposes and forwards the new selector option and recompiles when it changes.
tests/utils/tailwind-compiler.test.ts Verifies scoped, fallback, and disabled custom-variant strings.
tests/components/TailwindStyle.test.tsx Verifies that TailwindStyle forwards both dark-mode options to the compiler.

Reviews (1): Last reviewed commit: "feat: support scoping the dark: variant ..." | Re-trigger Greptile

@chrisschnaars
chrisschnaars merged commit df0f409 into next Sep 3, 2026
9 checks passed
@chrisschnaars
chrisschnaars deleted the chrisschnaars/tailwind-dark-mode-root-selector branch September 3, 2026 15:22
rafegoldberg pushed a commit that referenced this pull request Sep 3, 2026
## Version 15.4.0
### ✨ New & Improved

* support scoping the dark: variant to a root selector in tailwindCompiler ([#1608](#1608)) ([df0f409](df0f409)), closes [#1596](#1596)

<!--SKIP CI-->
@rafegoldberg

Copy link
Copy Markdown
Collaborator

This PR was released!

πŸš€ Changes included in v15.4.0

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants