agentleFS
lklynelklyne/skills/react-three-fiber/SKILL.md

react-three-fiber

Skill0 starsChanged 7 months agoMITView on GitHub

React Three Fiber (R3F) — declarative Three.js for React. Use when the user is building 3D scenes with `@react-three/fiber`, working with `<Canvas>`, `useFrame`, `useThree`, `useLoader`, hits performance issues (jank, frozen shaders, GC stutter, re-renders in the render loop), or asks about R3F pitfalls, instancing, ref-based animation, or memoizing uniforms with Leva.

13 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use locomotive-scroll, aframe-webxr and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • freshtechbroSkill

    locomotive-scroll

    Comprehensive skill for Locomotive Scroll smooth scrolling library with parallax effects, viewport detection, and scroll-driven animations. Use this skill when implementing smooth scrolling experiences, creating parallax effects, building scroll-triggered animations, or developing immersive scrolling websites. Triggers on tasks involving Locomotive Scroll, smooth scrolling, parallax, scroll detection, scroll events, sticky elements, horizontal scrolling, or GSAP ScrollTrigger integration. Integrates with GSAP for advanced scroll-driven animations.

    Also in 4 projects that use this

  • freshtechbroSkill

    aframe-webxr

    Declarative web framework for building browser-based 3D, VR, and AR experiences using HTML and entity-component architecture. Use this skill when creating WebXR applications, VR experiences, AR experiences, 360-degree media viewers, or immersive web content with minimal JavaScript. Triggers on tasks involving A-Frame, WebXR, VR development, AR development, entity-component-system, declarative 3D, or HTML-based 3D scenes. Built on Three.js with accessible HTML-first approach.

    Also in 3 projects that use this

  • +10 more from freshtechbro

The file

We split this skill into the rules it gives an agent

2 rules. 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 13 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Mutate per-frame in useFrame: Update .value in place — no new objects, no setState.

    line 38
  2. Very specific:

    Memoize the Leva control schema: if it's computed from props or state, so useControls doesn't tear down and rebuild the panel.

    line 39

“Common” is measured: kept by at least 6 in 10 of the 13 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

React Three Fiber

Declarative Three.js as React components. The render loop runs outside React — useFrame fires every frame, but React reconciliation does not. Most R3F bugs and perf problems come from forgetting that boundary.

Performance pitfalls

The single most important rule: don't drive the render loop through React state. Everything below is a corollary.

  • No setState in useFrame or fast event handlers. Each setState triggers reconciliation; at 60fps you'll re-render the whole subtree 60 times per second. Mutate refs instead. Use the delta arg from useFrame for refresh-rate-independent motion.
  • Animate in useFrame (lerp/damp) or with react-spring. Both run outside React. Driving an animation through React state is the most common source of R3F jank.
  • Don't reactively subscribe components to fast-changing store state. Selector subscriptions re-render on every change. Inside useFrame, read with store.getState() directly — no subscription, no re-render.
  • Share materials and geometries. Each unique material/geometry is a shader compile and a GPU upload. Reuse them across meshes. For many similar meshes, use instancing (<instancedMesh> or drei's <Instances>).
  • Avoid remounting expensive subtrees. Toggle visible instead of conditionally rendering. Mounting recompiles materials and re-uploads geometry.
  • Hoist temp objects. Allocating a new THREE.Vector3() inside useFrame allocates 60 objects per second per call site. The GC pause shows up as periodic stutter. Hoist Vector3/Matrix4/Color outside the frame callback and reuse via .set().
  • Use useLoader for assets. Loaders cache globally by URL — calling useLoader(GLTFLoader, url) from multiple components hits the cache. For GLTF scenes you reuse heavily, prefer gltfjsx-generated components: the JSX is immutable and the underlying buffers are shared.
  • For expensive state changes, wrap in startTransition. Concurrent mode de-prioritizes the work so the render loop stays responsive while the heavy update lands on a later commit.
  • Memoize uniforms objects. A new uniforms object every render means useFrame mutates a stale reference while the material reads from a fresh one — the shader appears frozen even though uniforms.uTime.value is incrementing. useMemo it once with [] deps.

Leva + uniforms

The pattern for live-tweaking uniforms with Leva without re-rendering. All five rules below collapse to one principle: the uniforms object is mutated, never replaced.

  • Memoize the uniforms object with [] deps so the reference is stable for the lifetime of the component.
  • Drive Leva via onChange, not the return value. Mutate uniforms.*.value directly; never call setState.
  • Mutate per-frame in useFrame. Update .value in place — no new objects, no setState.
  • Memoize the Leva control schema if it's computed from props or state, so useControls doesn't tear down and rebuild the panel.
  • Reuse Color and Vector instances. color.set(hex) and vec.set(x, y, z) mutate in place; assigning a fresh instance allocates and orphans the old one.
import { useMemo } from 'react'
import { useFrame } from '@react-three/fiber'
import { useControls } from 'leva'
import * as THREE from 'three'

function Scene() {
  const uniforms = useMemo(
    () => ({
      uTime: { value: 0 },
      uColor: { value: new THREE.Color('#ff0') },
    }),
    [],
  )

  useControls({
    color: {
      value: '#ff0',
      onChange: (v: string) => uniforms.uColor.value.set(v),
    },
  })

  useFrame((_, delta) => {
    uniforms.uTime.value += delta
  })

  // ...pass `uniforms` into a ShaderMaterial
}

For heavy work triggered by a control change, debounce the onChange or push the work into useFrame via a ref — never block the Leva input thread.

Canonical sources

WebFetch these when a question reaches beyond the curated wisdom above (e.g. specific drei component APIs, post-processing, or render targets).

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.