Regions
Regions
Every marked import becomes a region, a part of the page with its own rule for where its HTML comes from and when its JavaScript runs. Client islands, server islands, lakes and held regions are four settings of that one idea.
The parts of a real page want different things. A menu needs JavaScript. A greeting that names the visitor has to be rendered for each request. A long block of prose inside an interactive widget should never reach the bundle. A search result may be a component the server picks at runtime.
ogygia handles all of these with one idea, the region: a part of the page with its own rule for where its HTML comes from and when it wakes up. You make one by adding import attributes to a component import, or, for a held region, by calling region(). The tag in your markup doesn’t change.
Every kind is wrapped in the same <ogygia-region> element, and every kind whose HTML comes later is fetched from the same signed endpoint, so there is one way to hydrate, one way to sign a request and one way to pass props. Once you know how one kind behaves, the others work the same way with different settings.
<script>
import Menu from '$lib/Menu.svelte' with { wake: 'load' };
import Greeting from '$lib/Greeting.svelte' with {
render: 'deferred'
};
</script>
<Menu />
<Greeting />Render and wake
Three import attributes set a region’s behavior. Each answers one question:
| Attribute | Question | Values |
|---|---|---|
render | Where does the HTML come from? | 'static' (default): rendered in the page’s own server pass · 'deferred': fetched from the server later · 'live': rendered in the page, then refreshed when the island around it mounts it again |
wake | Does it ship JavaScript, and when does it run? | 'load' · 'idle' · 'visible' · 'interaction' · a media query · 'none' (never: a lake) |
fetch | When does a deferred region’s HTML arrive? | 'load' (default) · 'idle' · 'visible' · 'interaction' · a media query |
wake and fetch share one set of timing words, explained in Timing and nesting. A deferred region has no JavaScript of its own, so it takes fetch, never wake. Writing both fails the build (hole_wake_removed), and so does fetch without render: 'deferred' (region_import_invalid). render: 'static' on its own marks nothing and fails the build too (region_import_invalid): it’s what you get when you leave render out.
render: 'live' goes on a lake inside an island, so it belongs in the island’s own file. With render: 'live', wake is when the lake refetches its HTML; it ships no JavaScript. Lakes shows it.
In the example, the page places a chart that wakes when it scrolls into view and an unread count the server fills when the browser is idle. Sidebar is an island that wakes at once, and inside it Ticker is a live lake and Prose a plain one.
<script>
import Chart from '$lib/Chart.svelte' with {
wake: 'visible'
};
import Unread from '$lib/Unread.svelte' with {
render: 'deferred',
fetch: 'idle'
};
import Sidebar from '$lib/Sidebar.svelte' with {
wake: 'load'
};
</script>
<Chart />
<Unread />
<Sidebar /><script>
import Ticker from '$lib/Ticker.svelte' with {
render: 'live',
wake: 'idle'
};
import Prose from '$lib/Prose.svelte' with { wake: 'none' };
</script>
<Ticker />
<Prose />Region kinds
Each kind is one setting of those attributes, or a call to region():
| Kind | You write | What it is |
|---|---|---|
| Client island | with { wake: 'visible' } | Rendered in the page’s server pass, then hydrated on a schedule. Use it for anything interactive. |
| Server island | with { render: 'deferred' } | A hole in the page that the server fills on each request. It can be personal, and it ships no JavaScript. |
| Lake | with { wake: 'none' } | Static HTML inside an island, kept out of the island’s bundle. With render: 'live', it refreshes. |
| Held region | region(Card, props) | A region as a value: made in a load or a remote function, sent over the wire, placed with <Region of>. |
Markup you don’t mark isn’t a region at all. It’s plain server HTML compiled into the page, which is the default and the cheapest thing you can ship. Children and snippets you pass into an island are one more shape: they cross as regions, as Snippets explains.
Other attributes
A few more attributes adjust a region. They go in the same with { … }, except preset and region: 'raw', which must each be the only attribute on their import:
keep: 'name': the island keeps its live state across SPA navigations instead of remounting. It needs awake: on a hole or a lake it fails the build (region_import_invalid). See Persistent islands.preset: 'name': use a named bundle of settings fromogygia({ presets }). Presets also hold the options that aren’t allowed inline, such asmarginandmaxAge. Seepresets.prefetch: warm a deferred region’s HTML before itsfetchmoment. Withoutrender: 'deferred'it fails the build (region_import_invalid). See Server islands.region: 'raw': a held region with no schedule of its own. See Held regions.stitch: render a deferred region into a stored page as it is served.'serve'fills the hole on your server each time the stored page is served;'edge'writes an ESI include (an edge-side include tag) for your CDN to fill, so the stored page stays cached at the edge. In a preset,truemeans'serve'. Withoutrender: 'deferred'it fails the build (region_import_invalid). See Personalization.
Any other key on a .svelte import fails the build with the list of keys it takes (region_attribute_unknown). Keys on other imports, like with { type: 'json' }, are left alone. If another tool already uses these names, ogygia({ importKeys }) renames wake, fetch, render, preset and region in your with { … } clauses. Preset definitions keep the standard names (wake, render, fetch).
In the example, the config defines two presets, and the page places a chart that uses one and a player kept across navigations.
import { sveltekit } from '@sveltejs/kit/vite';
import { ogygia } from 'ogygia/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [
ogygia({
presets: {
chart: { wake: 'visible', margin: '200px' },
pricing: {
render: 'deferred',
fetch: 'load',
maxAge: '1h'
}
}
}),
sveltekit()
]
});<script>
import Chart from '$lib/Chart.svelte' with {
preset: 'chart'
};
import Player from '$lib/Player.svelte' with {
wake: 'load',
keep: 'player'
};
</script>
<Chart />
<Player />Guarantees
The settings vary, but every kind keeps the same promises:
- Server HTML first. A client island or a lake renders its real HTML on the server, and its JavaScript attaches to that HTML instead of replacing it. A server island renders its fallback, and its HTML arrives once JavaScript runs.
- One hydration. A region hydrates once and adopts its server DOM in place, with no flash. A region nested in an island joins that island’s hydration.
- Signed requests. Every later fetch of a region’s HTML goes through an endpoint guarded by a signature made at render time. The browser holds a ticket for one region, not an open door to render any component.
- Props cross by value. Props are serialized into the page, so a prop has to be data, and state that must stay live lives inside the region. Pass data into an island lists what crosses.
Rules
The marks are static: the build reads them, so a mark can’t come from a variable, and a dynamic import() with region attributes fails the build (dynamic_region_import). To load a component on click, gate a marked import with {#if}, or use a plain await import() inside an island.
A mark goes on a component you place, so import * as ui (region_import_namespace), import type (region_import_type_only) and a dotted tag like <Menu.Item> (region_dotted_tag) can’t take one. Import the component itself by name.
These two pages apply to every kind:
- Timing and nesting: the schedules, and what happens when regions sit inside each other.
- Constraints: what crosses a region’s boundary and what doesn’t.
Most pages start with a client island, so read Client islands next.