Skip to content

Commit 579f2d1

Browse files
committed
fix(clerk-js): Update usePrefersReducedMotion initial value
1 parent 125255b commit 579f2d1

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

packages/clerk-js/src/ui/hooks/usePrefersReducedMotion.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import { useEffect, useState } from 'react';
33
const mediaQueryNoPreference = '(prefers-reduced-motion: no-preference)';
44

55
export function usePrefersReducedMotion() {
6-
const [prefersReducedMotion, setPrefersReducedMotion] = useState(true);
6+
// Get the correct initial value instead of defaulting to true
7+
const getInitialValue = () => {
8+
if (typeof window === 'undefined') return true; // SSR fallback
9+
return !window.matchMedia(mediaQueryNoPreference).matches;
10+
};
11+
12+
const [prefersReducedMotion, setPrefersReducedMotion] = useState(getInitialValue);
713

814
useEffect(() => {
915
const mediaQueryList = window.matchMedia(mediaQueryNoPreference);

0 commit comments

Comments
 (0)