Skip to content

Commit

Permalink
fix(color-mode): fix SSR compat
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Sep 26, 2019
1 parent c1dbb8f commit bb0188a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/core/src/colorModes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import {
const STORAGE_KEY = 'xstyled-color-mode'

const storage = {
get: () => window.localStorage.getItem(STORAGE_KEY),
get: () =>
typeof window === 'undefined'
? null
: window.localStorage.getItem(STORAGE_KEY),
set: value => window.localStorage.setItem(STORAGE_KEY, value),
clear: () => window.localStorage.removeItem(STORAGE_KEY),
}
Expand Down Expand Up @@ -95,7 +98,9 @@ export function createColorStyles(theme, { targetSelector = 'body' } = {}) {
}

function getSystemModeMql(mode) {
if (window.matchMedia === undefined) return null
if (typeof window === 'undefined' || window.matchMedia === undefined) {
return null
}
const query = getColorModeQuery(mode)
return window.matchMedia(query)
}
Expand Down

0 comments on commit bb0188a

Please sign in to comment.