From 6afa83c4195478d178e3f89ba5a2a2fd04d1c41c Mon Sep 17 00:00:00 2001 From: Alexey Pyltsyn Date: Wed, 10 Mar 2021 22:10:07 +0300 Subject: [PATCH] fix(v2): set theme color mode for SSR (#4383) --- .../docusaurus-theme-classic/src/theme/hooks/useTheme.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/hooks/useTheme.ts b/packages/docusaurus-theme-classic/src/theme/hooks/useTheme.ts index b3a58630bd47..b2a24c356c39 100644 --- a/packages/docusaurus-theme-classic/src/theme/hooks/useTheme.ts +++ b/packages/docusaurus-theme-classic/src/theme/hooks/useTheme.ts @@ -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);