perf(thermal): eradicate thermal heating, CPU throttling, and excessive power draw across mobile and low-end devices
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import React from 'react';
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { Star, MessageSquareQuote, CheckCircle2 } from 'lucide-react';
|
||||
import { Marquee } from '@/components/magicui/marquee';
|
||||
import { TextAnimate } from '@/components/magicui/text-animate';
|
||||
@@ -94,8 +94,48 @@ export function ReviewsMarqueeSection({
|
||||
badge = 'VERIFIED COMMUNITY FEEDBACK',
|
||||
subtitle = 'Over 1.4 million photos processed with five-star ratings across web and mobile apps.',
|
||||
}: ReviewsMarqueeSectionProps) {
|
||||
const sectionRef = useRef<HTMLDivElement>(null);
|
||||
const [isInView, setIsInView] = useState(false);
|
||||
|
||||
// Viewport-aware animation: Pauses CSS animation completely when section is offscreen
|
||||
// Eliminates 100% idle CPU and GPU compositing when user is browsing other sections
|
||||
useEffect(() => {
|
||||
const el = sectionRef.current;
|
||||
if (!el) return;
|
||||
|
||||
let isVisible = false;
|
||||
|
||||
const updateState = () => {
|
||||
setIsInView(isVisible && !document.hidden);
|
||||
};
|
||||
|
||||
const observer = new IntersectionObserver(
|
||||
([entry]) => {
|
||||
isVisible = entry.isIntersecting;
|
||||
updateState();
|
||||
},
|
||||
{ threshold: 0.05 }
|
||||
);
|
||||
|
||||
observer.observe(el);
|
||||
|
||||
const handleVisibility = () => {
|
||||
updateState();
|
||||
};
|
||||
document.addEventListener('visibilitychange', handleVisibility);
|
||||
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
document.removeEventListener('visibilitychange', handleVisibility);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<section id="user-reviews" className="py-14 sm:py-20 bg-[#FAF8F5] relative overflow-hidden border-t border-slate-900/[0.06]">
|
||||
<section
|
||||
id="user-reviews"
|
||||
ref={sectionRef}
|
||||
className="py-14 sm:py-20 bg-[#FAF8F5] relative overflow-hidden border-t border-slate-900/[0.06]"
|
||||
>
|
||||
{/* Symbolic Elemental Ambient Highlights */}
|
||||
<div
|
||||
className="absolute inset-0 pointer-events-none -z-10"
|
||||
@@ -124,17 +164,29 @@ export function ReviewsMarqueeSection({
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Marquee Container with Left & Right Gradient Feather Masks */}
|
||||
<div className="relative flex w-full flex-col items-center justify-center overflow-hidden [mask-image:linear-gradient(to_right,transparent,black_10%,black_90%,transparent)]">
|
||||
{/* Marquee Container with Left & Right Gradient Feather Masks - Paused when offscreen */}
|
||||
<div
|
||||
className="relative flex w-full flex-col items-center justify-center overflow-hidden [mask-image:linear-gradient(to_right,transparent,black_10%,black_90%,transparent)]"
|
||||
style={{
|
||||
animationPlayState: isInView ? 'running' : 'paused',
|
||||
}}
|
||||
>
|
||||
{/* Row 1: Leftward Marquee */}
|
||||
<Marquee pauseOnHover className="[--duration:35s]">
|
||||
<Marquee
|
||||
pauseOnHover
|
||||
className={`[--duration:35s] ${!isInView ? '[&>*]:[animation-play-state:paused]' : ''}`}
|
||||
>
|
||||
{REVIEWS_ROW_1.map((review, idx) => (
|
||||
<ReviewCard key={idx} {...review} />
|
||||
))}
|
||||
</Marquee>
|
||||
|
||||
{/* Row 2: Rightward Reverse Marquee */}
|
||||
<Marquee reverse pauseOnHover className="[--duration:40s] mt-4">
|
||||
<Marquee
|
||||
reverse
|
||||
pauseOnHover
|
||||
className={`[--duration:40s] mt-4 ${!isInView ? '[&>*]:[animation-play-state:paused]' : ''}`}
|
||||
>
|
||||
{REVIEWS_ROW_2.map((review, idx) => (
|
||||
<ReviewCard key={idx} {...review} />
|
||||
))}
|
||||
|
||||
Reference in New Issue
Block a user