-
Notifications
You must be signed in to change notification settings - Fork 139
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
base: main
Are you sure you want to change the base?
Conversation
- 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
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
setIsEnabled(newValue); | ||
localStorage.setItem('animatedBackgroundEnabled', String(newValue)); | ||
// Reload the page to apply changes | ||
window.location.reload(); |
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.
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>"); |
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.
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, ")"); |
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.
Consider extracting magic numbers (e.g. gridOpacity, gridSize, and curve strengths) into named constants to improve maintainability and ease of tuning.
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
2. Accessibility Improvements
prefers-reduced-motion
media query3. Performance Optimizations
willChange: transform
CSS hint for better GPU optimizationalpha: false
canvas context for better performance4. Code Organization
BackgroundToggle
component with proper stylingAnimatedBackground
component to respect user preferencesTesting
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.
BackgroundToggle
component to toggle animated background, saving preference inlocalStorage
.prefers-reduced-motion
to automatically disable animation for users with motion sensitivity.AnimatedBackground.js
.willChange: transform
CSS hint for GPU optimization.BackgroundToggle
andAnimatedBackground
intoLayout/index.js
.Codicon
component toMDXComponents.js
.localStorage
persistence.This description was created by
for bd6e775. You can customize this summary. It will automatically update as commits are pushed.