
page-transition-animation
This skill should be used when the user asks to "animate page or route transitions", "add a page transition or crossfade between views", "animate route changes in Next.js App Router", "use the View Transitions API", "AnimatePresence exit doesn't fire on navigation", or "Framer Motion exit animation not working / exit animation before unmount in Next.js". Covers enter/exit page-transition animation with the View Transitions API and Framer Motion, for Next.js App Router and general SPA routing.
- Installs
- 2.4K
- Last 24h
- +56
- Trending rank
- #3119
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/iart-ai/web-animation-skills --skill page-transition-animation- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads page-transition-animation automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Page Transition Animation (Next.js App Router)
Implement page enter/exit transitions in the Next.js App Router, and fix the single most common failure: Framer Motion AnimatePresence exit animations never fire on navigation. The reason is structural — in the App Router, when navigating, Next.js unmounts the old route's content and mounts the new one almost immediately. AnimatePresence can only animate an exit if the exiting element stays mounted under a persistent AnimatePresence wrapper long enough to run the animation. Because the router swaps children out from under it, the exit is skipped. Two approaches solve this: a pathname-keyed AnimatePresence with the FrozenRouter pattern, or the View Transitions API (native / next-view-transitions).
When to use
Use when adding animated page transitions in a Next.js App Router app, when a Framer Motion exit prop does nothing on route change, when an old page disappears instantly instead of animating out, when choosing between Framer Motion and the View Transitions API for Next.js, or when debugging why AnimatePresence won't animate between routes.
Why exit doesn't fire (the core problem)
AnimatePresence detects removal of a direct keyed child. On App Router navigation:
- The wrapper must persist across the navigation. If
AnimatePresencelives in a component that itself unmounts, there is nothing left to run the exit. - The child's
keymust change per route so AnimatePresence sees "old removed, new added". - During the brief overlap, the outgoing subtree must still render its old content — but the App Router has already swapped the route context, so the outgoing tree would otherwise render the new page's data. This is what FrozenRouter fixes.
Solution A: template.tsx + keyed AnimatePresence + FrozenRouter
template.tsx is the App Router's purpose-built hook for this: unlike layout.tsx (which persists), a template remounts on every navigation, giving each route a fresh instance — ideal for per-route enter animations. Combine it with a pathname-keyed AnimatePresence and FrozenRouter for clean exit + enter.
// app/template.tsx
'use client';
import { AnimatePresence } from 'framer-motion';
import { usePathname } from 'next/navigation';
import { FrozenRouter } from './frozen-router';
import { PageTransition } from './page-transition';
export default function Template({ children }: { children: React.ReactNode }) {
const pathname = usePathname();
return (
<AnimatePresence mode="wait" initial={false}>
{/* key on pathname so AnimatePresence sees old removed / new added */}
<PageTransition key={pathname}>
{/* FrozenRouter keeps the OUTGOING tree rendering its old content
while it animates out */}
<FrozenRouter>{children}</FrozenRouter>
</PageTransition>
</AnimatePresence>
);
}
// app/page-transition.tsx
'use client';
import { motion } from 'framer-motion';
export function PageTransition({ children }: { children: React.ReactNode }) {
return (
<motion.div
initial={{ opacity: 0, y: 12 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -12 }}
transition={{ duration: 0.3, ease: [0.22, 1, 0.36, 1] }}
>
{children}
</motion.div>
);
}
// app/frozen-router.tsx
'use client';
import { useContext, useRef } from 'react';
import {
LayoutRouterContext,
} from 'next/dist/shared/lib/app-router-context.shared-runtime';
// Freezes the router context so the exiting page keeps rendering its
// OWN content during the exit animation instead of the next route's.
export function FrozenRouter({ children }: { children: React.ReactNode }) {
const context = useContext(LayoutRouterContext ?? {});
const frozen = useRef(context).current;
return (
<LayoutRouterContext.Provider value={frozen}>
{children}
</LayoutRouterContext.Provider>
);
}
How it fits together:
mode="wait"makes AnimatePresence fully finish the exit before mounting the new page. (Use the default mode if enter/exit should overlap/crossfade.)initial={false}skips the enter animation on first load (optional).key={pathname}is what makes AnimatePresence treat each route as a distinct presence.FrozenRoutersnapshotsLayoutRouterContextso the outgoing subtree renders the previous route's content throughout the exit, instead of flashing the new route's content. Without it, exit either skips or shows the wrong content.
Note: LayoutRouterContext is a Next.js internal; its import path can change between Next versions. If the import breaks after an upgrade, that path is the thing to update.
Solution B: native View Transitions API
The View Transitions API animates between two DOM states with the browser capturing before/after snapshots — no per-element exit components.
/* globals.css */
@view-transition { navigation: auto; } /* opt MPA-style in (where supported) */
::view-transition-old(root) { animation: fade 0.25s both reverse; }
::view-transition-new(root) { animation: fade 0.25s both; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
For SPA-style App Router navigations, wrap the router update:
if (document.startViewTransition) {
document.startViewTransition(() => router.push(href));
} else {
router.push(href);
}
next-view-transitions library
next-view-transitions integrates the View Transitions API with the App Router's client navigation so it works out of the box:
// app/layout.tsx
import { ViewTransitions } from 'next-view-transitions';
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<ViewTransitions>
<html lang="en"><body>{children}</body></html>
</ViewTransitions>
);
}
// use the library's Link instead of next/link
import { Link } from 'next-view-transitions';
<Link href="/about">About</Link>;
Choose View Transitions for simple cross-page fades/morphs and shared-element transitions with minimal JS; choose Framer Motion when fine-grained, orchestrated, interruptible, or staggered exit animations are needed. View Transitions API browser support is still uneven, so provide a graceful fallback (the if (document.startViewTransition) guard).
AnimatePresence debug checklist
When exit still won't fire, verify in order:
- Wrapper stays mounted.
AnimatePresencemust live in something persistent — ideallytemplate.tsx, or a layout-level client component — not inside the page that's unmounting. - Stable, changing key. The animated child needs
key={pathname}(or similar) so removal is detected. No key, or a key that doesn't change → no exit. - Direct motion descendant. The element with the
exitprop must be amotion.*component and a child ofAnimatePresence(a non-motion wrapper in between can block detection). mode="wait"if old and new should not overlap; without it both render simultaneously and may jump.- FrozenRouter present if the outgoing page flashes the new route's content during exit.
'use client'on every file using AnimatePresence/usePathname/motion.- Single child at a time under
mode="wait"— AnimatePresence expects one keyed presence to swap.
Deliver & verify (standalone HTML)
Packaged helper (
scripts/):scripts/seek-shot.sh anim.html 0 1.5 3freezes the?t=Nharness and screenshots each moment;scripts/contact-sheet.sh sheet.png frame-*.pngtiles them for one-glance review. Seescripts/README.md.
The real target is a Next.js app, but to prove the transition shape (the enter/exit curve, direction, crossfade) you can ship one HTML file that opens directly in a browser — two stub "pages" you toggle, animated with motion from CDN or the native View Transitions API. One file is the right tier for validating motion before wiring the router; don't stand up Next just to eyeball a fade.
Output contract:
- One
.htmlfile: two view stubs and a toggle, animated with either an inline<script type="module">importingmotion/React from CDN, ordocument.startViewTransition+::view-transition-*CSS. - A way to freeze the resolved end state — a route transition is state-driven (which view, mid-swap), so screenshot the state, not a clock.
Seek harness — pin a transition phase. ?view=b mounts the destination view (or ?phase=exit to hold the outgoing tree mid-animation) so a screenshot lands on a settled phase:
<script>
const p = new URLSearchParams(location.search);
document.documentElement.dataset.view = p.get("view") || "a"; // CSS/React keys off this
// Framer Motion: set the controlled key/route from ?view; for mode="wait" the resolved end is the new page
// View Transitions: screenshot the END state (snapshots are transient); or pause via emulate slow animations
window.__ready = true;
</script>
Verify loop — render → set phase → screenshot → check: open source, mid, and destination (?view=a, ?phase=exit, ?view=b), screenshot each, and check fidelity (exit actually runs, direction/crossfade matches the brief, no mode="wait" lag) plus artifacts (outgoing tree flashing the new page's content, double-mount, FOUC, jank). Any headless tool works:
npx playwright screenshot --wait-for-timeout=500 "file://$PWD/transition.html?view=b" dest.png
Before you finish:
- Opens standalone — no console errors, CDN
motion/React (if used) resolves,startViewTransitionguarded. - The
?view=/?phase=freeze lands a deterministic transition phase. - Screenshotted at source / mid / destination — matches the brief, no content flash or skipped exit.
prefers-reduced-motionhonored — slide/translate dropped to a short crossfade.- Easing is intentional — entrances ease-out, exits ease-in, durations ~0.2–0.4s (not laggy under
mode="wait").
Quick reference
| Need | Approach |
|---|---|
| Per-route enter animation | app/template.tsx (remounts each nav) |
| Exit animation on nav | keyed AnimatePresence mode="wait" + FrozenRouter |
| Outgoing page shows old content | FrozenRouter (snapshot LayoutRouterContext) |
| Detect route change | usePathname() as the key |
| Simple cross-page fade/morph | View Transitions API / next-view-transitions |
| Shared element transition | view-transition-name CSS |
| Skip first-load animation | initial={false} |
Gotchas
layout.tsxpersists and will NOT remount per route — usetemplate.tsxfor per-route enter animations.- Omitting FrozenRouter makes the exiting page render the new route's content mid-animation (visible flash) or skip exit entirely.
LayoutRouterContextimport path is a Next internal; it may change across versions — first thing to fix after an upgrade.- Without
key={pathname}, AnimatePresence sees the same child and never triggers exit. mode="wait"waits for exit before enter; overusing it on slow exits makes navigation feel laggy — tune durations (~0.2-0.4s).- View Transitions API lacks full browser support; always guard
document.startViewTransition. - Every transition file needs
'use client'; server components can't use AnimatePresence/usePathname.
Reference files
references/full-examples.md— directional/slide transitions, shared-element View Transitions withview-transition-name, a non-mode="wait"crossfade variant, loading-state transitions withloading.tsx, and a complete working App Router folder layout.
FAQ
What does the page-transition-animation skill do?
This skill should be used when the user asks to "animate page or route transitions", "add a page transition or crossfade between views", "animate route changes in Next.js App Router", "use the View Transitions API", "AnimatePresence exit doesn't fire on navigation", or "Framer Motion exit animation not working / exit animation before unmount in Next.js". Covers enter/exit page-transition animation with the View Transitions API and Framer Motion, for Next.js App Router and general SPA routing.
How do I install page-transition-animation?
Run npx skills add https://github.com/iart-ai/web-animation-skills --skill page-transition-animation in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/page-transition-animation/ (personal) or .claude/skills/page-transition-animation/ (project).
Which AI agents can use page-transition-animation?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is page-transition-animation safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains page-transition-animation?
It is published by iart-ai in iart-ai/web-animation-skills. It has 2,383 recorded installs.
More from iart-ai/web-animation-skills
accessible-animation
iart-ai/web-animation-skills
This skill should be used when the user asks to "respect prefers-reduced-motion", "honor reduced motion", "make my animations accessible", "fix vestibular / motion-sickness issues", "add a useReducedMotion hook", "gate GSAP / Framer Motion / Lenis for reduced motion", or "meet WCAG 2.3.3 / C39". Provides tiered (not all-or-nothing) reduced-motion patterns in CSS and JS.
60fps-animation
iart-ai/web-animation-skills
This skill should be used when the user asks to "fix janky CSS animation", "make animation 60fps", "stop layout thrashing", "animate width/height/top/left smoothly", "convert animation to transform", "animate box-shadow performantly", "animate height auto", "FLIP animation", or "why is my scroll/hover animation choppy".
svg-animation
iart-ai/web-animation-skills
This skill should be used when the user asks to "animate an SVG", "make a line draw itself on", "do a stroke draw-on / signature animation", "morph one shape into another", "move an element along a path", "animate an icon/logo", or "animate an SVG gradient or filter". Covers stroke-dashoffset draw-on, path morphing, motion-along-path, and animated icons/gradients/filters via CSS, SMIL, and GSAP.
micro-interaction
iart-ai/web-animation-skills
This skill should be used when the user asks to "add a hover/press effect", "animate a toggle or switch", "build an animated like button", "make a toast/snackbar slide in", "animate a drawer or modal", "animate list reordering or add/remove", "do a shared-element layout transition", or "polish UI feedback". Covers UI motion with Framer Motion (motion/react) and modern CSS.
gsap-web
iart-ai/web-animation-skills
This skill should be used when the user asks to "build a scroll animation", "add ScrollTrigger", "pin a section while scrolling", "scrub an animation to scroll", "create a hero timeline", "do a horizontal scroll section", "split text and animate words", "animate a layout change with GSAP Flip", "sync ScrollTrigger with Lenis", "Lenis smooth scroll jittery", "ScrollTrigger markers drift", "ScrollTrigger pins break with Lenis/Locomotive", or "set up smooth scroll with GSAP pinning". Covers GSAP timelines, ScrollTrigger, SplitText, Flip, and Lenis/Locomotive smooth-scroll sync for code-driven web motion.
glassmorphism
iart-ai/web-animation-skills
This skill should be used when the user asks to "add a glassmorphism effect", "frosted glass UI", "Apple liquid glass style", "frosted blur card", "translucent glass panel animation", "make a frosted nav bar", "build a glass modal/dialog", "animate a glass card on hover", or "add a refracting liquid-glass hero". Covers frosted translucent panels with backdrop-filter blur, edge/specular highlights, SVG liquid-glass refraction, motion on hover/scroll/enter, and accessible reduced-transparency fallbacks.
Popular frontend & design skills
setup-matt-pocock-skills
mattpocock/skills
Configure this repo for the engineering skills: set up its issue tracker, triage label vocabulary, and domain doc layout. Run once before first use of the other engineering skills.
frontend-design
anthropics/skills
Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.
hyperframes-animation
heygen-com/hyperframes
All animation knowledge for HyperFrames — atomic motion rules, multi-phase scene blueprints, scene transitions, broader motion-design techniques, AND the seven runtime adapters (GSAP default, plus Lottie, Three.js, Anime.js, CSS keyframes, Web Animations API, TypeGPU). Use for any motion or animation task: pick 2-4 rules and compose, or load a blueprint, or look up runtime-specific API (e.g. GSAP eases / Lottie player / Three.js mixer). Also covers auditing an existing composition's choreography (animation map) and 24 named text-animation effects. HyperFrames-native: single paused timeline, seek-safe, deterministic.
prototype
mattpocock/skills
Build a throwaway prototype to answer a design question. Use when the user wants to sanity-check whether a state model or logic feels right, or explore what a UI should look like.
hyperframes-core
heygen-com/hyperframes
The HyperFrames composition contract — build one renderable project. Use for composition structure, the data- timing attributes, class="clip", tracks, sub-compositions, variables, framework-owned media playback, deterministic-render rules, and validation. Read before writing composition HTML.
vercel-react-best-practices
vercel-labs/agent-skills
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.