diff --git a/src/hooks/useThemeManager.ts b/src/hooks/useThemeManager.ts index 192e5c68..3efade4c 100644 --- a/src/hooks/useThemeManager.ts +++ b/src/hooks/useThemeManager.ts @@ -79,15 +79,31 @@ function clearColorScheme(): void { delete root.dataset.themeMode } +const THEME_STYLE_ID = 'laputa-theme-vars' + +function getOrCreateThemeStyle(): HTMLStyleElement { + let el = document.getElementById(THEME_STYLE_ID) as HTMLStyleElement | null + if (!el) { + el = document.createElement('style') + el.id = THEME_STYLE_ID + document.head.appendChild(el) + } + return el +} + function applyVarsToDom(vars: Record): void { const root = document.documentElement for (const [key, value] of Object.entries(vars)) { root.style.setProperty(key, value) } updateColorScheme(vars) - // Force WebKit to recalculate ::before/::after pseudo-element styles - // when CSS custom properties change (WKWebView doesn't auto-invalidate). - void root.offsetHeight + // WKWebView doesn't invalidate ::before/::after pseudo-element styles when + // CSS custom properties change via inline styles alone — `void offsetHeight` + // triggers layout reflow but not style recalculation on pseudo-elements. + // Replacing a