Skip to Content
Neshel-UI
Animations (experimental)Effects

Page Transitions

The 10 effects PT01–PT10: purpose, API, options, examples, reduced motion and cost.

Experimental and not on npm

@neshel-ui/animations is a private package (0.0.0). It cannot be installed, and its API may change before a first publication. These pages document what exists in the repository.

Page transitions use the browser's View Transitions: the effects animate snapshots, never your elements. A navigation never waits for an effect — without the API, under reduced motion with an instant effect, on a hidden page or after a failure, the update simply runs. One transition runs at a time per document. Use usePageTransition() in React or startPageTransition() anywhere; with the second, wrap React updates in flushSync.

PT01 · Cross-fade

The default effect of startPageTransition, "fade", cross-fades the old and the new content. Pass scope to limit it to the part that changes; the default is the whole document.

Import
@neshel-ui/animations/page-transitions
API
startPageTransition, usePageTransition, PageTransition
Stylesheet
@neshel-ui/animations/page-transitions.css
Reduced motion
instant — the end state appears at once
Performance
The browser animates snapshots of the old and new content (View Transitions); without support the update just runs.
Preview: PT01
Preview theme: PT01
Page 1
pt01.tsx
"use client";
import "@neshel-ui/animations/page-transitions.css";
import { startPageTransition } from "@neshel-ui/animations/page-transitions";
import { Button } from "@neshel-ui/components";
import { useRef, useState } from "react";
import { flushSync } from "react-dom";

export default function PT01Example() {
  const ref = useRef<HTMLDivElement>(null);
  const [page, setPage] = useState(1);
  return (
    <div className="grid justify-items-start gap-3">
      <div
        ref={ref}
        className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground"
      >
        Page {page}
      </div>
      <Button
        onClick={() =>
          startPageTransition(() => flushSync(() => setPage(page + 1)), {
            effect: "fade",
            scope: ref.current ?? undefined,
          })
        }
      >
        Next page
      </Button>
    </div>
  );
}
Options: PageTransitionOptions

PageTransitionOptions

PageTransitionOptions
PropTypeDefaultDescription
directionNavigationDirection | "auto"——
effectPageEffect——
fallback"none" | "flip""none"Shared elements without the API: FLIP from the old box (default "none").
maxWaitnumber—ms the browser may hold rendering for the update (0–10000, default 1500).
reducedMotionReducedMotion——
scopeElement—Element whose content changes (default: the document root).
typesreadonly string[]——

PT02 · Shared element

<SharedElement> morphs two elements with the same name across an update: size and position are animated by the browser. Names must be unique on the page at each moment; a duplicate is skipped with a development warning.

Import
@neshel-ui/animations/page-transitions
API
SharedElement, registerSharedElement
Stylesheet
@neshel-ui/animations/page-transitions.css
Reduced motion
instant — the end state appears at once
Performance
The browser animates snapshots of the old and new content (View Transitions); without support the update just runs.
Preview: PT02
Preview theme: PT02
pt02.tsx
"use client";
import "@neshel-ui/animations/page-transitions.css";
import { SharedElement, usePageTransition } from "@neshel-ui/animations/page-transitions";
import { Button } from "@neshel-ui/components";
import { useState } from "react";

export default function PT02Example() {
  const [detail, setDetail] = useState(false);
  const transition = usePageTransition();
  return (
    <div className="grid justify-items-start gap-3">
      <SharedElement name="docs-photo" asChild>
        <div
          key={String(detail)}
          className={`rounded-xl bg-neshel-primary ${detail ? "h-40 w-72" : "h-16 w-24"}`}
        />
      </SharedElement>
      <Button onClick={() => transition.start(() => setDetail(!detail))}>
        {detail ? "Back to the list" : "Open the photo"}
      </Button>
    </div>
  );
}
Options: PageTransitionOptions

PageTransitionOptions

PageTransitionOptions
PropTypeDefaultDescription
directionNavigationDirection | "auto"——
effectPageEffect——
fallback"none" | "flip""none"Shared elements without the API: FLIP from the old box (default "none").
maxWaitnumber—ms the browser may hold rendering for the update (0–10000, default 1500).
reducedMotionReducedMotion——
scopeElement—Element whose content changes (default: the document root).
typesreadonly string[]——

PT03 · Slide

effect: "slide" of startPageTransition pushes the pages in the given direction. Under reduced motion it becomes a short fade, without travel.

Import
@neshel-ui/animations/page-transitions
API
startPageTransition, usePageTransition, PageTransition
Stylesheet
@neshel-ui/animations/page-transitions.css
Reduced motion
fade — opacity only, no travel
Performance
The browser animates snapshots of the old and new content (View Transitions); without support the update just runs.
Preview: PT03
Preview theme: PT03
Page 1
pt03.tsx
"use client";
import "@neshel-ui/animations/page-transitions.css";
import { startPageTransition } from "@neshel-ui/animations/page-transitions";
import { Button } from "@neshel-ui/components";
import { useRef, useState } from "react";
import { flushSync } from "react-dom";

export default function PT03Example() {
  const ref = useRef<HTMLDivElement>(null);
  const [page, setPage] = useState(1);
  const go = (step: 1 | -1) =>
    startPageTransition(() => flushSync(() => setPage(page + step)), {
      effect: "slide",
      direction: step === 1 ? "forward" : "back",
      scope: ref.current ?? undefined,
    });
  return (
    <div className="grid justify-items-start gap-3">
      <div
        ref={ref}
        className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground"
      >
        Page {page}
      </div>
      <div className="flex gap-2">
        <Button variant="outline" onClick={() => go(-1)}>
          Previous
        </Button>
        <Button onClick={() => go(1)}>Next</Button>
      </div>
    </div>
  );
}
Options: PageTransitionOptions

PageTransitionOptions

PageTransitionOptions
PropTypeDefaultDescription
directionNavigationDirection | "auto"——
effectPageEffect——
fallback"none" | "flip""none"Shared elements without the API: FLIP from the old box (default "none").
maxWaitnumber—ms the browser may hold rendering for the update (0–10000, default 1500).
reducedMotionReducedMotion——
scopeElement—Element whose content changes (default: the document root).
typesreadonly string[]——

PT04 · Navigation direction

useNavigationDirection reports forward, back, replace or unknown from the Navigation API entry indexes; URLs are never compared. trackNavigationDirection is the engine, and direction: "auto" uses its value.

Import
@neshel-ui/animations/page-transitions
API
trackNavigationDirection, useNavigationDirection
Stylesheet
@neshel-ui/animations/page-transitions.css
Reduced motion
fade — opacity only, no travel
Performance
The browser animates snapshots of the old and new content (View Transitions); without support the update just runs.
Preview: PT04
Preview theme: PT04

Last navigation: unknown (unknown)

pt04.tsx
"use client";
import "@neshel-ui/animations/page-transitions.css";
import { useNavigationDirection } from "@neshel-ui/animations/page-transitions";

export default function PT04Example() {
  const { direction, type } = useNavigationDirection();
  return (
    <p className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground">
      Last navigation: <output>{direction}</output> (<output>{type}</output>)
    </p>
  );
}

PT05 · Scale-through

effect: "scale" of startPageTransition moves through the old page into the new one. It suits drill-down navigation; under reduced motion it fades.

Import
@neshel-ui/animations/page-transitions
API
startPageTransition, usePageTransition, PageTransition
Stylesheet
@neshel-ui/animations/page-transitions.css
Reduced motion
fade — opacity only, no travel
Performance
The browser animates snapshots of the old and new content (View Transitions); without support the update just runs.
Preview: PT05
Preview theme: PT05
Page 1
pt05.tsx
"use client";
import "@neshel-ui/animations/page-transitions.css";
import { startPageTransition } from "@neshel-ui/animations/page-transitions";
import { Button } from "@neshel-ui/components";
import { useRef, useState } from "react";
import { flushSync } from "react-dom";

export default function PT05Example() {
  const ref = useRef<HTMLDivElement>(null);
  const [page, setPage] = useState(1);
  return (
    <div className="grid justify-items-start gap-3">
      <div
        ref={ref}
        className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground"
      >
        Page {page}
      </div>
      <Button
        onClick={() =>
          startPageTransition(() => flushSync(() => setPage(page + 1)), {
            effect: "scale",
            scope: ref.current ?? undefined,
          })
        }
      >
        Go through
      </Button>
    </div>
  );
}
Options: PageTransitionOptions

PageTransitionOptions

PageTransitionOptions
PropTypeDefaultDescription
directionNavigationDirection | "auto"——
effectPageEffect——
fallback"none" | "flip""none"Shared elements without the API: FLIP from the old box (default "none").
maxWaitnumber—ms the browser may hold rendering for the update (0–10000, default 1500).
reducedMotionReducedMotion——
scopeElement—Element whose content changes (default: the document root).
typesreadonly string[]——

PT06 · Curtain wipe

effect: "wipe" of startPageTransition uncovers the new page with a moving edge that follows direction. Under reduced motion the update is immediate.

Import
@neshel-ui/animations/page-transitions
API
startPageTransition, usePageTransition, PageTransition
Stylesheet
@neshel-ui/animations/page-transitions.css
Reduced motion
instant — the end state appears at once
Performance
The browser animates snapshots of the old and new content (View Transitions); without support the update just runs.
Preview: PT06
Preview theme: PT06
Page 1
pt06.tsx
"use client";
import "@neshel-ui/animations/page-transitions.css";
import { startPageTransition } from "@neshel-ui/animations/page-transitions";
import { Button } from "@neshel-ui/components";
import { useRef, useState } from "react";
import { flushSync } from "react-dom";

export default function PT06Example() {
  const ref = useRef<HTMLDivElement>(null);
  const [page, setPage] = useState(1);
  return (
    <div className="grid justify-items-start gap-3">
      <div
        ref={ref}
        className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground"
      >
        Page {page}
      </div>
      <Button
        onClick={() =>
          startPageTransition(() => flushSync(() => setPage(page + 1)), {
            effect: "wipe",
            scope: ref.current ?? undefined,
          })
        }
      >
        Wipe
      </Button>
    </div>
  );
}
Options: PageTransitionOptions

PageTransitionOptions

PageTransitionOptions
PropTypeDefaultDescription
directionNavigationDirection | "auto"——
effectPageEffect——
fallback"none" | "flip""none"Shared elements without the API: FLIP from the old box (default "none").
maxWaitnumber—ms the browser may hold rendering for the update (0–10000, default 1500).
reducedMotionReducedMotion——
scopeElement—Element whose content changes (default: the document root).
typesreadonly string[]——

PT07 · Route progress

<RouteProgress> shows an indeterminate role="progressbar" while pending, after delay (120 ms) so that fast navigations never flash, and never invents a percentage. failed shows the error state and announce adds a status message.

Import
@neshel-ui/animations/page-transitions
API
RouteProgress, createRouteProgress
Stylesheet
@neshel-ui/animations/page-transitions.css
Reduced motion
reduced — a smaller signal remains because it conveys state
Performance
The package stylesheet renders it on layers owned by the package; your element gets no transition or animation.
Preview: PT07
Preview theme: PT07
pt07.tsx
"use client";
import "@neshel-ui/animations/page-transitions.css";
import { RouteProgress } from "@neshel-ui/animations/page-transitions";
import { Button } from "@neshel-ui/components";
import { useState } from "react";

export default function PT07Example() {
  const [pending, setPending] = useState(false);
  const navigate = () => {
    setPending(true);
    setTimeout(() => setPending(false), 1500);
  };
  return (
    <div className="grid justify-items-start gap-3">
      <RouteProgress pending={pending} announce className="text-neshel-primary" />
      <Button onClick={navigate}>Slow navigation</Button>
    </div>
  );
}
Options: RouteProgressOptions

RouteProgressOptions

RouteProgressOptions
PropTypeDefaultDescription
announcebooleanfalseAnnounce completion/failure once in a status region (default false).
delaynumber—ms before the bar appears (0–2000, default 120).
labelsPartial<Record<"loading" | "loaded" | "failed", string>>——
minVisiblenumber—ms the completed/failed state stays visible (0–3000, default 300).
onTimeout() => void—Called when the watchdog cancels a navigation that never settled (the owner should clear its state).
timeoutnumber—ms after which a pending navigation is cancelled (1000–120000, default 15000).

PT08 · Persistent element

<PersistentElement> keeps an element that stays mounted, such as a player, still above the changing page. It is the same DOM node, so its state survives by itself.

Import
@neshel-ui/animations/page-transitions
API
PersistentElement, registerSharedElement
Stylesheet
@neshel-ui/animations/page-transitions.css
Reduced motion
instant — the end state appears at once
Performance
The browser animates snapshots of the old and new content (View Transitions); without support the update just runs.
Preview: PT08
Preview theme: PT08

Loading the example…

pt08.tsx
"use client";
import "@neshel-ui/animations/page-transitions.css";
import { PersistentElement, startPageTransition } from "@neshel-ui/animations/page-transitions";
import { Button } from "@neshel-ui/components";
import { useState } from "react";
import { flushSync } from "react-dom";

export default function PT08Example() {
  const [page, setPage] = useState(1);
  return (
    <div className="grid justify-items-start gap-3">
      <PersistentElement name="docs-player" asChild>
        <div className="rounded-lg bg-neshel-primary p-3 text-neshel-primary-foreground">
          Player: keeps its DOM and its state
        </div>
      </PersistentElement>
      <p className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground">
        Page {page}
      </p>
      <Button
        onClick={() =>
          startPageTransition(() => flushSync(() => setPage(page + 1)), { effect: "fade" })
        }
      >
        Change the page
      </Button>
    </div>
  );
}

PT09 · Cross-document transitions

Import the MPA stylesheet in both same-origin documents and the browser animates full page loads; enableCrossDocumentTransitions optionally adds the effect and direction. Firefox 159 navigates normally. There is no live example here because it needs two documents; the Playground has one.

Import
@neshel-ui/animations/page-transitions
API
enableCrossDocumentTransitions
Stylesheet
@neshel-ui/animations/page-transitions-mpa.css
Reduced motion
instant — the end state appears at once
Performance
The browser animates snapshots of the old and new content (View Transitions); without support the update just runs.
Example (source only): pt09.tsx
"use client";
// Both same-origin documents import this stylesheet: it opts in to cross-document view transitions.
import "@neshel-ui/animations/page-transitions-mpa.css";
import { enableCrossDocumentTransitions } from "@neshel-ui/animations/page-transitions";
import { useEffect } from "react";

/** Optional: adds the effect and the navigation direction. Render it in both documents. */
export default function CrossDocumentTransitions() {
  useEffect(() => enableCrossDocumentTransitions({ effect: "slide" }), []);
  return null;
}
Options: CrossDocumentOptions

CrossDocumentOptions

CrossDocumentOptions
PropTypeDefaultDescription
effectPageEffect——

PT10 · Router adapters

<NextPageTransitions> and <TransitionLink> connect the Next.js App Router (16.4 or later) with progress, direction and focus after a commit; page-transitions/react-router does the same for React Router 8. Both are optional peers and never prevent defaults.

Import
@neshel-ui/animations/page-transitions/next
API
NextPageTransitions, TransitionLink
Stylesheet
@neshel-ui/animations/page-transitions.css
Reduced motion
n/a — nothing moves by itself, so nothing changes
Performance
The browser animates snapshots of the old and new content (View Transitions); without support the update just runs.
Example (source only): pt10.tsx
"use client";
import "@neshel-ui/animations/page-transitions.css";
import { PageTransition } from "@neshel-ui/animations/page-transitions";
import { NextPageTransitions, TransitionLink } from "@neshel-ui/animations/page-transitions/next";
import type { ReactNode } from "react";

/** Render it once in the root layout of a Next.js App Router application. */
export default function Shell({ children }: { children: ReactNode }) {
  return (
    <NextPageTransitions>
      <nav aria-label="Main">
        <TransitionLink href="/pricing">Pricing</TransitionLink>
      </nav>
      <PageTransition effect="slide">{children}</PageTransition>
    </NextPageTransitions>
  );
}
Options: NextPageTransitionsProps

NextPageTransitionsProps

NextPageTransitionsProps
PropTypeDefaultDescription
childrenReactNode——
focus"auto" | "none""auto"Focus [data-neshel-route-focus] after a committed push/replace (default "auto").
progressRouteProgressOptions | false—Route progress options, or false to render none.
Edit on GitHub

On this page