# How I built a 3D scroll portfolio with Astro, React Three Fiber, GSAP and Lenis

> Source: <https://dev.to/nishar_multani/how-i-built-a-3d-scroll-portfolio-with-astro-react-three-fiber-gsap-and-lenis-1j06>
> Published: 2026-11-26 12:05:32+00:00

**Recommendation:** 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.
More in the playbook "Running AI in production": <https://wpnews.pro/playbooks/production-ops>

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.

Live: [nishar.xyz](https://nishar.xyz)

It 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.

Making 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.

If 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.

The 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:

``` js
export const whenIdle: Promise<void> = new Promise((resolve) => {
  const settle = () =>
    setTimeout(
      () => ('requestIdleCallback' in window
        ? requestIdleCallback(() => resolve(), { timeout: 3000 })
        : resolve()),
      3000
    );
  if (document.readyState === 'complete') settle();
  else addEventListener('load', settle, { once: true });
});
```

Every heavy scene awaits `whenIdle` before it starts. Nothing visual changed, but the first seconds stopped competing with the 3D.

I 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.

I wrote a `paintGate` that asks whether the element can actually be seen right now, using `checkVisibility`:

```
painted = el.checkVisibility({ opacityProperty: true, visibilityProperty: true });
```

Each 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.

The 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.

The fix has two parts:

`fetch` and `createImageBitmap(blob)`, and resize during the decode.
If `createImageBitmap` isn't available, the code falls back to a plain `<img>`.

I 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.

I 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.

The 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.

On 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.

`prefers-reduced-motion`. Smooth scroll is switched off for those users.
Build 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.

If you try the site, I'd like feedback on how it performs on your device: [nishar.xyz](https://nishar.xyz).
