gsap-in-react

A React coding rule for GSAP, a JavaScript animation library, when preserving animations from a Webflow export. It places animation setup in React's effect lifecycle and cleans it up when the component is removed.

In plain words
What is it for?
Use it when moving Webflow GSAP animations into React components, including animations that use ScrollTrigger or SplitText.
Why use it?
It keeps animations scoped to the intended component and prevents leftover animations, scroll triggers, or styles from accumulating.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/dmenchaca/webflow-to-react/gsap-in-react
Clone the repo
git clone --depth 1 https://github.com/dmenchaca/webflow-to-react
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 901 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00901
Opus 5 $0.00000 $0.00451
Sonnet 5 $0.00000 $0.00180
Haiku 4.5 $0.00000 $0.00090

Measured 2d ago against content hash dbfd04a6a87f, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

gsap-in-react scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

rules/gsap-in-react.mdc · 93 lines

How it starts

The opening of the file, as written. The whole thing — 93 lines — stays where its author put it; the contents beside it link to each section on GitHub.

GSAP in React (keep the Webflow animations intact)

This project migrated from a Webflow export that uses GSAP (and sometimes ScrollTrigger/SplitText). The migration strategy is: keep those animations as-is, just wrap initialization in React's lifecycle. Do NOT rewrite them in Framer Motion.

Core pattern: gsap.context() inside useEffect

import { useEffect, useRef } from 'react'
import gsap from 'gsap'

export function HeroSection() {
  const scopeRef = useRef<HTMLDivElement>(null)

  useEffect(() => {
    const ctx = gsap.context(() => {
      gsap.from('.hero-title', { y: 40, opacity: 0, duration: 1 })
      gsap.to('.hero-cta', { scale: 1.05, yoyo: true, repeat: -1 })
    }, scopeRef)

    return () => ctx.revert()
  }, [])

  return <div ref={scopeRef}>…</div>
}

Why gsap.context():

  • Scopes selectors to scopeRef so .hero-title doesn't match elsewhere on the page.
  • ctx.revert() kills every tween, removes every ScrollTrigger, and restores inline styles on unmount. One line, no leaks.
  • Safe under React 19 StrictMode's double-effect invocation (revert undoes the first run cleanly).

ScrollTrigger

import { useEffect, useRef } from 'react'
import gsap from 'gsap'
import ScrollTrigger from 'gsap/ScrollTrigger'

gsap.registerPlugin(ScrollTrigger)

export function Section() {
  const ref = useRef<HTMLDivElement>(null)
  useEffect(() => {
    const ctx = gsap.context(() => {
      gsap.from('.reveal', {
        y: 60, opacity: 0, duration: 0.8,
        scrollTrigger: { trigger: '.reveal', start: 'top 80%' },
      })
    }, ref)
    return () => ctx.revert()
  }, [])
  return <div ref={ref}>…</div>
}

After route changes, async content loads, or layout shifts, call ScrollTrigger.refresh().

Rules

Do

  • Initialize GSAP inside useEffect, never during render.
  • Use gsap.context(fn, scopeRef) so selectors are scoped and cleanup is one call.
  • Return () => ctx.revert() from every effect that touches GSAP.
  • Register plugins once at module scope: gsap.registerPlugin(ScrollTrigger).
  • For reusable global animations (hero reveals, marquee), consider a hook: useHeroAnimations(containerRef) wired in MarketingSiteRoot.

Read the full file on GitHub · 93 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 93 lines · 0 tokens per session scan A dbfd04a6a87f

Subscribe to this mod's changes

gsap-in-react is a cursor rule published in the GitHub repository dmenchaca/webflow-to-react (27 stars, last pushed 2mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 901 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.