SSGOI

Qwik

Qwik keeps ownership of projected content and serializes state. Supply transition functions through a QRL factory and attach SSGOI to the layout that owns the routed slot.

Setup

Don't wrap the route <Slot /> in another component — forwarding it can keep routed content out of the live DOM during navigation.

// src/lib/ssgoi-config.ts
import { $ } from "@builder.io/qwik";
import { drill } from "@ssgoi/qwik/view-transitions";

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

// src/routes/layout.tsx
import { Slot, component$, useSignal } from "@builder.io/qwik";
import { useLocation } from "@builder.io/qwik-city";
import { useSsgoi } from "@ssgoi/qwik";
import { config$ } from "../lib/ssgoi-config";

export default component$(() => {
  const root = useSignal<HTMLElement>();
  useSsgoi(root, { config$, framework: { location: useLocation() } });

  return (
    <main ref={root} class="relative z-0 min-h-dvh overflow-x-clip">
      <Slot />
    </main>
  );
});

// src/routes/posts/index.tsx — each routed page marks its own root
import { component$ } from "@builder.io/qwik";

export default component$(() => (
  <article data-ssgoi-transition="/posts">{/* page */}</article>
));

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. useSsgoiTransition returns a serialisable store provided by useSsgoi, so call it in a component below the layout that attached SSGOI.

import { component$, useVisibleTask$ } from "@builder.io/qwik";
import { useSsgoiTransition } from "@ssgoi/qwik";

export const Comments = component$(() => {
  const transition = useSsgoiTransition();
  useVisibleTask$(({ track }) => {
    if (track(() => transition.status) !== "idle") return;
    document.getElementById("comments")?.scrollIntoView();
  });
  return null;
});

Qwik City

Experimental API

Pass Qwik City’s location store as framework where SSGOI is attached. Route group layouts and pages call the boundary hook and apply the returned id and key to their own roots, so each keeps ownership of its DOM and slots.

Layout scopes

useSsgoiLayoutBoundary() takes no arguments: the id is the path, and the key is the config.layouts scope at the hook’s depth (each boundary inside another is one deeper), or the path. Apply both to the component’s own root. A keyed boundary that wraps <Slot /> must keep a constant key: if its key changed, Qwik would move the projected children into the new element and the outgoing page would animate empty. So the root layout only calls useSsgoi, each route group layout puts a depth-0 boundary on its own root (one key per scope, and Qwik City replaces the whole group layout when you cross groups), and pages put a depth-1 boundary on their own root. useSsgoiLayoutBoundary throws if SSGOI was attached without framework.

// src/routes/(top-level)/layout.tsx — (detail)/layout.tsx is the same without the nav
import { Slot, component$ } from "@builder.io/qwik";
import { useSsgoiLayoutBoundary } from "@ssgoi/qwik";
import { BottomNav } from "~/components/bottom-nav";

export default component$(() => {
  // Depth 0: one key for every tab, so it stays while you move between tabs.
  const boundary = useSsgoiLayoutBoundary();
  return (
    <div key={boundary.value.key} data-ssgoi-transition={boundary.value.id}>
      <Slot />
      <BottomNav />
    </div>
  );
});

// src/routes/(top-level)/posts/index.tsx — every page marks its own root
export default component$(() => {
  const boundary = useSsgoiLayoutBoundary(); // depth 1: keyed by the path
  return (
    <article key={boundary.value.key} data-ssgoi-transition={boundary.value.id}>
      {/* page */}
    </article>
  );
});

Config and navigation

Tab ↔ tab keeps the (top-level) layout, bottom nav included, and moves only the page roots. Tab → detail replaces the whole (top-level) layout with the (detail) one, nav included. A shop layout under (top-level) can keep a depth-1 boundary with a constant key across categories (the nested /shop/** scope) while each category page root is depth 2.

const TOP_LEVEL = ["/posts", "/shop/**", "/pinterest", "/profile"];

export const config$ = $(() => ({
  layouts: [
    { paths: TOP_LEVEL, layouts: [{ paths: "/shop/**" }] },
    { paths: "/**", except: TOP_LEVEL },
  ],
  transitions: [{ from: TOP_LEVEL, to: TOP_LEVEL, transition: fade() } /* , ... */],
}));

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.