Skip to content

feat: add toggle for animated background with performance optimizations #299

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

roomote[bot]
Copy link
Contributor

@roomote roomote bot commented Aug 5, 2025

This PR addresses the GPU strain and battery drain issues caused by the animated background graphics on the documentation site.

Changes Made

1. User Preference Toggle

  • Added a floating toggle button (bottom-right corner) that allows users to enable/disable the animated background
  • User preference is saved to localStorage and persists across sessions
  • Toggle shows 🎨 when enabled and 🚫 when disabled

2. Accessibility Improvements

  • Implemented automatic detection of prefers-reduced-motion media query
  • When users have reduced motion enabled in their OS settings, the animation is automatically disabled
  • This ensures better accessibility for users with motion sensitivity

3. Performance Optimizations

  • Reduced particle count from 50 to 30 (with dynamic scaling based on screen width)
  • Implemented frame skipping to run animation at 30fps instead of 60fps
  • Added mouse movement throttling to limit updates to 20fps
  • Added willChange: transform CSS hint for better GPU optimization
  • Used alpha: false canvas context for better performance

4. Code Organization

  • Created new BackgroundToggle component with proper styling
  • Updated AnimatedBackground component to respect user preferences
  • Integrated both components into the main Layout

Testing

  • Tested toggle functionality across page reloads
  • Verified localStorage persistence
  • Confirmed reduced motion detection works
  • Validated performance improvements

Impact

This change allows users who experience GPU strain or battery drain to disable the animated background while maintaining the visual appeal for users who prefer it. The performance optimizations also reduce the resource usage even when the animation is enabled.

Fixes the issue reported about GPU strain and battery drain on laptops when viewing the documentation.


Important

Adds a toggle for animated backgrounds with performance optimizations and accessibility improvements.

  • Behavior:
    • Adds BackgroundToggle component to toggle animated background, saving preference in localStorage.
    • Detects prefers-reduced-motion to automatically disable animation for users with motion sensitivity.
  • Performance:
    • Reduces particle count from 50 to 30 in AnimatedBackground.js.
    • Implements frame skipping to 30fps and mouse movement throttling to 20fps.
    • Adds willChange: transform CSS hint for GPU optimization.
  • Code Organization:
    • Integrates BackgroundToggle and AnimatedBackground into Layout/index.js.
    • Adds Codicon component to MDXComponents.js.
  • Testing:
    • Verified toggle functionality and localStorage persistence.
    • Confirmed reduced motion detection and performance improvements.

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

- Add user preference to disable animated background
- Implement reduced motion detection for accessibility
- Optimize animation performance (reduce particles, throttle mouse events, 30fps)
- Add floating toggle button to enable/disable background
- Persist user preference in localStorage

Addresses GPU strain and battery drain issues reported by users
Copy link

vercel bot commented Aug 5, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
roo-code-docs ❌ Failed (Inspect) Aug 5, 2025 11:19pm

setIsEnabled(newValue);
localStorage.setItem('animatedBackgroundEnabled', String(newValue));
// Reload the page to apply changes
window.location.reload();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reloading the page to apply the toggle isn’t optimal for UX; consider using state management or context to re-render components without a full page reload.

{tutorial_videos_json_1.default.videos.map(function (video) { return (<div key={video.id} className="video-item">
<div className="video-container" onClick={function (e) {
var target = e.currentTarget;
target.innerHTML = "<iframe src='https://www.youtube.com/embed/".concat(video.id, "?autoplay=1' title='").concat(video.title, "' allow='accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture' allowFullScreen></iframe>");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Directly setting innerHTML on click bypasses React’s rendering. Consider using state to conditionally render an iframe instead.

ctx.fillRect(0, 0, canvas.width, canvas.height);
});
// Draw grid lines with perspective effect
ctx.strokeStyle = "rgba(50, 50, 70, ".concat(gridOpacity, ")");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider extracting magic numbers (e.g. gridOpacity, gridSize, and curve strengths) into named constants to improve maintainability and ease of tuning.

@daniel-lxs daniel-lxs marked this pull request as draft August 7, 2025 00:42
@daniel-lxs daniel-lxs moved this from Triage to PR [Draft / In Progress] in Roo Code Roadmap Aug 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: PR [Draft / In Progress]
Development

Successfully merging this pull request may close these issues.

2 participants