perf(smoothness): eliminate scroll lag via responsive WebP hero, native 120Hz smooth scroll, intersection observer navbar, and removing 50+ backdrop-filter blur bottlenecks

This commit is contained in:
2026-11-05 17:15:36 +05:30
parent 44cb60ecfe
commit d13008b334
11 changed files with 73 additions and 174 deletions
+32 -14
View File
@@ -17,18 +17,36 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
const [mobileMenuOpen, setMobileMenuOpen] = useState(false);
const pathname = usePathname();
// Track scroll position: transforms from text buttons into semi-solid navbar
// 100% Off-Main-Thread Observer: 0% CPU, 0 Scroll Lag
useEffect(() => {
const handleScroll = () => {
// On homepage, transform smoothly when scrolling towards the end of the hero image
const heroThreshold = typeof window !== 'undefined' ? Math.max(320, window.innerHeight * 0.7) : 450;
const threshold = pathname === '/' ? heroThreshold : 20;
setIsScrolled(window.scrollY > threshold);
};
// On non-homepage pages, navbar is immediately in solid state
if (pathname !== '/') {
setIsScrolled(true);
return;
}
handleScroll();
window.addEventListener('scroll', handleScroll, { passive: true });
return () => window.removeEventListener('scroll', handleScroll);
setIsScrolled(false);
const sentinel = document.getElementById('hero-sentinel');
if (!sentinel) {
const handleScroll = () => {
setIsScrolled(window.scrollY > 400);
};
window.addEventListener('scroll', handleScroll, { passive: true });
return () => window.removeEventListener('scroll', handleScroll);
}
const observer = new IntersectionObserver(
([entry]) => {
setIsScrolled(!entry.isIntersecting && entry.boundingClientRect.top < 0);
},
{
threshold: 0,
rootMargin: '-60px 0px 0px 0px',
}
);
observer.observe(sentinel);
return () => observer.disconnect();
}, [pathname]);
// Close mobile menu on Escape key
@@ -61,12 +79,12 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
return (
<header
className={`fixed top-0 left-0 right-0 w-full z-50 transition-all duration-300 pointer-events-auto ${
className={`fixed top-0 left-0 right-0 w-full z-50 transition-[background-color,border-color,padding] duration-200 pointer-events-auto ${
mobileMenuOpen
? 'bg-[#FAF8F5] border-b border-slate-200/90 shadow-sm'
? 'bg-[#FAF8F5] border-b border-slate-200/90 shadow-2xs'
: isHeroTransparent
? 'bg-transparent border-b border-transparent py-2 sm:py-3'
: 'bg-[#FAF8F5]/92 backdrop-blur-md border-b border-slate-200/80 shadow-sm py-2 sm:py-2.5'
? 'bg-transparent border-b border-transparent py-2.5 sm:py-3.5'
: 'bg-[#FAF8F5]/96 border-b border-slate-200/80 shadow-2xs py-2 sm:py-2.5'
}`}
>
<div className="max-w-[1640px] mx-auto px-4 sm:px-6 lg:px-10 flex items-center justify-between">