Commit c266423
fix(api): eliminate theme flash on docs.warp.dev/api (#6)
* 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>
* fix(api): boot Scalar in resolved theme to remove dark→light→dark flash
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>
---------
Co-authored-by: Oz <oz-agent@warp.dev>1 parent c92f3c9 commit c266423
1 file changed
Lines changed: 64 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
101 | 109 | | |
102 | 110 | | |
103 | 111 | | |
| |||
128 | 136 | | |
129 | 137 | | |
130 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
131 | 163 | | |
132 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
133 | 181 | | |
134 | 182 | | |
135 | 183 | | |
| |||
254 | 302 | | |
255 | 303 | | |
256 | 304 | | |
257 | | - | |
258 | | - | |
259 | | - | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
260 | 317 | | |
261 | 318 | | |
262 | 319 | | |
263 | 320 | | |
264 | 321 | | |
265 | 322 | | |
266 | 323 | | |
267 | | - | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
268 | 328 | | |
269 | 329 | | |
270 | 330 | | |
| |||
0 commit comments