mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 07:37:19 +02:00
fix(v2): set theme color mode for SSR (#4383)
This commit is contained in:
parent
02cd5d343b
commit
6afa83c419
1 changed files with 4 additions and 4 deletions
|
@ -21,9 +21,9 @@ const coerceToTheme = (theme) => {
|
|||
return theme === themes.dark ? themes.dark : themes.light;
|
||||
};
|
||||
|
||||
const getInitialTheme = () => {
|
||||
const getInitialTheme = (defaultMode) => {
|
||||
if (!ExecutionEnvironment.canUseDOM) {
|
||||
return themes.light; // SSR: we don't care
|
||||
return coerceToTheme(defaultMode);
|
||||
}
|
||||
return coerceToTheme(document.documentElement.getAttribute('data-theme'));
|
||||
};
|
||||
|
@ -38,9 +38,9 @@ const storeTheme = (newTheme) => {
|
|||
|
||||
const useTheme = (): useThemeReturns => {
|
||||
const {
|
||||
colorMode: {disableSwitch, respectPrefersColorScheme},
|
||||
colorMode: {defaultMode, disableSwitch, respectPrefersColorScheme},
|
||||
} = useThemeConfig();
|
||||
const [theme, setTheme] = useState(getInitialTheme);
|
||||
const [theme, setTheme] = useState(getInitialTheme(defaultMode));
|
||||
|
||||
const setLightTheme = useCallback(() => {
|
||||
setTheme(themes.light);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue