Skip to content

fix(api): eliminate theme flash on docs.warp.dev/api#6

Merged
hongyi-chen merged 2 commits intomainfrom
fix/api-theme-flash
Apr 30, 2026
Merged

fix(api): eliminate theme flash on docs.warp.dev/api#6
hongyi-chen merged 2 commits intomainfrom
fix/api-theme-flash

Conversation

@hongyi-chen
Copy link
Copy Markdown
Collaborator

Problem

docs.warp.dev/api flashed white on first load before settling into dark mode. The rest of docs.warp.dev does not flash because Starlight's CSS is keyed off :root[data-theme] and applies synchronously when the head script sets the attribute on <html>.

Root cause

The head script in src/pages/api.astro already set <html data-theme="dark|light"> synchronously, but no CSS in <head> keyed off that attribute. All theme-aware styling for /api lived inside Scalar's runtime-injected customCss (which keys off body.dark-mode / body.light-mode), and that block only exists after the Scalar bundle (loaded mid-<body>) downloads, parses, and mounts. So between body parse and Scalar mount, the page painted with the browser default white — then repainted dark.

Fix

Add a small inline <style> block in <head> that paints html (and inheriting body) based on data-theme. The canvas color is now correct on the very first frame, before the Scalar bundle even starts to download. Scalar's customCss still takes over once it mounts.

html[data-theme="dark"]  { background-color: #121212; color-scheme: dark; }
html[data-theme="light"] { background-color: #ffffff; color-scheme: light; }
body { background-color: inherit; }

No JS changes — the existing localStorage read + data-theme write was already correct.

Values mirror --scalar-background-1 from the existing customCss block; comment in the file flags the lockstep dependency.

Validation

  • npm run build succeeds; dist/api/index.html contains the new html[data-theme=dark]{background-color:#121212;color-scheme:dark} rule.
  • After deploy, hard-refresh docs.warp.dev/api in incognito (cold cache) and confirm no white flash in either dark or auto mode.

Artifacts

Co-Authored-By: Oz oz-agent@warp.dev

The /api page flashed white on first load before settling into dark mode.
The head script already set <html data-theme> synchronously, but no CSS
in <head> keyed off that attribute — the only theme-aware CSS lived
inside Scalar's runtime-injected customCss (which keys off body classes
.dark-mode / .light-mode), and that CSS only existed after the Scalar
bundle (loaded mid-<body>) downloaded, parsed, and mounted.

Add an inline <style> in <head> that paints html (and inheriting body)
based on data-theme, so the canvas color is correct on the very first
frame. Scalar's customCss still drives the rest of the page once it
mounts.

Co-Authored-By: Oz <oz-agent@warp.dev>
@cla-bot cla-bot Bot added the cla-signed label Apr 30, 2026
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Apr 30, 2026 9:58pm

Request Review

The previous fix removed the white-on-first-frame flash but exposed a
deeper timing bug: Scalar booted in light mode on cold loads, briefly
flipped the page to light, then DOMContentLoaded restored dark.

Root cause: the Scalar config sync script reads
`document.body.classList.contains('dark-mode')` synchronously inside
<body>, before the head script's body-class apply runs (which is queued
for DOMContentLoaded because document.body is null in <head>). So
cfg.darkMode was always false on cold load → Scalar mounted light → the
mirror MutationObserver flipped html[data-theme]='light' → the new
canvas CSS painted white → DOMContentLoaded fired and corrected
everything.

Fix:
1. Expose `window.__warpResolveTheme()` — a read-only sibling of the
   existing __warpApplyTheme that just resolves localStorage +
   prefers-color-scheme to 'dark' or 'light'.
2. Add a top-of-body inline script that calls __warpResolveTheme() and
   applies the body class synchronously, before any other body-level
   script runs.
3. Switch the Scalar config sync to read __warpResolveTheme() instead
   of body.classList, decoupling Scalar's boot value from DOM apply
   ordering.

Co-Authored-By: Oz <oz-agent@warp.dev>
@hongyi-chen hongyi-chen merged commit c266423 into main Apr 30, 2026
8 checks passed
rachaelrenk added a commit that referenced this pull request May 5, 2026
- Fix title case → sentence case in titles and sidebar labels:
  computer-use, web-search, api-keys, mcp-servers, network-log,
  known-issues
- Simplify integration titles: remove 'for Oz' suffix (azure-devops,
  bitbucket, gitlab, linear, slack)
- Add key principle #6 to SEO audit skill with explicit sentence case
  rule and ✅/❌ examples to prevent future casing mistakes

Co-Authored-By: Oz <oz-agent@warp.dev>
rachaelrenk added a commit that referenced this pull request May 5, 2026
…ss 51 pages (#22)

* Automated SEO fixes: resolve title length and description issues across 51 pages

- Fix 40 title_too_short warnings by adding descriptive frontmatter titles with sidebar.label to preserve nav labels
- Fix 4 title_too_long warnings by shortening guide titles
- Fix 7 description_too_long info issues by trimming descriptions to ≤160 chars
- Skip 5 allowlisted pages (Changelog, Guides, Tabs, Split panes, Tab Configs)
- Skip 1 unfixable page (https://docs.warp.dev/api/ - no source file)

Co-Authored-By: Oz <oz-agent@warp.dev>

* fix: sentence case corrections and skill update for casing rules

- Fix title case → sentence case in titles and sidebar labels:
  computer-use, web-search, api-keys, mcp-servers, network-log,
  known-issues
- Simplify integration titles: remove 'for Oz' suffix (azure-devops,
  bitbucket, gitlab, linear, slack)
- Add key principle #6 to SEO audit skill with explicit sentence case
  rule and ✅/❌ examples to prevent future casing mistakes

Co-Authored-By: Oz <oz-agent@warp.dev>

* fix: remove duplicate sidebar key in skills.mdx frontmatter

Co-Authored-By: Oz <oz-agent@warp.dev>

---------

Co-authored-by: Oz <oz-agent@warp.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants