Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Sep 26, 2025

Summary

  • AnimatedBackground now respects prefers-reduced-motion.
  • When reduce is enabled, it renders a single static frame and does not start the requestAnimationFrame loop.
  • If the preference changes at runtime to reduce, any running animation stops immediately and a static frame is rendered.
  • Mousemove listener is only attached when animation is enabled.

Implementation details

  • Introduced media query detection and change listener for (prefers-reduced-motion: reduce).
  • startAnimation/stopAnimation helpers ensure no RAF or mouse listeners under reduced motion.
  • Resize continues to redraw a static frame without animation.

Testing

  • Manual: Enabled OS/browser reduced motion and verified there is no animation (no RAF), canvas renders static grid/gradients.
  • Toggled reduced motion at runtime and verified animation stops and re-renders static frame.
  • Ran repository tests with Vitest; all suites pass.

Notes

  • Optional micro-optimizations (not required): skip self-pairs in connectParticles inner loop; skip particle creation entirely when reduced motion is active at mount.

Important

AnimatedBackground now respects prefers-reduced-motion, rendering a static frame and stopping animations when reduced motion is preferred.

  • Behavior:
    • AnimatedBackground respects prefers-reduced-motion by rendering a static frame and stopping requestAnimationFrame loop when reduced motion is enabled.
    • On runtime preference change to reduce, stops animation and renders static frame.
    • mousemove listener attached only when animation is enabled.
  • Implementation:
    • Introduces media query detection and change listener for (prefers-reduced-motion: reduce).
    • startAnimation/stopAnimation helpers ensure no RAF or mouse listeners under reduced motion.
    • resizeCanvas continues to redraw a static frame without animation.
  • Testing:
    • Manual: Verified no animation with reduced motion enabled, static grid/gradients rendered.
    • Toggled reduced motion at runtime, verified animation stops and static frame re-renders.
    • All repository tests pass with Vitest.

This description was created by Ellipsis for cd07bac. You can customize this summary. It will automatically update as commits are pushed.

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.
@roomote roomote bot requested review from cte, jr and mrubens as code owners September 26, 2025 16:02
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Sep 26, 2025
@github-actions
Copy link
Contributor

🚀 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.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Sep 26, 2025
Copy link
Contributor Author

@roomote roomote bot left a 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)
Copy link
Contributor Author

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.

Suggested change
if (animationId !== undefined) cancelAnimationFrame(animationId)
if (animationId !== undefined) {
cancelAnimationFrame(animationId)
animationId = undefined
}

drawGrid()
} else {
startAnimation()
}
Copy link
Contributor Author

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.

Suggested change
}
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)
Copy link
Contributor Author

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.

Suggested change
if (mediaQuery) mediaQuery.removeEventListener("change", onMotionPreferenceChange)
if ("removeEventListener" in mediaQuery) {
mediaQuery.removeEventListener("change", onMotionPreferenceChange)
} else {
// @ts-expect-error legacy API
mediaQuery.removeListener(onMotionPreferenceChange)
}

@daniel-lxs
Copy link
Member

Closing as stale

@daniel-lxs daniel-lxs closed this Oct 14, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Oct 14, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants