Skip to content

Commit 94e0b7d

Browse files
committed
Minify further
1 parent 6c11128 commit 94e0b7d

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

lib/src/client/switcher/switcher.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ThemeSwitcherProps } from "../theme-switcher";
22
import { DARK, DEFAULT_ID, LIGHT } from "../../constants";
3-
import { useThemeStore } from "../../store";
3+
import { UNDEFINED, useThemeStore } from "../../store";
44
import type { ResolveFunc, UpdateDOMFunc, UpdateForcedPropsFunc } from "../theme-switcher/no-fouc";
55

66
let media: MediaQueryList;
@@ -43,7 +43,7 @@ export const Switcher = ({
4343

4444
const [state, setState] = useThemeStore(targetSelector);
4545

46-
if (typeof m != "undefined" && !updateForcedProps) {
46+
if (typeof m != UNDEFINED && !updateForcedProps) {
4747
[media, updateDOM, resolveTheme, updateForcedProps] = [m, u, r, f];
4848

4949
media.addEventListener("change", () =>

lib/src/client/theme-switcher/theme-switcher.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ColorSchemeType } from "../../types";
22
import { noFOUCScript, type ScriptArgs } from "./no-fouc";
3-
import { initialState } from "../../store";
3+
import { initialState, UNDEFINED } from "../../store";
44
import { DEFAULT_ID } from "../../constants";
55
import { Switcher } from "../switcher";
66

@@ -53,7 +53,7 @@ const Script = ({
5353
forcedColorScheme,
5454
] as ScriptArgs;
5555
// handle client side exceptions when script is not run. <- for client side apps like vite or CRA
56-
typeof window !== "undefined" && noFOUCScript(...args);
56+
typeof window != UNDEFINED && noFOUCScript(...args);
5757
return (
5858
<script
5959
// skipcq: JS-0440

lib/src/hooks/use-theme.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { useEffect } from "react";
2-
import { useThemeStore } from "../store";
1+
import { UNDEFINED, useThemeStore } from "../store";
32
import { ResolveFunc } from "../client/theme-switcher/no-fouc";
43
import { ColorSchemeType, ResolvedColorSchemeType } from "../types";
54
import { DARK, LIGHT, SYSTEM } from "../constants";
@@ -37,9 +36,7 @@ export interface UseThemeYield {
3736

3837
export const useTheme = (targetSelector?: string): UseThemeYield => {
3938
const [state, setState] = useThemeStore(targetSelector);
40-
useEffect(() => {
41-
resolveTheme = window.r;
42-
}, []);
39+
if (!resolveTheme && typeof window != UNDEFINED) resolveTheme = window.r;
4340

4441
/** helper */
4542
const setter =

lib/src/store.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ export const initialState: ThemeStoreType = {
3030
s: LIGHT,
3131
};
3232

33+
export const UNDEFINED = "undefined";
34+
3335
/** @internal store */
3436
export const useThemeStore = (targetSelector?: string) => {
3537
const key = targetSelector ?? "#" + DEFAULT_ID;
3638
return useRGS<ThemeStoreType>(key, () => {
37-
const str = typeof m !== "undefined" && localStorage.getItem(key);
39+
const str = typeof m !== UNDEFINED && localStorage.getItem(key);
3840
return str ? { ...JSON.parse(str), s: m.matches ? DARK : LIGHT } : initialState;
3941
});
4042
};

0 commit comments

Comments
 (0)