fix(mobile): resolve mobile touch runtime errors, webgl transmission GPU stall and add root icon

This commit is contained in:
2026-11-05 11:42:47 +05:30
parent d20f98cb36
commit 35a615f4ea
4 changed files with 184 additions and 76 deletions
+50 -36
View File
@@ -25,49 +25,63 @@ export function SmoothScrollProvider({ children }: SmoothScrollProviderProps) {
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
if (prefersReducedMotion) return;
// Initialize ultra-lightweight Lenis instance
const lenis = new Lenis({
duration: 1.15,
easing: (t: number) => Math.min(1, 1.001 - Math.pow(2, -10 * t)), // Silky exponential ease-out
orientation: 'vertical',
gestureOrientation: 'vertical',
smoothWheel: true,
wheelMultiplier: 0.95,
touchMultiplier: 1.25,
infinite: false,
});
// Expose lenis instance globally for programmatic scrolling
(window as any).__lenis = lenis;
// Locked high-frequency RAF loop
let lenis: Lenis | null = null;
let animId = 0;
const raf = (time: number) => {
lenis.raf(time);
try {
// Initialize ultra-lightweight Lenis instance
lenis = new Lenis({
duration: 1.15,
easing: (t: number) => Math.min(1, 1.001 - Math.pow(2, -10 * t)), // Silky exponential ease-out
orientation: 'vertical',
gestureOrientation: 'vertical',
smoothWheel: true,
syncTouch: false, // Preserves native 120Hz iOS/Android touch momentum without interference
wheelMultiplier: 0.95,
touchMultiplier: 1.0,
infinite: false,
});
// Expose lenis instance globally for programmatic scrolling
(window as any).__lenis = lenis;
// Locked high-frequency RAF loop
const raf = (time: number) => {
lenis?.raf(time);
animId = requestAnimationFrame(raf);
};
animId = requestAnimationFrame(raf);
};
animId = requestAnimationFrame(raf);
} catch {
// Fallback silently to native smooth scrolling
}
// Intercept in-page anchor links for seamless animated scrolling
// Intercept in-page anchor links for seamless animated scrolling (safe on text nodes on mobile)
const handleAnchorClick = (e: MouseEvent) => {
const target = e.target as HTMLElement | null;
if (!target) return;
const anchor = target.closest('a[href^="#"]') as HTMLAnchorElement | null;
if (!anchor) return;
const href = anchor.getAttribute('href');
if (!href || href === '#' || href === '#!') return;
try {
const target = e.target as Node | null;
if (!target) return;
const element = (target instanceof Element ? target : target.parentElement) as HTMLElement | null;
if (!element || typeof element.closest !== 'function') return;
const anchor = element.closest('a[href^="#"]') as HTMLAnchorElement | null;
if (!anchor) return;
const href = anchor.getAttribute('href');
if (!href || href === '#' || href === '#!') return;
const targetElement = document.querySelector(href);
if (targetElement) {
e.preventDefault();
lenis.scrollTo(targetElement as HTMLElement, {
offset: -80, // Offset for floating glass navbar
duration: 1.25,
easing: (t: number) => Math.min(1, 1.001 - Math.pow(2, -10 * t)),
});
if (lenis) {
lenis.scrollTo(targetElement as HTMLElement, {
offset: -80, // Offset for floating glass navbar
duration: 1.25,
easing: (t: number) => Math.min(1, 1.001 - Math.pow(2, -10 * t)),
});
} else {
targetElement.scrollIntoView({ behavior: 'smooth' });
}
}
} catch {
// Fallback gracefully to default navigation if querySelector fails
@@ -79,7 +93,7 @@ export function SmoothScrollProvider({ children }: SmoothScrollProviderProps) {
return () => {
cancelAnimationFrame(animId);
document.removeEventListener('click', handleAnchorClick, { capture: true });
lenis.destroy();
lenis?.destroy();
delete (window as any).__lenis;
};
}, []);