Files
compiler-explorer/views
Aryan Naraghi 62e6a813c8 Fixes the flash of white issue when theme is set to system and the user has dark mode enabled (#8720)
Currently, when the user's theme is set to "Same as system", the string
"system" is written as the settings.theme key in Local Storage. When the
page first loads, a JavaScript function in `<head>` injects the value of
settings.theme ("system") into the `data-theme` attribute of the
`<html>` tag with the aim of immediately selecting the correct CSS theme
file. However, there is no matching CSS file for "data-theme=system" in
static/styles/themes.

Eventually, the `setTheme()` function in static/themes.ts figures out
the correct theme CSS file to use. In the interim, for users who have
dark mode enabled on their system, they see a flash of white until
`setTheme()` finishes because DOM rendering has already begun before
`setTheme()` starts.

The fix is to set `data-theme` at the start to:

* "dark" when the system is in dark mode and (settings.theme == "system"
or unset); and
* "default" when the system is **not** in dark mode and (settings.theme
== "system" or unset).

This PR also fixes a second issue: the "real-dark" and "onedark"
settings.theme values are currently not handled properly by the `<head>`
script. For "real-dark", `data-theme` needs to be "dark" and for
"onedark", `data-theme` needs to be "one-dark". Again, this is handled
correctly by static/themes.ts, so this bug merely results in a temporary
flash were the wrong CSS is applied until static/themes.ts runs.

See demo:
https://github.com/user-attachments/assets/e6d232dd-a805-46f2-9bd6-e730391862c5
2026-05-26 22:55:15 +02:00
..
2025-10-14 13:51:16 +02:00
2019-09-06 19:39:31 -04:00
2022-11-13 10:35:39 -06:00