From 10aa46aa9e96b90e3929306d6e7a1d2962b874b0 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Thu, 15 Jan 2026 04:41:59 +0200 Subject: [PATCH] Prevent flash of wrong theme on startup (web) (#9577) * prevent flash of wrong theme on startup * move bg color to #root * Update and use existing system * Darken slightly, better contrast --------- Co-authored-by: Eric Bailey --- bskyweb/templates/base.html | 59 +++++++++++++++++++++---------- src/alf/util/useColorModeTheme.ts | 1 + src/style.css | 34 ------------------ web/index.html | 54 +++++++++++++++++++++++----- 4 files changed, 88 insertions(+), 60 deletions(-) diff --git a/bskyweb/templates/base.html b/bskyweb/templates/base.html index b5f504904f..7ecfa66017 100644 --- a/bskyweb/templates/base.html +++ b/bskyweb/templates/base.html @@ -37,29 +37,20 @@ font-style: italic; font-display: swap; } - html { - background-color: white; + :root { + --text: black; + --background: white; + --backgroundLight: #e2e7ee; } @media (prefers-color-scheme: dark) { - html { - background-color: black; + :root { + color-scheme: dark; + --text: white; + --background: black; + --backgroundLight: #232e3e; } } html, - body { - margin: 0px; - padding: 0px; - font-family: InterVariable, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Liberation Sans', Helvetica, Arial, sans-serif; - text-rendering: optimizeLegibility; - /* Platform-specific reset */ - -webkit-overflow-scrolling: touch; - -webkit-text-size-adjust: 100%; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; - -ms-overflow-style: scrollbar; - font-synthesis-weight: none; - } - html, body, #root { display: flex; @@ -67,6 +58,32 @@ min-height: 100%; width: 100%; } + html.theme--light, + html.theme--light body, + html.theme--light #root { + background-color: white; + --text: black; + --background: white; + --backgroundLight: #DCE2EA; + } + html.theme--dark, + html.theme--dark body, + html.theme--dark #root { + color-scheme: dark; + background-color: black; + --text: white; + --background: black; + --backgroundLight: #232E3E; + } + html.theme--dim, + html.theme--dim body, + html.theme--dim #root { + color-scheme: dark; + background-color: #151D28; + --text: white; + --background: #151D28; + --backgroundLight: #2C3A4E; + } #splash { display: flex; position: fixed; @@ -93,6 +110,12 @@ overflow-y: scroll; } + {% include "scripts.html" %} diff --git a/src/alf/util/useColorModeTheme.ts b/src/alf/util/useColorModeTheme.ts index 4ae94899cd..83b13a94ba 100644 --- a/src/alf/util/useColorModeTheme.ts +++ b/src/alf/util/useColorModeTheme.ts @@ -51,6 +51,7 @@ function updateDocument(theme: ThemeName) { html.classList.add(`theme--${theme}`) // set color to 'theme-color' meta tag meta?.setAttribute('content', getBackgroundColor(theme)) + window.localStorage.setItem('ALF_THEME', theme) } } diff --git a/src/style.css b/src/style.css index 97602d88c8..bf2ffed698 100644 --- a/src/style.css +++ b/src/style.css @@ -11,40 +11,6 @@ * * HTML & BODY STYLES IN `web/index.html` and `bskyweb/templates/base.html` */ -:root { - --text: black; - --background: white; - --backgroundLight: #f9fafb; -} -@media (prefers-color-scheme: dark) { - :root { - color-scheme: dark; - --text: white; - --background: black; - --backgroundLight: #111822; - } -} - -html.theme--light { - --text: black; - --background: white; - --backgroundLight: #f9fafb; - background-color: white; -} -html.theme--dark { - color-scheme: dark; - background-color: black; - --text: white; - --background: black; - --backgroundLight: #111822; -} -html.theme--dim { - color-scheme: dark; - background-color: #151d28; - --text: white; - --background: #151d28; - --backgroundLight: #1c2736; -} /* Buttons and inputs have a font set by UA, so we'll have to reset that */ button, diff --git a/web/index.html b/web/index.html index 5458b57a36..89d5d955f9 100644 --- a/web/index.html +++ b/web/index.html @@ -19,6 +19,7 @@ %WEB_TITLE% + +