Regions
Snippets
Children and snippets you pass into an island work as they would on any component. Plain children freeze to server HTML, a named snippet hydrates inside the island, and region.snippet() builds one by hand.
An island’s props are serialized into the page, and a snippet is a function, which can’t be serialized. Yet <Tabs>{@render children()}</Tabs>, a {#snippet header()} passed to an island, and a wrapper that forwards its children into an island all work. ogygia sends every snippet given to an island across as a region, the same idea behind every marked component.
You don’t call anything for this. Write children and snippets the way you always do:
<script>
import Tabs from '$lib/Tabs.svelte' with { wake: 'load' };
import LiveButton from '$lib/LiveButton.svelte';
</script>
<Tabs>
<p>
Prose that never changes. It crosses as HTML and ships no
code.
</p>
{#snippet toolbar()}
<LiveButton />
{/snippet}
</Tabs>Snippet transport
ogygia picks one of two ways, based on how you wrote the content, not on what it renders:
- Static. Children written straight between the island’s tags, without a
{#snippet}around them, render once on the server. The island adopts that HTML in place, so nothing reruns and nothing ships. This suits prose, a code block or markup with no behavior. - Live. Every named
{#snippet}you write between an island’s tags compiles to its own entry and hydrates inside the island, whatever its body renders. It renders on the server like everything else, then becomes interactive where it lands. Snippet parameters work, and each call’s arguments travel with it. A named snippet with no parameters, passed to a plain component, is compiled the same way, so it stays live when a wrapper forwards it into an island.
A named snippet that can’t be compiled on its own freezes to static HTML instead. That happens when it reads a variable from an enclosing {#each}, {#await} or {@const} that isn’t one of its own parameters, or a host variable that the host changes. Snippets in files under node_modules are never compiled to entries.
Islands nested inside static content keep working, in plain children and in a snippet that froze. They render as full islands and wake on their own, even though the content around them is frozen.
A live snippet is part of the island that renders it:
- An island inside it hydrates with that island, as if it were in the island’s own template.
- A server island inside it stays deferred: its fallback ships with the page, and its HTML arrives on its schedule.
- A lake inside it stays static, and an island inside that lake wakes on its own schedule.
- It can render the host’s top-level snippets, and read the host’s
<script module>imports and values. - It reads the page’s context, on the server and in the browser.
- The island sets
data-hydratedand firesogygia:hydratedonly after its live snippets have hydrated too.
In the example, the row snippet hydrates inside the List island, and each Star in it hydrates with List.
<script>
import List from '$lib/List.svelte' with { wake: 'load' };
import Star from '$lib/Star.svelte';
let { data } = $props();
</script>
<List items={data.items}>
{#snippet row(item)}
<span>{item.name}</span>
<Star id={item.id} />
{/snippet}
</List>Wrapper components
A plain component (not an island) can forward its children into an island. The crossing happens at the island’s boundary, so the wrapper is ordinary Svelte with nothing special in it.
<script>
import Card from '$lib/Card.svelte' with { wake: 'load' };
let { title, children } = $props();
</script>
<Card {title}>{@render children()}</Card>Captured values
A snippet crossing into an island is rendered from the values it reads, captured when the page renders. Like any prop, that’s a copy: changing the host’s variable later doesn’t change the island.
- A
$storeread inside a crossing snippet is captured as the store’s value at render time. The build rewrites it and warns with the file and line (snippet_store_snapshot). To silence it, read the store into a plain variable outside the snippet. For a value that stays live across islands, use a wired class. $$propsand$$restPropsbelong to the host and can’t be captured, so reading them in a crossing snippet fails the build (snippet_reads_dollar_props). Read what you need into a plain variable first.- A plain function (an event handler) passed as a prop never crosses. Only snippets do. Don’t pass one: the server can mistake it for a snippet and freeze it, rather than stop with
function_prop_cannot_cross.
<script>
import Panel from '$lib/Panel.svelte' with { wake: 'load' };
import { user } from '$lib/stores';
const name = $user.name;
</script>
<Panel>
{#snippet title()}<h2>Hello, {name}</h2>{/snippet}
</Panel>region.snippet()
When you need a snippet made from raw HTML, use region.snippet(), the counterpart of region() for snippets. It mirrors Svelte’s createRawSnippet, but the result is a region snippet: you can {@render} it, and it can cross into an island.
Pass an existing snippet that takes no parameters, and it’s frozen as static content. This form renders the snippet with Svelte’s server renderer, so it works only on the server; in the browser it throws region_snippet_on_client. Or pass { render, setup?, captures? }, which works on both sides. It’s like the object createRawSnippet’s function returns, except that render and setup get the captures as arguments:
capturesis an array of inputs. They must be serializable, like island props.rendergets the captures as its arguments and returns the HTML. ogygia wraps it in one<ogygia-snippet style="display:contents">element, so it doesn’t need a single root.setupgets that wrapping element and the captures, and runs in the browser after mount. Its return value is ignored, so it can’t return a cleanup. It’s dropped when the snippet crosses a boundary, since a frozen snippet has nothing to start.
In the example, Toolbar gets two region snippets: label is the page’s badge snippet frozen to HTML, and stamp is built from a render function with one capture.
<script>
import { region } from 'ogygia';
import Toolbar from '$lib/Toolbar.svelte' with {
wake: 'load'
};
const stamp = region.snippet({
render: (label) => `<span class="stamp">${label}</span>`,
captures: ['shipped']
});
</script>
{#snippet badge()}<span class="badge">stable</span>{/snippet}
<Toolbar label={region.snippet(badge)} {stamp} />