Skip to content

Commit e0588d4

Browse files
hongyi-chenoz-agent
andcommitted
fix(api): paint /api canvas synchronously to eliminate theme flash
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>
1 parent fc1c798 commit e0588d4

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/pages/api.astro

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,30 @@ const specJson = JSON.stringify(specObject);
128128
else document.addEventListener('DOMContentLoaded', startMirror);
129129
})();
130130
</script>
131+
<style>
132+
/* First-paint canvas color, keyed off the `data-theme` attribute set
133+
synchronously by the script above. Without this, `/api` flashes
134+
white before mounting because Scalar's themed `customCss` (which
135+
keys off `body.dark-mode` / `body.light-mode`) only ships inside
136+
the Scalar bundle loaded mid-`<body>`, so nothing paints the
137+
page background until that bundle parses + mounts.
138+
139+
Values mirror `--scalar-background-1` from the customCss block
140+
below. If you change the canvas there (or in custom.css), update
141+
these in lockstep so the first-paint color matches what Scalar
142+
applies a few frames later. */
143+
html[data-theme="dark"] {
144+
background-color: #121212;
145+
color-scheme: dark;
146+
}
147+
html[data-theme="light"] {
148+
background-color: #ffffff;
149+
color-scheme: light;
150+
}
151+
body {
152+
background-color: inherit;
153+
}
154+
</style>
131155
</head>
132156
<body>
133157
<WarpTopbar crumb="API Reference" />

0 commit comments

Comments
 (0)