Skip to content

Commit

Permalink
fix(color-mode): fix document undefined on SSR
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Sep 26, 2019
1 parent c95d7d1 commit 606ecac
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/core/src/colorModes.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function useSystemMode(theme) {
return systemMode
}

export function useColorModeState(theme, { target = document.body } = {}) {
export function useColorModeState(theme, { target } = {}) {
const systemMode = useSystemMode(theme)
const defaultColorMode = getDefaultColorModeName(theme)
const initialColorMode = getInitialColorModeName(theme)
Expand Down Expand Up @@ -177,9 +177,10 @@ export function useColorModeState(theme, { target = document.body } = {}) {
const initial = initialColorMode !== mode
if (!stored && !initial) return undefined
const className = getColorModeClassName(mode)
target.classList.add(className)
const usedTarget = target || document.body
usedTarget.classList.add(className)
return () => {
target.classList.remove(className)
usedTarget.classList.remove(className)
}
}, [customPropertiesEnabled, target, mode, initialColorMode])

Expand Down

0 comments on commit 606ecac

Please sign in to comment.