feat: theme follows system preference by default + fix dark mode FOUC
- getTheme: manual localStorage override first, else prefers-color-scheme - layout: inline head script sets data-theme before first paint (no white flash in dark mode on loading screen) - AppProvider: listen for system theme change when user hasn't overridden
This commit is contained in:
1 parent
1a8a588d60
commit
e3afba65fa
3 files changed
+36
-2
No files matched your search
+7
-2
@@ -195,8 +195,13 @@ export function generateCaptcha() {
|
||||
return { question: a + ' ' + op + ' ' + b + ' = ?', answer: op === '+' ? a + b : a - b };
|
||||
}
|
||||
|
||||
// 主题
|
||||
// 主题:手动设置优先,否则跟随系统偏好
|
||||
export function getTheme() {
|
||||
if (typeof window === 'undefined') return 'light';
|
||||
return localStorage.getItem('forumlify-theme') || 'light';
|
||||
const saved = localStorage.getItem('forumlify-theme');
|
||||
if (saved) return saved;
|
||||
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||
return 'dark';
|
||||
}
|
||||
return 'light';
|
||||
}
|
||||
Reference in new issue
Block a user