-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix(web): respect prefers-reduced-motion in AnimatedBackground #8329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Ensure the animated canvas renders a single static frame and never starts requestAnimationFrame when prefers-reduced-motion: reduce is enabled. Adds runtime listener to stop animations if the user toggles the setting. Mousemove listener is only attached when animating.
|
🚀 Preview deployed! Your changes have been deployed to Vercel: Preview URL: https://roo-code-website-mvch0cz82-roo-code.vercel.app This preview will be updated automatically when you push new commits to this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewing my own code: the ouroboros of accountability continues to chew quietly.
| if (!isAnimating) return | ||
| isAnimating = false | ||
| window.removeEventListener("mousemove", handleMouseMove) | ||
| if (animationId !== undefined) cancelAnimationFrame(animationId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: Minor: after cancelAnimationFrame, reset animationId to undefined to avoid accidental double-cancel or stale ids after toggling animation state.
| if (animationId !== undefined) cancelAnimationFrame(animationId) | |
| if (animationId !== undefined) { | |
| cancelAnimationFrame(animationId) | |
| animationId = undefined | |
| } |
| drawGrid() | ||
| } else { | ||
| startAnimation() | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Older Safari uses the legacy addListener API for MediaQueryList. Add a runtime fallback so preference changes are handled across browsers.
| } | |
| if ("addEventListener" in mediaQuery) { | |
| mediaQuery.addEventListener("change", onMotionPreferenceChange) | |
| } else { | |
| // Safari < 14 | |
| // @ts-expect-error legacy API | |
| mediaQuery.addListener(onMotionPreferenceChange) | |
| } |
| cancelAnimationFrame(animationId) | ||
| // Ensure animation and listeners are stopped | ||
| stopAnimation() | ||
| if (mediaQuery) mediaQuery.removeEventListener("change", onMotionPreferenceChange) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Mirror the addListener fallback on cleanup to ensure the change listener is properly removed in older Safari.
| if (mediaQuery) mediaQuery.removeEventListener("change", onMotionPreferenceChange) | |
| if ("removeEventListener" in mediaQuery) { | |
| mediaQuery.removeEventListener("change", onMotionPreferenceChange) | |
| } else { | |
| // @ts-expect-error legacy API | |
| mediaQuery.removeListener(onMotionPreferenceChange) | |
| } |
|
Closing as stale |
Summary
Implementation details
Testing
Notes
Important
AnimatedBackgroundnow respectsprefers-reduced-motion, rendering a static frame and stopping animations when reduced motion is preferred.AnimatedBackgroundrespectsprefers-reduced-motionby rendering a static frame and stoppingrequestAnimationFrameloop when reduced motion is enabled.mousemovelistener attached only when animation is enabled.(prefers-reduced-motion: reduce).startAnimation/stopAnimationhelpers ensure no RAF or mouse listeners under reduced motion.resizeCanvascontinues to redraw a static frame without animation.This description was created by
for cd07bac. You can customize this summary. It will automatically update as commits are pushed.