Regions
Client islands
Mark an import with wake, and that one component ships JavaScript on the schedule you pick while the rest of the page stays server HTML. The marked import is a normal component you can pass around, list and render dynamically.
On this page
On a csr = false page nothing runs in the browser unless you mark it. That’s what you want for most of the page, but not for the parts that react to the visitor: a counter, a menu, a form widget, a chart. A client island brings those parts to life. You mark the component’s import with wake, and ogygia ships JavaScript for that component alone, on the schedule you chose.
The server renders Counter into the page like any component, wrapped in an <ogygia-region> element. When its schedule fires, the runtime loads its code and hydrates it against the HTML that is already there. If a part never needs JavaScript, leave it unmarked.
<script>
import Counter from '$lib/Counter.svelte' with {
wake: 'load'
};
</script>
<h1>Static heading</h1>
<Counter start={3} />Wake schedules
The word you give wake decides when the island’s JavaScript loads and runs: load, idle, visible, interaction or a media query like '(max-width: 600px)'. Timing and nesting defines each one, with visible margins, how downloads are queued and what a replayed click can’t do.
Each demo below is a real island with a different schedule. Each one shows when it woke, so you can see the idle and visible islands wake after the load one, and the interaction one stay asleep until you press it. Your first press still counts: it’s replayed once the island is live. With JavaScript off, the markup is still there and nothing responds.
wake: 'load'wake: 'idle'wake: 'visible'wake: 'interaction'In the example, the menu wakes at once, the comments when they scroll into view, and the search box when the visitor reaches for it.
<script>
import Menu from '$lib/Menu.svelte' with { wake: 'load' };
import Comments from '$lib/Comments.svelte' with {
wake: 'visible'
};
import Search from '$lib/Search.svelte' with {
wake: 'interaction'
};
</script>
<Menu />
<Search />
<Comments />Props
Props work as they do on any component, with one difference: the server serializes them into the page, and the browser reads them back when the island wakes. So a prop has to be data:
- Crosses: anything devalue serializes: strings, numbers, booleans,
null,undefined, plain objects and arrays,Date,Map,Set,BigInt,URL,RegExp, typed arrays, and repeated or circular references. - Crosses live: an instance of a class that declares a wire codec. Every island that gets it shares one live object. See Sharing state.
- Crosses as a region: children and snippets. Plain children freeze to HTML, and a named
{#snippet}hydrates inside the island. See Snippets. - Doesn’t cross: functions (an
onSavecallback), promises, and a class instance whose class has no wire codec. Do the work inside the island, or call a remote function. A value that can’t be copied stops the server withprop_not_serializable. Don’t pass a callback: today the server treats a plain function prop as a snippet and freezes what it returns, so it can fail quietly instead of withfunction_prop_cannot_cross.
A prop is a copy. Changing it inside the island changes nothing outside, and in dev ogygia warns (prop_mutation). Copy it into the island’s own $state and change that. Constraints has the full rules.
The same goes for the tag’s attributes. <Counter bind:count /> passes count in as a copy, and nothing flows back, because the page’s script doesn’t run in the browser. An event attribute like onchange={…} is a function, so it doesn’t cross.
An island can also read page from $app/state, and context the page sets.
In the example, the layout passes the cart’s size to a badge island, which copies it into its own $state.
<script>
let { initial = 0 } = $props();
let count = $state(initial);
</script>
<button onclick={() => count++}>Cart ({count})</button><script>
import CartBadge from '$lib/CartBadge.svelte' with {
wake: 'load'
};
let { data, children } = $props();
</script>
<header><CartBadge initial={data.cart.length} /></header>
{@render children()}Islands as values
When you mark an import, ogygia replaces the binding itself with an island wrapper. The template still says <Counter />, but Counter is now a component that carries its island settings wherever it goes. You can assign it, pass it as a prop, put it in an object, or render it from a list, and it’s still an island.
A marked import used a thousand times on a page makes one wrapper module and one client chunk. Each placement still gets its own region and its own props.
In the example, the page keeps Chart and Table in a views object and picks one from the load’s data, and each pick is still an island that wakes when visible.
The demo below is that page. Four panels come from a list, and each picks its component from the views map by its kind. Each one is its own island with its own state: add a bar to one chart, or sort one table, and the others don’t change. Press show as table under a panel: the server picks the other component for it, and the new one hydrates as an island too.
<script>
import Chart from '$lib/Chart.svelte' with {
wake: 'visible'
};
import Table from '$lib/Table.svelte' with {
wake: 'visible'
};
let { data } = $props();
const views = { chart: Chart, table: Table };
const View = views[data.view];
</script>
<View rows={data.rows} />
{#each data.panels as panel}
{@const Panel = views[panel.kind]}
<Panel rows={panel.rows} />
{/each}Package and barrel imports
The mark works on a named import too, so a component that reaches you through a barrel (a design system’s index.ts, a package) is marked the same way. The island imports the component by its export name, and the bundler tree-shakes the barrel, so one marked component out of a hundred ships one component. Rename with as when you need two schedules for one component.
One with covers every name in its braces. Put components with different schedules, and anything that isn’t a component, on separate import lines. The build checks this: a marked name used as anything but a component (called, read with ., spread, typeof, put in text, {@render}, an action) fails with the plain import line to write instead (region_binding_not_component).
Import sorters usually leave marked imports alone. TypeScript’s organize imports, eslint-plugin-import-x and Biome never merge a marked import with a plain one. The autofix of eslint-plugin-import’s import/no-duplicates does: it can move a plain name under a with, or merge two different with clauses. Turn that rule off, or use import-x/no-duplicates.
A component library can ship marked components of its own. Packaging shows how.
In the example, the layout wakes Header, Footer and Ticker at load, a second Ticker renamed SlowTicker when idle, and imports the helper formatDate on a plain line of its own.
<script>
import { Header, Footer, Ticker } from '@acme/ui' with {
wake: 'load'
};
import { Ticker as SlowTicker } from '@acme/ui' with {
wake: 'idle'
};
import { formatDate } from '@acme/ui';
let { children } = $props();
</script>
<Header />
<Ticker />
{@render children()}
<SlowTicker />
<Footer updated={formatDate(new Date())} />Boot islands
On a csr = false page, the <script> of +page.svelte and +layout.svelte never runs in the browser, so onMount, $effect, event listeners and analytics written there do nothing. An island is the only place browser code runs.
When you need code without UI, write an island that renders nothing. That’s a boot island: a component with no markup whose job is its $effect. Give it what it needs as props, under the same rules as any island.
A boot island in a page remounts on each navigation, so its $effect runs again. One in a layout usually has to keep running instead, without reopening a socket on every route: add keep, and the live instance moves to the next page.
If an island already imports your store module, you may not need a boot island at all. Top-level code in a .svelte.ts module runs when the first island imports it. A boot island is for code that has to run on pages with no islands, like site-wide analytics or a global keyboard shortcut.
<script>
import { startTracking } from '$lib/analytics';
let { siteId } = $props();
$effect(() => {
const tracker = startTracking(siteId);
return () => tracker.stop();
});
</script><script>
import Analytics from '$lib/Analytics.svelte' with {
wake: 'load',
keep: 'analytics'
};
let { data, children } = $props();
</script>
<Analytics siteId={data.siteId} />
{@render children()}Persistence across navigations
With keep: 'name', an island survives an SPA navigation. When the next page places an island with the same name, the live element and its state move into the new spot instead of remounting, so a music player keeps playing. The new page’s props are pushed into the live component, so a prop that changes per route still updates.
keep needs the SPA router. With ogygia({ router: false }) every navigation is a full page load, so nothing is kept, and dev warns (keep_without_router). Use a different name for each kind of thing you keep. Keep a whole island has more.
In the example, a player in the root layout keeps playing as the visitor moves between pages, and takes each page’s track as a prop.
<script>
import Player from '$lib/Player.svelte' with {
wake: 'load',
keep: 'player'
};
let { data, children } = $props();
</script>
<Player track={data.track} />
{@render children()}Hydration state
When an island has hydrated, its <ogygia-region> element gets a data-hydrated attribute and fires an ogygia:hydrated event, which bubbles. Tests can wait for the attribute, and page code can listen for the event.
Inside the island, hydratedBy() tells you which schedule woke it.
import { test, expect } from '@playwright/test';
test('cart badge counts', async ({ page }) => {
await page.goto('/');
const badge = page.locator('ogygia-region[data-hydrated]', {
hasText: 'Cart'
});
await badge.getByRole('button').click();
await expect(badge).toContainText('Cart (1)');
});Inline islands
An island placed inside a <p> must render an inline element, like a <span>. If its component renders a <div> or a <p>, the browser’s HTML parser moves that block out of the paragraph before any script runs, the island finds itself empty, and a second copy mounts beside the first. In dev, ogygia names the island (island_block_in_inline). Render a <span>, or place the island on its own line.
<script>
let { likes = 0 } = $props();
let count = $state(likes);
</script>
<span><button onclick={() => count++}>♥ {count}</button></span>Foreign DOM edits
An island can sleep for a long time while other scripts run: a design-system runtime, an A/B tool, a translator. Some of them edit the DOM inside the island, removing a whitespace node or adding a comment. Svelte hydrates by walking the nodes it finds, so an edited island would normally be thrown away and rendered again, and the click that woke it would land on a node that no longer exists.
To prevent that, ogygia keeps each island’s server markup from the moment it connects. If the walk fails because the live DOM drifted, ogygia puts the server markup back and hydrates that. The island gets data-og-healed, and in dev one warning names it (island_healed). Only if that also fails does Svelte render the island in the browser (data-og-recovered), and dev explains the likely causes (hydration_discarded).
A heal discards whatever the other script added, so scripts should still leave <ogygia-region> elements alone. DOM ownership shows where a third-party widget can sit safely.
Error handling
An island that can’t load stays as its server HTML. It doesn’t break the page:
- Its code can’t be fetched (a network error, or a file missing after a deploy):
island_load_failed. After a deploy, ogygia retries with the current build’s file before it reports this. - A file its code imports failed, and the browser keeps that failure until the page reloads:
chunk_reload_needed, said once per page. - The component threw while hydrating:
island_hydrate_failed, with the component’s error after it.
Do and don’t
- Do use
wake: 'visible'for islands below the fold. - Do keep islands small and focused, since a smaller island ships less code.
- Do put browser-only code in a boot island.
- Don’t pass callbacks or class instances without a codec as props. Move the logic inside, or use shared state.
- Don’t wrap the whole page in one island. One island around the whole page ships all of its code, like
csr = true.