Skip to content

Commit bb0188a

Browse files
committed
fix(color-mode): fix SSR compat
1 parent c1dbb8f commit bb0188a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/core/src/colorModes.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import {
99
const STORAGE_KEY = 'xstyled-color-mode'
1010

1111
const storage = {
12-
get: () => window.localStorage.getItem(STORAGE_KEY),
12+
get: () =>
13+
typeof window === 'undefined'
14+
? null
15+
: window.localStorage.getItem(STORAGE_KEY),
1316
set: value => window.localStorage.setItem(STORAGE_KEY, value),
1417
clear: () => window.localStorage.removeItem(STORAGE_KEY),
1518
}
@@ -95,7 +98,9 @@ export function createColorStyles(theme, { targetSelector = 'body' } = {}) {
9598
}
9699

97100
function getSystemModeMql(mode) {
98-
if (window.matchMedia === undefined) return null
101+
if (typeof window === 'undefined' || window.matchMedia === undefined) {
102+
return null
103+
}
99104
const query = getColorModeQuery(mode)
100105
return window.matchMedia(query)
101106
}

0 commit comments

Comments
 (0)