Zero-Re-Render Pointer Tracking via Ref Springs
When a user moves their mouse over an interactive 3D model, updating component state with setPointerPos({ x, y }) forces React to re-render the entire component tree at 60Hz to 120Hz. On mobile or budget laptops, this instantly introduces jank and frame drops.
The solution is to decouple interaction coordinates entirely from React state. We store normalized coordinates in mutable useRef values and interpolate rotation angles inside the requestAnimationFrame loop using spring damping (lerp factor 0.05). React re-renders zero times during the entire mouse tracking interaction.
Never let mousemove events touch React useState. Keep high-frequency pointer coordinates in refs and resolve them inside the animation loop.
// Update mutable target refs without triggering React reconciliation
const onPointerMove = (e: MouseEvent) => {
targetRotationX.current = ((e.clientY - rect.top) / rect.height - 0.5) * 1.8;
targetRotationY.current = ((e.clientX - rect.left) / rect.width - 0.5) * 1.8;
};Conserving GPU Energy: IntersectionObserver Pausing
A 3D canvas executing WebGL shader calculations while hidden below the viewport wastes device battery and competes for thread bandwidth during user scrolling.
By wrapping the WebGL renderer with an IntersectionObserver, we halt the animation frame request the moment the canvas leaves the screen, instantly releasing GPU draw calls.
Hardware-Accelerated Fallback for prefers-reduced-motion
Accessibility is non-negotiable in modern engineering. Users with vestibular sensitivities can suffer discomfort from rapid gyroscopic motion. We detect window.matchMedia("(prefers-reduced-motion: reduce)") and instantly freeze high-speed orbital revolutions into a calm, static geometric projection.