未验证 提交 f7b8e540 编写于 作者: P Peter Pan 提交者: GitHub

fix: theme broken in some cases (#985)

上级 5f2f5761
......@@ -14,15 +14,14 @@
* limitations under the License.
*/
import {THEME, autoTheme} from '~/utils/theme';
import {THEME, autoTheme, parseTheme} from '~/utils/theme';
import type {ThemeActionTypes, ThemeState} from './types';
import {ActionTypes} from './types';
import type {Theme} from '~/utils/theme';
const STORAGE_KEY = 'theme';
const theme = THEME || (window.localStorage.getItem(STORAGE_KEY) as Theme | undefined) || 'auto';
const theme = THEME || parseTheme(window.localStorage.getItem(STORAGE_KEY) || '') || 'auto';
const initState: ThemeState = {
theme: theme === 'auto' ? autoTheme : theme,
......
......@@ -21,7 +21,9 @@ import kebabCase from 'lodash/kebabCase';
export type Theme = 'light' | 'dark';
export const THEME: Theme | undefined = import.meta.env.SNOWPACK_PUBLIC_THEME;
export const parseTheme = (t: string): Theme | undefined => (['light', 'dark'].includes(t) ? (t as Theme) : undefined);
export const THEME = parseTheme(import.meta.env.SNOWPACK_PUBLIC_THEME);
export const matchMedia = window.matchMedia('(prefers-color-scheme: dark)');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册