SSGOI

Route boundaries

Mark each page so SSGOI can tell which one just left and which one arrived.

A route boundary is the real DOM element that owns a changing page. The framework creates and removes it; SSGOI observes that lifetime and animates the region. The layout boundary each package ships builds this element from the route your provider's framework object reads, so a router does not need a dedicated SSGOI package.

// React: use the committed pathname from your router.
<div key={pathname} data-ssgoi-transition={pathname}>
  {children}
</div>

Place the boundary inside one provider. Get the pathname from the router in the same render as its children; a mount-time window.location read or an effect-delayed key can miss the outgoing page. The ready-made SsgoiLayoutBoundary does this for you and throws if its provider has no framework; each framework guide shows the object for its router.

What each value decides

They start out identical, but they answer different questions and are read by different things.

ValueWhat it decidesWho reads it
keyWhether this DOM node survives the navigation. SSGOI reacts to the framework destroying and rebuilding the routed node.Your framework
data-ssgoi-transitionWhich logical route the node represents, so the leaving page can be paired with the arriving one and matched against your rules.SSGOI config
Changing only the id on a node that stays mounted animates nothing. The key has to change too — the id labels the transition, the remount triggers it.

SsgoiLayoutBoundary takes no SSGOI props and sets both itself. The id is always the route path. The key is the config.layoutsscope that matches at the boundary's depth — the number of boundaries above it — and the route path when no scope matches there.

Build a boundary for your router

The React wrapper only needs the route id and the lifetime of its DOM root.

import type { HTMLAttributes, ReactNode } from "react";

type Props = HTMLAttributes<HTMLDivElement> & {
  children: ReactNode;
  pathname: string;
  routeKey?: string | number;
};

export function RouteBoundary({ children, pathname, routeKey, ...props }: Props) {
  return (
    <div {...props} key={routeKey ?? pathname} data-ssgoi-transition={pathname}>
      {children}
    </div>
  );
}

Feed this wrapper the active route's committed pathname and its children. A stable routeKey preserves a shell; changing page content still needs its own boundary. Do not put a browser-URL key around a background slot that an intercepted route should preserve.

Other frameworks use their own lifetime primitives: Vue uses keyed elements, Solid uses a keyed Show, and SvelteKit detaches the outgoing snippet in onNavigate before its content changes. Qwik keeps the marker and key on the page's own root; Angular can recreate an embedded template. The framework guides show those connections and their limits.

When they stop being the same

A persistent layout gives several routes one shared mount while their route ids keep changing.

A bottom-nav app is the usual case. Tab → tab should remount only the page content; tab → detail should remount the whole shell and take the nav with it. That needs an outer shell boundary and an inner content boundary, plus one config.layouts scope that lists the tab routes so the outer key holds across them.

When both change in the same navigation, the outer one owns the transition. The outer node is the one the framework removes, so the inner boundary is torn down inside it — there is no separate node left for it to animate.

Keep one <Ssgoi> provider. Add boundaries to express ownership; never nest providers.

When the framework hides instead of unmounting

Next.js Cache Components keeps visited routes alive, so there is no remount for a key to trigger.

With cacheComponents enabled, Next.js keeps a route you leave mounted inside React <Activity> and hides it, so Back brings it back with its state. SSGOI treats that hide as the route leaving and the reveal as it arriving. SsgoiLayoutBoundary would defeat this: its key change remounts the route and discards the state.

SsgoiPageBoundaryis the exception to the note above: it sets only the id and never a key, because the lifetime comes from the hide, not from a remount. Its id is the route's pathname and follows it only while the boundary is visible, so a hidden group boundary still names the route the user left from. It uses the same provider and framework, takes no SSGOI props, ignores config.layouts, and throws if its provider has no framework.

The root layout keeps the provider with 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 in one too. Intercepted @modal pages are not wrapped. The Next.js guide shows the files.

NavigationWhat happens
Tab → tabThe group stays visible; only the page boundary swaps, so the nav stays.
Tab → detailThe whole tab group is hidden and leaves with its nav.
Detail → detailThe detail group stays; only the page swaps.
BackThe hidden route is revealed with its state intact and animates in.

Wrap it once in your own screen component, such as an AppScreen every page returns, so no page can forget it.

Do not mix SsgoiLayoutBoundary and SsgoiPageBoundaryin the same region. A layout boundary's key change remounts the routes the page boundaries rely on staying alive.

Read next