fix: respect prefers-reduced-motion in GlowingEffect component - #534
fix: respect prefers-reduced-motion in GlowingEffect component#534Somil450 wants to merge 1 commit into
Conversation
Closes piyushdotcomm#524 The CSS media query in globals.css already halts CSS animations for users with prefers-reduced-motion. However the GlowingEffect component uses Motion's animate() JS API for its conic-gradient rotation, which bypasses CSS media queries entirely. Adds useReducedMotion() from motion/react (2 lines) to bail out of the pointermove/scroll effect handlers when the user prefers reduced motion, preventing the JS-driven animation from running at all.
👋 Thanks for opening a PR, @Somil450!Your PR has entered the 🚦 PR Review Pipeline.
What happens next
A pipeline status comment will appear below and update automatically as your PR progresses. While you wait
This comment is posted only once. |
|
Warning Review limit reached
Next review available in: 35 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoFix: respect prefers-reduced-motion in GlowingEffect
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Code Review by Qodo
Context used✅ Compliance rules (platform):
22 rules 1. Missing effect dependency
|
|
|
||
| useEffect(() => { | ||
| if (disabled || !isVisible) return; | ||
| if (disabled || !isVisible || prefersReducedMotion) return; |
There was a problem hiding this comment.
1. Missing effect dependency 🐞 Bug ≡ Correctness
GlowingEffect’s event-listener useEffect reads prefersReducedMotion but omits it from the dependency array, so changes to the reduced-motion preference won’t re-run the effect and may leave listeners (and associated animation work) active until some other dependency changes or the component unmounts. This is also the pattern flagged by the React hooks exhaustive-deps rule typically enabled via next/core-web-vitals.
Agent Prompt
### Issue description
`prefersReducedMotion` is used inside the event-listener `useEffect` but is not included in its dependency array. As a result, toggling the OS-level reduced-motion preference while the component is mounted will not trigger effect cleanup/re-subscription.
### Issue Context
- `prefersReducedMotion` is read via `useReducedMotion()`.
- The effect condition now early-returns when `prefersReducedMotion` is true.
- The effect dependency list currently does not include `prefersReducedMotion`.
### Fix Focus Areas
- components/ui/glowing-effect.tsx[117-135]
### Proposed fix
Update the dependency array to include `prefersReducedMotion` so the effect cleans up listeners when the preference changes:
```ts
useEffect(() => {
if (disabled || !isVisible || prefersReducedMotion) return;
// ...
}, [handleMove, disabled, isVisible, prefersReducedMotion]);
```
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Summary
Closes #524
Adds
useReducedMotion()frommotion/reactto theGlowingEffectcomponent to stop its JS-driven animation when the user has enabled the OS-level "Reduce motion" preference.Problem
The CSS media query already in
app/globals.csscovers CSS-based animations. However,GlowingEffectuses Motion'sanimate()JavaScript API to drive a conic-gradient rotation - a JS animation that completely bypasses CSS media queries. Users who set "Reduce motion" in their OS still had this animation running.Change