Skip to content

Commit

Permalink
fix(v2): set theme color mode for SSR (#4383)
Browse files Browse the repository at this point in the history
  • Loading branch information
lex111 authored Mar 10, 2021
1 parent 02cd5d3 commit 6afa83c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/docusaurus-theme-classic/src/theme/hooks/useTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
};
Expand All @@ -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);
Expand Down

0 comments on commit 6afa83c

Please sign in to comment.