agentleFS
Leo-AtienzaLeo-Atienza/atlas-claude/skills/_archived/barba-js/SKILL.md

barba-js

Skill4 starsChanged 4 months agoMITView on GitHub

Use Barba.js for Layer 0 in the Cinematic Web Engine (SK-096): smooth page transitions in Multi-Page Architecture (MPA) sites. Barba.js intercepts link clicks, fetches the next page via XHR, and swaps a container element — creating SPA-like transitions on traditional server-rendered sites. CRITICAL: Barba.js is MPA-only. It is NOT compatible with: - Next.js (App Router or Pages Router) - React SPAs (React Router, TanStack Router) - Any client-side routed framework For SPAs/Next.js, use instead: - <ViewTransition> component (React 19+ /…

  • Installs packages

3 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 8

    Very specific

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

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

    Use Barba.js for Layer 0 in the Cinematic Web Engine (SK-096): smooth page transitions in Multi-Page Architecture (MPA) sites.

    line 13
  2. Very specific:

    All hooks receive { current, next, trigger } data object.

    line 293
  3. Very specific:

    Always kill ScrollTriggers and GSAP tweens in leave or beforeLeave

    line 320
  4. Very specific:

    Always reset scroll position in afterEnter (window.scrollTo(0, 0))

    line 321
  5. Distinctive:

    Always destroy and recreate Lenis on page transition

    line 322
  6. Very specific:

    Use @barba/prefetch for perceived performance improvement

    line 323
  7. Distinctive:

    Keep transitions under 800ms total — users notice delays beyond this

    line 324
  8. Very specific:

    Use data-barba-prevent on download links, external links, and auth pages

    line 325
  9. Very specific:

    Use Barba.js in a React/Next.js/SPA project — use ViewTransition API instead

    line 329
  10. Very specific:

    Use both leave and once transitions without testing the initial page load

    line 333

“Common” is measured: kept by at least 6 in 10 of the 3 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
<!-- id: SK-094 name: barba-js description: Barba.js page transitions — MPA smooth transitions, GSAP orchestration, view lifecycle, prefetch, cross-page animation choreography keywords: barba, page-transition, mpa, smooth-transition, view-lifecycle, prefetch, cross-page, pjax, history-api, leave-enter version: 1.0.0 -->

Barba.js Page Transitions

When to Use This Skill

Use Barba.js for Layer 0 in the Cinematic Web Engine (SK-096): smooth page transitions in Multi-Page Architecture (MPA) sites. Barba.js intercepts link clicks, fetches the next page via XHR, and swaps a container element — creating SPA-like transitions on traditional server-rendered sites.

CRITICAL: Barba.js is MPA-only. It is NOT compatible with:

  • Next.js (App Router or Pages Router)
  • React SPAs (React Router, TanStack Router)
  • Any client-side routed framework

For SPAs/Next.js, use instead:

  • <ViewTransition> component (React 19+ / Next.js 15+) — see SK-054
  • Motion AnimatePresence — see SK-047
  • View Transitions API (native browser) — see SK-054

Good fit for: Static sites (Astro, 11ty, Hugo), WordPress, PHP sites, vanilla HTML/JS sites, agency portfolio sites.

Installation

npm install @barba/core @barba/prefetch

Optional: @barba/css for CSS-only transitions (no JS needed).

Core Concepts

<!-- Required DOM structure -->
<body>
  <!-- Wrapper: persists across pages -->
  <div data-barba="wrapper">
    <nav><!-- Navigation persists --></nav>

    <!-- Container: gets swapped on transition -->
    <main data-barba="container" data-barba-namespace="home">
      <!-- Page content -->
    </main>
  </div>
</body>
  • Wrapper (data-barba="wrapper"): The persistent outer element. Never animated.
  • Container (data-barba="container"): The content that gets swapped. This is what you animate.
  • Namespace (data-barba-namespace): Identifies the page type for per-page transitions.

Basic Setup

import barba from '@barba/core';

barba.init({
  transitions: [{
    leave({ current }) {
      // Animate current page out — return a Promise or GSAP timeline
      return gsap.to(current.container, { opacity: 0, duration: 0.5 });
    },
    enter({ next }) {
      // Animate next page in
      return gsap.from(next.container, { opacity: 0, duration: 0.5 });
    },
  }],
});

GSAP Orchestration (Primary Pattern)

The canonical pattern: return GSAP timelines from Barba hooks.

import barba from '@barba/core';
import gsap from 'gsap';
import { ScrollTrigger } from 'gsap/ScrollTrigger';

gsap.registerPlugin(ScrollTrigger);

barba.init({
  transitions: [{
    name: 'fade-slide',

    leave({ current }) {
      // 1. Kill all ScrollTriggers before page leaves
      ScrollTrigger.getAll().forEach(t => t.kill());

      // 2. Animate out — return timeline (Barba waits for it)
      const tl = gsap.timeline();
      tl.to(current.container, { opacity: 0, y: -30, duration: 0.4, ease: 'power2.in' });
      return tl;
    },

    enter({ next }) {
      // 3. Animate in
      const tl = gsap.timeline();
      tl.from(next.container, { opacity: 0, y: 30, duration: 0.6, ease: 'power3.out' });
      return tl;
    },

    afterEnter() {
      // 4. Re-initialize page-specific animations
      window.scrollTo(0, 0);
      ScrollTrigger.refresh();
    },
  }],
});

Critical: ScrollTrigger Cleanup

Always kill ScrollTriggers on page leave. Stale triggers from the previous page will cause layout issues and memory leaks.

leave({ current }) {
  // Kill ALL ScrollTriggers
  ScrollTrigger.getAll().forEach(t => t.kill());
  // Kill all GSAP tweens
  gsap.killTweensOf('*');
  return gsap.to(current.container, { opacity: 0, duration: 0.4 });
},

Lenis Integration

Destroy and recreate Lenis on each page transition:

import Lenis from 'lenis';

let lenis;

function initLenis() {
  lenis = new Lenis();
  lenis.on('scroll', ScrollTrigger.update);
  gsap.ticker.add((time) => lenis.raf(time * 1000));
  gsap.ticker.lagSmoothing(0);
}

barba.init({
  transitions: [{
    leave({ current }) {
      // Destroy Lenis before page leave
      lenis?.destroy();
      ScrollTrigger.getAll().forEach(t => t.kill());
      return gsap.to(current.container, { opacity: 0, duration: 0.4 });
    },
    afterEnter() {
      // Recreate Lenis for new page
      window.scrollTo(0, 0);
      initLenis();
      // Initialize page-specific animations here
    },
  }],
});

// Initial page load
initLenis();

Named Transitions

Route-specific transitions using from/to namespace rules:

barba.init({
  transitions: [
    {
      name: 'home-to-project',
      from: { namespace: ['home'] },
      to: { namespace: ['project'] },
      leave({ current }) {
        return gsap.timeline()
          .to('.grid-item', { scale: 0.8, opacity: 0, stagger: 0.05 })
          .to(current.container, { opacity: 0 }, '-=0.2');
      },
      enter({ next }) {
        return gsap.timeline()
          .from(next.container, { opacity: 0 })
          .from('.project-hero', { y: 100, opacity: 0, duration: 0.8 }, '-=0.3');
      },
    },
    {
      name: 'default',
      // Fallback for all other routes
      leave({ current }) {
        return gsap.to(current.container, { opacity: 0, duration: 0.3 });
      },
      enter({ next }) {
        return gsap.from(next.container, { opacity: 0, duration: 0.3 });
      },
    },
  ],
});

View Lifecycle

Per-page initialization using views:

barba.init({
  views: [
    {
      namespace: 'home',
      beforeEnter() {
        // Runs before enter transition
      },
      afterEnter() {
        // Initialize home-specific JS (carousels, scroll animations, etc.)
        initHomeAnimations();
      },
      beforeLeave() {
        // Cleanup before leaving home
        destroyHomeAnimations();
      },
    },
    {
      namespace: 'about',
      afterEnter() {
        initAboutAnimations();
      },
    },
  ],
  transitions: [/* ... */],
});

Prefetch Plugin

Prefetch pages on link hover for near-instant transitions:

import barba from '@barba/core';
import barbaPrefetch from '@barba/prefetch';

barba.use(barbaPrefetch);

barba.init({
  // prefetch is now active — pages are fetched on hover
  transitions: [/* ... */],
});

CSS Transitions (No JS)

For simple transitions without JavaScript:

import barba from '@barba/core';
import barbaCss from '@barba/css';

barba.use(barbaCss);

barba.init({
  transitions: [{
    name: 'fade',
    // CSS classes are automatically added/removed:
    // .fade-leave, .fade-leave-active, .fade-leave-to
    // .fade-enter, .fade-enter-active, .fade-enter-to
  }],
});
.fade-leave-active,
.fade-enter-active {
  transition: opacity 0.5s ease;
}
.fade-leave-to,
.fade-enter {
  opacity: 0;
}

Hooks Reference

HookTimingUse For
beforeLeaveBefore leave animationCleanup, kill animations
leaveLeave animationAnimate current page out
afterLeaveAfter leave completesRemove event listeners
beforeEnterBefore enter animationPrepare next page DOM
enterEnter animationAnimate next page in
afterEnterAfter enter completesInitialize page JS, scroll reset

All hooks receive { current, next, trigger } data object.

Preventing Links

<!-- Barba ignores these -->
<a href="/file.pdf" data-barba-prevent>Download PDF</a>
<a href="/external" data-barba-prevent="self">External</a>

<!-- Entire section -->
<div data-barba-prevent="all">
  <a href="/link1">Ignored</a>
  <a href="/link2">Ignored</a>
</div>

Limitations

  • No React/Next.js/SPA compatibility — Barba manages routing, conflicts with client-side routers
  • Analytics re-firing — Must manually trigger page views in afterEnter
  • Script re-execution — Inline <script> tags in the new page don't auto-execute; use view lifecycle hooks
  • Third-party widgets — May need reinitialization (chat widgets, embeds, etc.)
  • Low maintenance — Functionally complete but last npm publish was ~2 years ago
  • Small community — ~491 GitHub stars; limited recent community content

Best Practices

  • Always kill ScrollTriggers and GSAP tweens in leave or beforeLeave
  • Always reset scroll position in afterEnter (window.scrollTo(0, 0))
  • Always destroy and recreate Lenis on page transition
  • Use @barba/prefetch for perceived performance improvement
  • Keep transitions under 800ms total — users notice delays beyond this
  • Use data-barba-prevent on download links, external links, and auth pages

Do Not

  • Use Barba.js in a React/Next.js/SPA project — use ViewTransition API instead
  • Forget to kill ScrollTriggers on page leave — causes memory leaks and broken layouts
  • Animate the wrapper element — only animate containers and their children
  • Skip afterEnter initialization — page-specific JS won't run
  • Use both leave and once transitions without testing the initial page load

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.