fix(frontend,macos): reduce dark mode white flash on window open
Detect dark/light mode before React hydrates to eliminate the visible white-to-dark flash when opening windows in dark mode. Frontend: - Inline script now reads next-themes localStorage key and applies .dark class, colorScheme, and backgroundColor on <html> before first paint - Add CSS-only fallback via prefers-color-scheme media query in an inline <style> tag that fires before any JS executes macOS backend: - Detect system dark mode via `defaults read -g AppleInterfaceStyle` (cached with OnceLock) and set native window background color to match dark theme in apply_platform_window_style - Persist user appearance mode preference (dark/light/system) to DB alongside zoom level so new windows use the correct background - Add update_appearance_mode Tauri command; frontend syncs on mount, on settings change, and on cross-window storage events Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -51,7 +51,13 @@ export default async function RootLayout({
|
||||
suppressHydrationWarning
|
||||
>
|
||||
<body>
|
||||
{/* Apply appearance preferences (theme color + zoom) before first paint to prevent FOUC */}
|
||||
{/* CSS-only dark background: applies before JS executes, preventing white flash in dark mode */}
|
||||
<style
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `@media(prefers-color-scheme:dark){html:not(.light){background-color:#09090b;color-scheme:dark}}`,
|
||||
}}
|
||||
/>
|
||||
{/* Apply appearance preferences (theme color + zoom + dark class) before first paint to prevent FOUC */}
|
||||
<script dangerouslySetInnerHTML={{ __html: APPEARANCE_INIT_SCRIPT }} />
|
||||
{/* Suppress benign ResizeObserver loop warnings (W3C spec §3.3) */}
|
||||
<script>{`window.addEventListener("error",function(e){if(e.message&&e.message.indexOf("ResizeObserver")!==-1){e.stopImmediatePropagation();e.preventDefault()}});window.onerror=function(m){if(typeof m==="string"&&m.indexOf("ResizeObserver")!==-1)return true}`}</script>
|
||||
|
||||
Reference in New Issue
Block a user