Skip to content

v6: Mirror the active theme to data-theme on <html>#4293

Merged
trevor-scheer merged 1 commit into
graphiql-6from
trevor/theme-data-attr
May 17, 2026
Merged

v6: Mirror the active theme to data-theme on <html>#4293
trevor-scheer merged 1 commit into
graphiql-6from
trevor/theme-data-attr

Conversation

@trevor-scheer
Copy link
Copy Markdown
Contributor

@trevor-scheer trevor-scheer commented May 17, 2026

Summary

tokens.css scopes the v6 OKLCH cascade to [data-theme='light'] / [data-theme='dark'] selectors, but setTheme was only writing graphiql-light / graphiql-dark classes onto <body>. With no data-theme attribute set, v6 components fell through to the OS prefers-color-scheme media-query fallback regardless of the in-app toggle. This PR mirrors the active theme onto document.documentElement as data-theme so the selectors actually match; the existing body classes are preserved for any consumer CSS that depends on them.

Test plan

  • Open the deploy preview. With the GraphiQL theme dropdown set to System, confirm <html> has no data-theme attribute and v6 chrome follows your OS preference.
  • Toggle the theme to Light; confirm <html> gains data-theme="light" and v6 components (TopBar, StatusBar, ActivityRail, etc., once those PRs land) all switch to light tokens.
  • Toggle the theme to Dark; confirm <html> gains data-theme="dark" and v6 components switch to dark tokens.
  • Toggle back to System; confirm data-theme is removed and the v6 components revert to following the OS preference.

Refs: #4219

`tokens.css` gates its v6 OKLCH cascade on `[data-theme='light']` /
`[data-theme='dark']` selectors, but the only place theme state was
applied was a `graphiql-light` / `graphiql-dark` class on `<body>`.
With no `data-theme` attribute anywhere, the cascade always fell
through to the `@media (prefers-color-scheme)` fallback, so v6
components followed the OS preference instead of the GraphiQL toggle.

Mirror the active theme to `document.documentElement` as a
`data-theme` attribute so the selectors light up. The body classes
remain for any consumer CSS that depends on them.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 17, 2026

🦋 Changeset detected

Latest commit: 74c8018

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@trevor-scheer trevor-scheer marked this pull request as ready for review May 17, 2026 17:49
@github-actions
Copy link
Copy Markdown
Contributor

The latest changes of this PR are not available as canary, since there are no linked changesets for this PR.

@trevor-scheer trevor-scheer merged commit 6627635 into graphiql-6 May 17, 2026
13 checks passed
@trevor-scheer trevor-scheer deleted the trevor/theme-data-attr branch May 17, 2026 17:50
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