SSR islands for SvelteKit pronouncedoh-jee-jee-ya

ogygia

The missing layer for SvelteKit.

Islands. Server islands. Lakes. Web components. And more.

every demo is live

Start with one button

Every demo below is live, right here on this page. It starts with a single button, then adds one idea at a time until you have a whole site.

client island

Mark one import

Add wake: 'load' to an import, and that component wakes up in the browser. The page around it stays HTML. Flip the JS switch off and only the counter stops working.

Client island wake: 'load'
<script>
  import Panel from '$lib/Panel.svelte' with {
    wake: 'load'
  };
</script>

<Panel />
live island
Load island
10

schedules

Then pick when it wakes

load is only one choice. There's also idle, visible and any media query, and each component waits for its own moment. So a page that's mostly text stays cheap, because nothing loads before it's needed.

Schedules idle · visible · media · interaction
<script>
  import Chart from '$lib/Chart.svelte' with {
    wake: 'visible'
  };
</script>

<Chart />
each wakes on its own trigger
Idle clock
4:13:03 PM

Hydrated after idle

Visible island
0

Hydrated on intersect

Media island
0

Active when (max-width: 600px)

Interaction island asleep
0

no JavaScript yet · your first press wakes it

lake

Some parts never need to wake

If a component renders once and never changes, mark it wake: 'none'. The server still renders it, but none of its code goes to the browser. We call that a lake.

Lake wake: 'none'
<script>
  // a frozen subtree inside an island: SSR HTML, ships no client JS
  import Snapshot from '$lib/Snapshot.svelte' with {
    wake: 'none'
  };
</script>

<Snapshot value={42} />
frozen · 0 KB JS
Static snapshot
42

SSR HTML, no client JS

That's everything the browser does. The rest of the story is the server's.

server island

Let the server fill a gap

render: 'deferred' makes a server island. The page shows up first, then the island fetches its own HTML, made fresh for each visitor. It ships no code to the browser.

Server island render: 'deferred'
<script>
  import Greeting from '$lib/Greeting.svelte' with {
    render: 'deferred'
  };
</script>

<Greeting salutation="Aloha">
  {#snippet ogygiaFallback()}
    <p>loading…</p>
  {/snippet}
</Greeting>
server HTML, fetched late
/demo/deferred

press ↻: the fallback shows, then fresh server HTML

held region

Let the server pick the component

A held region goes one step further. The server decides which component to show, signs the HTML and sends it over. The browser just paints it, and never has to import any of the options.

Held region server picks the UI
<script>
  // the server picks the component; the client just paints it
  import { Region } from 'ogygia';
  import { search } from './search.remote';

  let q = $state('svelte');
  let result = $state(null);
</script>

<button onclick={async () => (result = await search(q))}>
  Search
</button>

{#if result}
  <Region of={result} />
{/if}
server chooses the component
Held region ready

Search to fetch a component from the server.

each search is a new server round trip · the demo server waits 400ms

live region

Keep it up to date

With query.live, the server sends fresh HTML every time it renders again, and the region updates in place. We call that a morph. You don't write any fetching or polling code.

Live region query.live
// tick.remote.ts — the server pushes rendered HTML each second.
// `yield` awaits the partial, so its HTML rides the ticket (no fetch).
export const liveTick = query.live(async function* () {
  let n = 1;
  while (true) {
    yield region(Tick, { n: n++, at: new Date().toISOString() });
    await new Promise((r) => setTimeout(r, 1000));
  }
});

// the island just paints the latest tick — static partials morph in place
<Region of={liveTick().current} />
server pushes HTML · morphs in place
Live region

connecting…

server pushes rendered HTML · no client data code · ↻ reconnects

So far, every region has worked alone. But two of them can share state too.

shared object

Share one object between islands

These are two separate islands, each with its own bundle, and both get the same live object as a prop. The button changes it and the counter shows it. You don't need a store or an event bus for this.

Shared object static [ogygia.wire]
// cart.svelte.ts — a live class that can cross island boundaries
export class Cart {
  items = $state([]);
  get count() { return this.items.length; }
  add(item) { this.items.push(item); }

  // the whole opt-in: how this instance travels as a prop
  static wire = import.meta.og.wire({
    encode: (c) => $state.snapshot(c.items),
    decode: (items) => Object.assign(new Cart(), { items }),
  });
}

// page.svelte — one instance, handed to two separate islands
const cart = new Cart();
<CartCount {cart} />   <!-- reads cart.count -->
<AddButton {cart} />   <!-- calls cart.add() -->
// click Add → the count island repaints. One live object, two islands.
one live object · two islands
Count island
0 items in the shared cart
Add island

separate bundle from the count

content

Your writing works the same way

Define a collection once with content(), from markdown, JSON or a CMS. You query it like any other remote function, and the text itself never ships to the browser. Whatever you render from it is a region, so it wakes on the same schedules as everything else. These docs are built this way.

Content collection @ogygia/content
// collections.server.ts — one server-only definition
import { content } from '@ogygia/content';

export const docs = content({
  loader: import.meta.og.loader.markdown('./docs/**/*.svx'),
  schema
});

// docs.remote.ts — expose it over the wire, bodies stripped
export const docNav = withRemotes(docs).list({
  map: (e) => ({ slug: e.id, title: e.data.title })
});
live over the wire · no bodies shipped
Content collection 140 pages

140 pages · one content() collection · fetched over the wire

one definition

Any source, the same API

You write one content() definition, and the source decides where the data comes from.

Markdown & islandsMarkdown with live components in it
<!-- posts/hello.svx — markdown, with real islands in the prose -->
<script>
  import Chart from '$lib/Chart.svelte' with { wake: 'visible' };
</script>

# {frontmatter.title}

Shiki-highlighted fences, heading ids, and a TOC in `meta.headings` —
and a live island, right in the copy:

<Chart {data} />
Markdown & Shiki →
Typed dataJSON through the same API
// typed data, not just prose — JSON through the same API
import { content } from '@ogygia/content';
import * as v from 'valibot';

export const authors = content({
  loader: import.meta.og.loader.json('./authors/*.json'),
  schema: v.object({ name: v.string(), bio: v.string() })
});

const ada = await authors.get('ada'); // fully typed { name, bio }
Collections →
Any source, even liveA CMS, an API, or a live feed
// any source — a CMS, a REST API, or a push feed
export const press = content({
  schema,
  loader: {
    // get() carries the body; refs() is metadata only (never a body on the wire).
    async get(id)  { const p = await api(`/posts/${id}`); return p && { id, data: p }; },
    async refs()   { return (await api('/posts')).map((p) => ({ id: p.slug, data: p })); }
  }
});

// pushes? add live() — a change signal; the feed re-emits on every change.
export const feed = withRemotes(press).live.list({ map: (e) => e.data });
Blocks & custom sources →

site kit

Put it together and you have a site

Give site() a collection and DocsShell builds the rest: the nav from your file names, previous and next links, full-text search, versions and translations, sitemap.xml and llms.txt. The frame is live. Search it (press /), switch the version or the language, or restyle it. This whole site runs on the same thing.

ogygia playground · DocsShell Open in full ↗

your own shell

Or build your own from the parts

DocsShell is just one way to put the public parts together. You can keep it and swap out a single region, or start from Frame and build your own shell. Versions and translations come from one small primitive too, called dimensions.

To try it, run npx ogygia site init. It gives you everything, and you delete what you don't need.

DimensionsVersions and languages, from one primitive

Remember the V2 and EN switchers you just tried? You declare the axes and return one outline for each combination. The URLs, the switchers and the fallback for pages that aren't translated yet all come with it.

// versioning and translations are the same primitive: dimensions
import { site, dimensions } from '@ogygia/content';

export const docs = site({
  outline: dimensions({
    axes: {
      version: { values: ['v2', 'v1'], default: 'v2', label: 'Version' },
      locale:  { values: ['en', 'de'], default: 'en', label: 'Language', fallback: true }
    },
    // one outline per coordinate — the axes compose
    resolve: ({ version, locale }) => corpora[version][locale]
  })
});

// /docs/routing        → v2 · en   (defaults serve bare)
// /docs/de/routing     → v2 · de
// /docs/v1/de/routing  → v1 · de
Dimensions →
CompositionSwap a region, or the whole shell

Every region of the shell is a snippet prop. Leave it out to get the built-in one, pass a snippet to replace it, or pass null to remove it. And if you'd rather start from nothing, Frame is the same shell with none of the choices made.

<!-- DocsShell is a composition. Keep it, swap one region: -->
<script>
  import DocsShell from '@ogygia/content/docs-shell';
  import { Search, ThemeToggle } from '@ogygia/content';
</script>

<DocsShell {meta} base="/docs">
  {#snippet tools()}
    <Search base="/docs" />
    <ThemeToggle />
  {/snippet}
</DocsShell>

<!-- absent = built-in · snippet = yours · null = removed.
     Or drop to <Frame> and build the shell from the same bricks. -->
Shells →
The bricksEvery part imports on its own

Sidebar, OnThisPage, Search, Switcher, Pager, ThemeToggle, Doc, TabGroup. You only pay for the ones you import, and their CSS ships only when you do.

Components →

the app layer

And it still feels like an app

All of that is what you see. Underneath, ogygia makes the page fast too. It prerenders the shell, fetches the server islands in one batch, and moves between pages like a single-page app, without any extra client code from you.

  1. Serve the shell from the CDN

    With partial prerendering, the shell is a static file on the CDN, and the server islands are fetched fresh for each visitor. There's a demo where you reload one page and it shows two different times. Partial prerendering →

  2. One request per navigation

    When you move to a new page, the SPA router fetches all of its server islands in one request. Each one arrives as soon as it's ready, and none of them waits on another. Single-flight navigation →

  3. Change data and repaint in one trip

    A command sends back the updated region in the same response, so the region on the page updates without a second fetch. Repaint after a command →

  4. Prerender the next page on hover

    While you hover a link, the browser's Speculation Rules load the next page in a hidden tab, so the click feels instant. Speculation →

the sea floorstart here

Start here

The full guide lives in the docs, split by topic, with live demos on every page. Pick a place to start.