mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-29 16:43:16 +00:00
Fix: Prevent flash in dark mode
This commit is contained in:
@@ -3,7 +3,6 @@ import Navigation from './Navigation';
|
||||
import Conversation from './conversation/Conversation';
|
||||
import About from './About';
|
||||
import PageNotFound from './PageNotFound';
|
||||
import { inject } from '@vercel/analytics';
|
||||
import { useMediaQuery } from './hooks';
|
||||
import { useState } from 'react';
|
||||
import Setting from './settings';
|
||||
@@ -11,7 +10,6 @@ import './locale/i18n';
|
||||
import { Outlet } from 'react-router-dom';
|
||||
import { SharedConversation } from './conversation/SharedConversation';
|
||||
import { useDarkTheme } from './hooks';
|
||||
inject();
|
||||
|
||||
function MainLayout() {
|
||||
const { isMobile } = useMediaQuery();
|
||||
@@ -34,7 +32,10 @@ function MainLayout() {
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
useDarkTheme();
|
||||
const [,,componentMounted] = useDarkTheme();
|
||||
if(!componentMounted) {
|
||||
return <div />
|
||||
}
|
||||
return (
|
||||
<div className="h-full relative overflow-auto">
|
||||
<Routes>
|
||||
|
||||
@@ -82,6 +82,7 @@ export function useDarkTheme() {
|
||||
};
|
||||
|
||||
const [isDarkTheme, setIsDarkTheme] = useState<boolean>(getInitialTheme());
|
||||
const [componentMounted, setComponentMounted] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
||||
@@ -102,11 +103,12 @@ export function useDarkTheme() {
|
||||
} else {
|
||||
document.body?.classList.remove('dark');
|
||||
}
|
||||
setComponentMounted(true);
|
||||
}, [isDarkTheme]);
|
||||
|
||||
const toggleTheme = () => {
|
||||
setIsDarkTheme(!isDarkTheme);
|
||||
};
|
||||
|
||||
return [isDarkTheme, toggleTheme] as const;
|
||||
return [isDarkTheme, toggleTheme, componentMounted] as const;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user