SSGOI

React

Use SSGOI with React independently of your router. Tell the provider how to read your router’s route through framework, and SsgoiLayoutBoundary connects it to a page lifetime.

Common setup

Install @ssgoi/react. Keep one provider and a stable config above routed content. The surrounding layout supplies position: relative, z-index: 0, min-height: 100dvh, and overflow-x: clip.

import type { ReactNode } from "react";
import { Ssgoi, type SsgoiConfig } from "@ssgoi/react";
import { drill } from "@ssgoi/react/view-transitions";

const config: SsgoiConfig = {
  transitions: [{ on: "/**", except: "/", transition: drill() }],
};

export function SsgoiProvider({ children }: { children: ReactNode }) {
  return <Ssgoi config={config}>{children}</Ssgoi>;
}

Transition state

A page that scrolls itself on arrival, such as an anchor jump or scrollIntoView, fights the animation. Read the provider's transition state and act once it is idle. The status is idle or transitioning; while transitioning it also carries from, to and direction. It flips as soon as the navigation is paired, one microtask after the DOM changed, and returns to idle when the run releases, the same span the scroll-input lock covers.

import { useEffect } from "react";
import { useSsgoiTransition } from "@ssgoi/react";

export function Comments({ anchor }: { anchor: string }) {
  const { status } = useSsgoiTransition();
  useEffect(() => {
    if (status !== "idle") return;
    document.getElementById(anchor)?.scrollIntoView();
  }, [status, anchor]);
  return null;
}

Connect a router

Pass framework to <Ssgoi>, then wrap routed children in SsgoiLayoutBoundary from @ssgoi/react. framework.useRoute is a hook you write with your router’s own hooks: it returns the current route ({ pathname, renderedPath? }) or null while the router is not ready. The first boundary reads it for every boundary inside it; boundaries take no SSGOI props. Keep the object at module scope so it stays stable. SsgoiLayoutBoundary throws if the nearest <Ssgoi> has no framework.

import { Ssgoi, SsgoiLayoutBoundary, type SsgoiFramework } from "@ssgoi/react";

const framework: SsgoiFramework = {
  useRoute: () => ({ pathname: useYourRouterPathname() }),
};

<Ssgoi config={config} framework={framework}>
  <SsgoiLayoutBoundary>{children}</SsgoiLayoutBoundary>
</Ssgoi>

Using another router

Any router works without a dedicated integration: return its committed pathname from useRoute, read in the same render as its children. You can also skip framework and render a keyed DOM boundary yourself. The Route boundaries guide explains the general pattern.

Next.js

Return the App Router’s pathname and the path its layout segments render from framework.useRoute. SsgoiLayoutBoundary keys by that path or its config.layouts scope, handles URL-hook suspension, and marks the routed region.

Connect the App Router

Place the common provider and config in app/ssgoi-provider.tsx, add "use client", and build framework.useRoute from usePathname and useSelectedLayoutSegments in next/navigation. renderedPath is what the children slot actually shows, so a soft intercepted modal leaves the background in place. The provider is a client component, so passing a function is fine. A null pathname (mixed app/pages projects) returns null, so no guessed route is registered.

// app/ssgoi-provider.tsx
"use client";

import type { ReactNode } from "react";
import { usePathname, useSelectedLayoutSegments } from "next/navigation";
import { Ssgoi, type SsgoiFramework } from "@ssgoi/react";
import { drill } from "@ssgoi/react/view-transitions";

const config = {
  transitions: [{ on: "/**", except: "/", transition: drill() }],
};

const INTERCEPTION_PREFIX = /^(?:\(\.\.\.\)|\(\.\.\)|\(\.\))+/;

const framework: SsgoiFramework = {
  useRoute: () => {
    const pathname = usePathname();
    // The page the children slot renders. During a soft intercept it is still
    // the background page, so no background boundary moves.
    const segments = useSelectedLayoutSegments();
    if (pathname == null) return null;
    const renderedPath = `/${segments
      .filter((segment) => !(segment.startsWith("(") && segment.endsWith(")")))
      .map((segment) => segment.replace(INTERCEPTION_PREFIX, ""))
      .filter(Boolean)
      .join("/")}`;
    return { pathname, renderedPath };
  },
};

export function SsgoiProvider({ children }: { children: ReactNode }) {
  return (
    <Ssgoi config={config} framework={framework}>
      {children}
    </Ssgoi>
  );
}

Root layout

Place both pieces inside the layout shell; no local router wrapper is needed. The wrapper supplies the containing block, stacking context, and horizontal clipping needed by the leaving page.

// app/layout.tsx
import { type ReactNode } from "react";
import { SsgoiLayoutBoundary } from "@ssgoi/react";
import { SsgoiProvider } from "./ssgoi-provider";

export default function RootLayout({ children }: { children: ReactNode }) {
  return (
    <html lang="en">
      <body>
        <main className="relative z-0 min-h-dvh overflow-x-clip">
          <SsgoiProvider>
            <SsgoiLayoutBoundary>{children}</SsgoiLayoutBoundary>
          </SsgoiProvider>
        </main>
      </body>
    </html>
  );
}

Persistent layouts

Declare the section in config.layouts, for example layouts: [{ paths: "/shop/**" }], and put a prop-less boundary around the changing content in its layout. The root boundary (depth 0) keys every /shop route by that one scope, so the header stays; the inner boundary (depth 1) keys by the path, so the content swaps. Boundary depth is automatic: each boundary inside another is one level deeper.

// app/ssgoi-provider.tsx
const config = {
  layouts: [{ paths: "/shop/**" }],
  transitions: [/* ... */],
};

// app/shop/layout.tsx
import type { ReactNode } from "react";
import { SsgoiLayoutBoundary } from "@ssgoi/react";

export default function ShopLayout({ children }: { children: ReactNode }) {
  return (
    <>
      <header>Shop</header>
      <SsgoiLayoutBoundary>{children}</SsgoiLayoutBoundary>
    </>
  );
}

Parallel slots and interception

During a soft intercept the URL points at the modal while the children slot still renders the background. Because useRoute returns renderedPath from the selected segments, no background boundary moves. Render the {modal} slot outside the boundaries; it animates by itself and needs no SSGOI setup. Interception still needs the app’s route/slot files and compatible middleware or proxy rules. Verify soft navigation, back, and direct entry.

Cache Components: SsgoiPageBoundary

With cacheComponents enabled, Next.js keeps visited routes mounted inside React <Activity> and hides them, so their state is still there on Back. SsgoiLayoutBoundary changes its key to force a remount, which discards that state. SsgoiPageBoundary never sets a key: Next hides the route you leave and reveals the one you open, and SSGOI animates that hide and reveal. It uses the same provider and framework.useRoute, takes no SSGOI props, takes its id from pathname (renderedPath is ignored), and throws if <Ssgoi> has no framework. A custom as component must forward its ref to its DOM root, or the id never updates. The root layout keeps the provider but no boundary. Every route-group layout wraps its whole content in SsgoiPageBoundary, bottom nav included, so the nav leaves with its group; every page wraps itself too. config.layouts is not used, intercepted @modal pages are not wrapped, and the two boundaries are not mixed in one region. In this beta, while a soft-intercepted modal is open the background boundaries’ id follows the URL. Known Next.js issue (vercel/next.js#98623): from the second visit on, Next reorders kept-alive routes and React moves their DOM, which reloads iframes, restarts media and resets inner scroll containers; SSGOI cannot prevent that move. Wrapping it once in your own screen component, such as an AppScreen, keeps pages from forgetting it.

// app/layout.tsx: <SsgoiProvider>{children}</SsgoiProvider>, no boundary

// app/(top-level)/layout.tsx
import type { ReactNode } from "react";
import { SsgoiPageBoundary } from "@ssgoi/react";

export default function TopLevelLayout({ children }: { children: ReactNode }) {
  return (
    <SsgoiPageBoundary className="flex min-h-dvh flex-col">
      {children}
      <BottomNav />
    </SsgoiPageBoundary>
  );
}

// app/(top-level)/posts/page.tsx, and every other page
export default function PostsPage() {
  return <SsgoiPageBoundary>{/* page content */}</SsgoiPageBoundary>;
}

Remix

Experimental API

Return Remix 2’s location from framework.useRoute. It reads Remix’s own router context, so it does not depend on a separately installed React Router version.

Pass the framework

In root.tsx, give the common provider a useRoute that returns Remix’s location. Keep the object at module scope so it stays stable. SsgoiLayoutBoundary throws if <Ssgoi> has no framework.

import { Outlet, useLocation } from "@remix-run/react";
import { Ssgoi, type SsgoiFramework } from "@ssgoi/react";
import { config } from "./ssgoi-config";

const framework: SsgoiFramework = { useRoute: () => useLocation() };

export default function App() {
  return (
    <Ssgoi config={config} framework={framework}>
      <Outlet />
    </Ssgoi>
  );
}

Wrap a layout outlet

Place the boundary in a route layout. Follow Remix 2’s own React 18 dependency requirements. React Router 7 framework mode returns React Router’s location instead.

import { Outlet } from "@remix-run/react";
import { SsgoiLayoutBoundary } from "@ssgoi/react";

export default function Layout() {
  return <SsgoiLayoutBoundary><Outlet /></SsgoiLayoutBoundary>;
}

Persistent route families

Declare the section in config.layouts, for example layouts: [{ paths: "/shop/**" }], and put a prop-less boundary around the changing content in its layout. The root boundary (depth 0) keys every /shop route by that one scope, so the header stays; the inner boundary (depth 1) keys by the path, so the content swaps.

React Router

Experimental API

Return React Router 6 or 7’s location from framework.useRoute. The boundary follows the committed location; query-only navigation preserves it.

Pass the framework

In app/root.tsx, give the common provider a useRoute that returns React Router’s location.

import { Outlet, useLocation } from "react-router";
import { Ssgoi, type SsgoiFramework } from "@ssgoi/react";

const framework: SsgoiFramework = { useRoute: () => useLocation() };

export default function App() {
  return (
    <Ssgoi config={config} framework={framework}>
      <Outlet />
    </Ssgoi>
  );
}

Wrap the outlet

Put this pathless layout inside the common provider. Register the layout around the pages that should transition.

import { Outlet } from "react-router";
import { SsgoiLayoutBoundary } from "@ssgoi/react";

export default function PageBoundaryLayout() {
  return <SsgoiLayoutBoundary><Outlet /></SsgoiLayoutBoundary>;
}

Route registration

In framework mode, put existing page routes under the boundary layout. Keep the document Layout and other root exports from your React Router app.

// app/routes.ts
import { type RouteConfig, index, layout, route } from "@react-router/dev/routes";

export default [
  layout("routes/page-boundary.layout.tsx", [
    index("routes/home.tsx"),
    route("posts/:postId", "routes/posts.$postId.tsx"),
  ]),
] satisfies RouteConfig;

Beyond the basics

A persistent shell needs two lifetimes. Declare the section in config.layouts, for example layouts: [{ paths: "/shop/**" }], and put a prop-less boundary around the changing content in its layout. The root boundary (depth 0) keys every /shop route by that one scope, so the header stays; the inner boundary (depth 1) keys by the path, so the content swaps. Here the root boundary is the pathless page-boundary layout and the inner one wraps the section layout’s <Outlet />; the complete pattern is in the agent guide and template.

TanStack Router

Experimental API

Return TanStack Router 1’s rendered pathname from framework.useRoute, including React applications built with TanStack Start. Both use the same router context.

Wrap the root outlet

useRoute reads the leaf match the outlet is rendering rather than location, which TanStack moves before pending matches render. For persistent sections, put boundaries in the owning route layouts instead.

import { Outlet, useRouterState } from "@tanstack/react-router";
import {
  Ssgoi,
  SsgoiLayoutBoundary,
  type SsgoiFramework,
} from "@ssgoi/react";

// Key by the leaf match the outlet renders, not location: location moves
// before pending matches render, and index routes match "/parent/".
const framework: SsgoiFramework = {
  useRoute: () => ({
    pathname: useRouterState({
      select: (state) => {
        const location = state.location.pathname;
        const leaf = state.matches.at(-1)?.pathname;
        if (!leaf) return location;
        return leaf.length > 1 && leaf.endsWith("/") && !location.endsWith("/")
          ? leaf.slice(0, -1)
          : leaf;
      },
    }),
  }),
};

<Ssgoi config={config} framework={framework}>
  <SsgoiLayoutBoundary><Outlet /></SsgoiLayoutBoundary>
</Ssgoi>

Beyond the basics

Declare the section in config.layouts, for example layouts: [{ paths: "/shop/**" }], and put a prop-less boundary around the changing content in its layout. The root boundary (depth 0) keys every /shop route by that one scope, so the header stays; the inner boundary (depth 1) keys by the path, so the content swaps. Here the inner boundary wraps the section route’s <Outlet />.

Each router connects through the provider's framework prop. Route boundaries explains how to connect another router directly. Transitions and route rules apply across the web frameworks.