{"slug": "how-i-built-a-3d-scroll-portfolio-with-astro-react-three-fiber-gsap-and-lenis", "title": "How I built a 3D scroll portfolio with Astro, React Three Fiber, GSAP and Lenis", "summary": "A product designer built a 3D scroll-based portfolio using Astro, React Three Fiber, Three.js, GSAP and Lenis, hosted on Cloudflare Pages, and documented the performance work needed to hold 60 fps. Key fixes included deferring WebGL scene initialization until the page load and hero intro finish, using checkVisibility to stop rendering faded or hidden canvases, decoding gallery images off the main thread with createImageBitmap, switching Lenis to frame-rate-independent lerp, and running the rope-hung About card on a fixed-step spring simulation.", "body_md": "I'm a product designer, and my portfolio is the one project where nobody can tell me what to cut. So I built it as a scroll experience: a hero that morphs into a 3D screen, a cube that turns between case studies, an About card hanging on ropes that you can tilt, drag and stretch, and a work grid you can throw around.\n\nLive: [nishar.xyz](https://nishar.xyz)\n\nIt is built with Astro for the pages, React islands with React Three Fiber and Three.js for the 3D, GSAP (ScrollTrigger, Draggable, Inertia) and Lenis for motion, and Tailwind for layout. It is hosted on Cloudflare Pages. I designed it in Figma first, then built it with AI-assisted development (Claude Code, Codex and Cursor) so I could test how it felt in the browser instead of guessing from a prototype.\n\nMaking it look right was the easy part. Making it *feel* right at 60 fps took much longer. These are the problems that cost me the most time.\n\nIf every Three.js scene starts at page load, shader compilation and texture uploads land at exactly the moment the hero intro plays, and the intro stutters.\n\nThe fix was a small gate. WebGL scenes wait until the page has loaded, the hero intro has had time to play (about 2.6 seconds), and the main thread is idle:\n\n``` js\nexport const whenIdle: Promise<void> = new Promise((resolve) => {\n  const settle = () =>\n    setTimeout(\n      () => ('requestIdleCallback' in window\n        ? requestIdleCallback(() => resolve(), { timeout: 3000 })\n        : resolve()),\n      3000\n    );\n  if (document.readyState === 'complete') settle();\n  else addEventListener('load', settle, { once: true });\n});\n```\n\nEvery heavy scene awaits `whenIdle` before it starts. Nothing visual changed, but the first seconds stopped competing with the 3D.\n\nI paused scenes with `IntersectionObserver`, but that only tells you whether an element is inside the viewport. A canvas that GSAP has faded to `opacity: 0`, or that sits in a hidden chapter, still counts as intersecting, so it kept rendering for nothing.\n\nI wrote a `paintGate` that asks whether the element can actually be seen right now, using `checkVisibility`:\n\n```\npainted = el.checkVisibility({ opacityProperty: true, visibilityProperty: true });\n```\n\nEach render loop calls it every frame, but the style check itself runs at most every 100 ms, so it is cheap. Layers that are faded out or hidden now stop rendering entirely.\n\nThe work grid is a WebGL gallery. Chrome decodes an `<img>` synchronously on the main thread when you upload it to WebGL, which costs roughly 10 to 30 ms per image, and the galleries load several at once. That adds up to dropped frames.\n\nThe fix has two parts:\n\n`fetch` and `createImageBitmap(blob)`, and resize during the decode.\nIf `createImageBitmap` isn't available, the code falls back to a plain `<img>`.\n\nI started with Lenis using a fixed duration of 1.8 seconds, which looks silky in a demo but makes the page trail behind the wheel.\n\nI switched to Lenis's frame-rate-independent `lerp` (0.11). Each wheel tick now moves the page immediately and it settles in about 0.6 seconds, so the page follows the hand instead of trailing it. Lenis is driven by the GSAP ticker so ScrollTrigger and the smooth scroll stay on the same clock, and touch scrolling is left native on phones.\n\nThe About card hangs from four ropes. If the physics is tied to frame rate, it feels different on a 60 Hz laptop and a 120 Hz display. I used a fixed-step spring simulation (1/120 second per step) that has no DOM, renderer or frame-rate-dependent interpolation, so the same drag gives the same stretch everywhere.\n\nOn phones I removed the tilt, drag and stretch completely. The card stays on fixed ropes and touches scroll the page, because fighting the scroll gesture on a phone is a bad trade for a fun effect.\n\n`prefers-reduced-motion`. Smooth scroll is switched off for those users.\nBuild the motion you love, then budget as much time for performance as for the design. The visible effects are the easy part. The hard part is making sure they don't cost more than the user can feel.\n\nIf you try the site, I'd like feedback on how it performs on your device: [nishar.xyz](https://nishar.xyz).", "url": "https://wpnews.pro/news/how-i-built-a-3d-scroll-portfolio-with-astro-react-three-fiber-gsap-and-lenis", "canonical_source": "https://dev.to/nishar_multani/how-i-built-a-3d-scroll-portfolio-with-astro-react-three-fiber-gsap-and-lenis-1j06", "published_at": "2026-11-26 12:05:32+00:00", "updated_at": "2026-11-26 12:14:12.191601+00:00", "lang": "en", "topics": ["developer-tools"], "entities": ["Astro", "React Three Fiber", "Three.js", "GSAP", "Lenis", "Cloudflare Pages", "Figma", "Claude Code"], "also_reported_by": [], "takeaway": "Deferring WebGL scene startup until load plus a ~2.6-second intro delay, gating render loops on checkVisibility, and decoding gallery images with createImageBitmap off the main thread eliminated the stutter and dropped frames in a 3D scroll portfolio.", "recommendation": {"advice": "Gate heavy WebGL scenes behind a load-and-idle promise and pause render loops with checkVisibility rather than IntersectionObserver alone, since faded or hidden canvases still count as intersecting.", "playbook": "production-ops", "playbook_url": "https://wpnews.pro/playbooks/production-ops"}, "alternates": {"html": "https://wpnews.pro/news/how-i-built-a-3d-scroll-portfolio-with-astro-react-three-fiber-gsap-and-lenis", "markdown": "https://wpnews.pro/news/how-i-built-a-3d-scroll-portfolio-with-astro-react-three-fiber-gsap-and-lenis.md", "text": "https://wpnews.pro/news/how-i-built-a-3d-scroll-portfolio-with-astro-react-three-fiber-gsap-and-lenis.txt", "jsonld": "https://wpnews.pro/news/how-i-built-a-3d-scroll-portfolio-with-astro-react-three-fiber-gsap-and-lenis.jsonld"}}