Regions
Timing and nesting
The schedules that decide when an island's JavaScript runs and when a server island's HTML arrives, how ogygia queues the downloads, and the one rule for regions inside regions.
On this page
Every region depends on two things: when it wakes, and what happens when it sits inside another region. This page is the reference for both. The timing is one word on the import, wake for an island and fetch for a server island:
<script>
import Chart from '$lib/Chart.svelte' with {
wake: 'visible'
};
import Reviews from '$lib/Reviews.svelte' with {
render: 'deferred',
fetch: 'idle'
};
</script>
<Chart />
<Reviews />Schedules
wake and fetch share one set of timing words, so you learn them once. wake is when an island’s JavaScript runs. fetch is when a server island’s HTML arrives.
| Value | When it fires | Good for |
|---|---|---|
load | Once the page has painted and your fetchpriority="high" images have loaded (at most 2.5 s) | UI above the fold that must work at once |
idle | When the browser is idle (requestIdleCallback) | Widgets that can wait a moment |
visible | When it scrolls into view | Anything below the fold |
interaction | On the first click, key press or focus inside it | UI most visitors never touch |
| a media query | When the query first matches, like '(max-width: 600px)'; it stays live after that | UI for small screens only, or large ones only |
Any other word fails the build: region_import_invalid in a .svelte file, wake_strategy_unknown in a .ts module. wake: 'none' makes a lake, which never wakes, so it has no place in this table. A server island’s fetch: 'load' doesn’t wait for the paint: its request starts from the page’s head. On a server island, fetch: 'interaction' makes an on-demand hole that fetches on the first hover, focus, touch or key press inside its fallback.
Each of the four demos below is a real island with that schedule. The media-query one wakes only on a narrow screen. The example places one region for each word.
<script>
import Now from '$lib/Now.svelte' with { wake: 'load' };
import Later from '$lib/Later.svelte' with { wake: 'idle' };
import Below from '$lib/Below.svelte' with {
wake: 'visible'
};
import Phone from '$lib/Phone.svelte' with {
wake: '(max-width: 600px)'
};
import Panel from '$lib/Panel.svelte' with {
render: 'deferred',
fetch: 'visible'
};
</script>
<Now />
<Later />
<Below />
<Phone />
<Panel />Interaction wake
wake: 'interaction' is the laziest schedule. The island ships no JavaScript until someone uses it. A press, a key or focus inside it wakes it, and the interaction that woke it isn’t lost:
- The first click counts. ogygia holds the click while the island wakes and replays it once the island is live, so a button, a checkbox or a link fires exactly once.
- Typed text stays. Characters land in the field as usual, because it’s real HTML. After hydration, the value, the selection and the focus are put back, and
bind:picks them up. - Hover warms it. When the pointer enters the island, its code starts downloading, so by the time the press lands, the wake is usually immediate.
Click the button below. It has no JavaScript until you do, and your first click still counts.
What a replayed click can’t do
The replayed click isn’t a trusted browser gesture (event.isTrusted is false). So browser features that need a real gesture, like window.open, the clipboard and fullscreen, refuse it. A component that ignores untrusted clicks (if (!event.isTrusted) return) ignores the replay too, so narrow such a check.
hydratedBy() from ogygia tells a component which schedule woke it. It returns 'interaction' when a visitor’s input woke the island (an interaction island, or a scheduled one pressed before it was live, whose click is replayed too), and the schedule otherwise. An island nested in another hydrates with its parent, so it gets the parent’s schedule. It returns null on the server and on csr = true pages. Call it during setup, like getContext.
Use it to render a real link instead of calling window.open. Keep gesture-gated actions off interaction; counters, carts, menus, forms and editors all work fine on it.
<script>
import { hydratedBy } from 'ogygia';
let { url } = $props();
const replayed = hydratedBy() === 'interaction';
</script>
{#if replayed}
<a href={url} target="_blank" rel="noopener">Open</a>
{:else}
<button onclick={() => window.open(url)}>Open</button>
{/if}Early clicks
The click replay isn’t only for interaction. A load, idle, visible or media-query island is server HTML with no handlers until it wakes. A press on it before then wakes it at once, and the click is replayed when it’s live. A Ctrl, Cmd, Shift or middle click on a link opens it the way the browser normally would.
While an island is starting, its click goes to the island and nothing else. ogygia holds it from the page’s own click listeners too (a document listener that closes a menu on an outside click, click analytics), so no listener sees it twice. They hear it once, as the replay, when the island is live. So a page listener hears an early click late, and untrusted. Only a listener that runs before ogygia’s hears the original press: one on window in the capture phase, or one on document in the capture phase added before ogygia started. If the island fails to wake, ogygia gives the click back to the server markup.
Visible margins
visible uses an IntersectionObserver, by default with no margin: the island wakes as it enters the viewport. A margin starts it earlier, so it’s ready by the time it’s on screen.
Set a default for the whole app with ogygia({ visible: { margin } }). For one import, put margin in a preset. margin isn’t allowed inline in with { … } (region_attribute_unknown). A held region’s schedule function can return a margin too.
import { sveltekit } from '@sveltejs/kit/vite';
import { ogygia } from 'ogygia/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [
ogygia({
visible: { margin: '100px' },
presets: {
chart: {
wake: 'visible',
margin: '400px'
}
}
}),
sveltekit()
]
});<script>
import Chart from '$lib/Chart.svelte' with {
preset: 'chart'
};
</script>
<Chart />Downloads
The schedule decides when an island’s code downloads, not only when it runs. None of this needs configuration:
- No island code moves before your hero has arrived. Every wake except
interactionwaits until the page has painted and every image or preload you markedfetchpriority="high"has loaded. That’s your LCP image, and ogygia doesn’t guess it. The visitor’s first click or key ends the wait at once, and so does a 2.5 second cap. A page with no marked image waits only for the paint. - Downloads are queued by who’s waiting. An island or hole on screen downloads at normal priority. One that isn’t on screen yet (an
idleisland, avisibleone a screen away, a hole’sprefetch) and the router’s page prefetch download at low priority, a few at a time, so they never crowd out what the visitor sees. Something that scrolls into view moves up the queue. A click never waits, and neither does a hole’s HTML on screen. - An island’s whole module graph downloads at once. The page carries each island’s list of files as data. At the wake, the runtime adds a
<link rel="modulepreload">for each file the island needs, so the browser fetches them in parallel instead of finding each import only after the last one has parsed. - An island that never wakes downloads nothing. A
visibleisland fetches when it nears the viewport, anidleone in idle time, a media-query one when the query matches, and aninteractionone on the first hover, focus or touch.
On a csr = true page, Kit hydrates the islands instead of the runtime, so a load island keeps a fetchpriority="low" modulepreload hint at the end of the body.
In the examples, the hero image is marked fetchpriority="high", once on an <img> and once as a preload for a CSS background or a <picture>, so island downloads wait for it.
<img
src="/hero.jpg"
fetchpriority="high"
alt="The harbour at dawn"
/><!-- for a CSS background or a <picture> hero -->
<svelte:head>
<link
rel="preload"
as="image"
href="/hero.jpg"
fetchpriority="high"
/>
</svelte:head>Props and styles
Props come after the content. Each island’s serialized props sit at the end of the body, in one <script type="application/ogygia-props"> per distinct island, never in the middle of the content. The page seed (page.data for islands that read it) comes last, and only when an island on the page reads it. A load hole’s request starts in the head instead, because it fetches content, not code. When the response has a Content Security Policy that would block that small inline script, ogygia adds its hash to the policy.
Props don’t repeat what the seed carries. When the seed ships, a prop that is also part of page.data (the same object, or a copy) becomes a short path into the seed instead of a second copy. The island still gets its own copy when it wakes, so changing it never reaches the seed or another island. A CMS page that hands twelve blocks their slices of one content tree ships the tree once, plus twelve paths. With dataShake(), the seed carries only the page.data keys your islands read.
Each island’s CSS is linked only when it renders. On a csr = false page, the server links a stylesheet for each island that actually rendered, and nothing for the rest. A marked import the page never places, or the other blocks of a registry, cost no stylesheet and no download hint. Kit’s own links cover the page’s and layouts’ styles. Kit’s inlineStyleThreshold applies to island styles too: a sheet under the threshold ships as a <style> in the head instead of a blocking <link>, so many small island sheets cost no requests before the first paint.
Nesting
To find out what a nested region does, walk up the tree: the closest marked parent decides.
| Nesting | What happens |
|---|---|
| Island on the page | Gets its own JavaScript. |
| Island inside an island | Hydrates with its parent, as one tree. Its own schedule is ignored. |
| Lake inside an island | Stays static HTML. Its code never ships. |
| Island inside a lake | Gets its own JavaScript again, and wakes on its own schedule. |
| Server island inside an island | Renders inline as static HTML, like a lake. render: 'deferred' is ignored. An island inside it wakes alone. |
| Island inside a server island | Gets its own JavaScript and wakes after the hole’s HTML lands. |
| Island inside a server island’s fallback | A full island of the page, waking on its own, even when the fallback is kept. |
| Server island inside a live snippet | Stays deferred: its fallback ships, and its HTML arrives on its schedule. |
Dev warns when it ignores a schedule (nested_island_with_parent) or renders a server island inline (nested_server_island_inline). To give a nested island its own schedule, put a lake between it and its parent.
page → island → lake → island → …Do and don’t
- Do use
visiblefor islands below the fold. - Do use
idlefor UI people don’t touch right away, andinteractionfor UI most never touch. - Do mark your hero image
fetchpriority="high". - Don’t use
interactionfor a button that opens a window or copies to the clipboard. - Don’t try to make a
render: 'deferred'region interactive withwake. Nest awakeisland inside it.