Skip to content

Commit 1bb5cb8

Browse files
authored
fix(color-mode): fix clearing color mode (#385)
1 parent 0843917 commit 1bb5cb8

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

packages/core/src/colorModes.tsx

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,13 @@ export function useColorModeState(
221221
// Add mode className
222222
const customPropertiesEnabled = checkHasCustomPropertiesEnabled(theme)
223223

224-
const manualSetRef = React.useRef(false)
225224
const manuallySetMode = React.useCallback((value: string | null) => {
226-
manualSetRef.current = true
227-
setMode(value)
225+
setMode(value || null)
226+
if (value) {
227+
storage.set(value)
228+
} else {
229+
storage.clear()
230+
}
228231
}, [])
229232

230233
// Set initial color mode in lazy
@@ -237,17 +240,6 @@ export function useColorModeState(
237240
}
238241
}, [])
239242

240-
// Store mode preference
241-
useIsomorphicLayoutEffect(() => {
242-
if (manualSetRef.current) {
243-
if (mode) {
244-
storage.set(mode)
245-
} else {
246-
storage.clear()
247-
}
248-
}
249-
}, [mode])
250-
251243
// Sync system mode
252244
useIsomorphicLayoutEffect(() => {
253245
const storedMode = storage.get()

0 commit comments

Comments
 (0)