Hydratable
hydratable() runs once on the server; the hydrated island reads the same value from <head> on the client without re-running the async work. Watch the server console — the 'computing fact' line prints once per request, never on hydration.
Page (SSR-only)
Runs in the page's top-level script and is inlined into the rendered HTML.
SQLite 3.53.2, server time 2026-08-31 23:13:56
Island using hydratable()
Reads the SSR value out of window.__svelte.h on the client without re-running the work.
Island using a prop
Receives the value as a prop; Mochi serialises it into the island's HTML.
SQLite 3.53.2, server time 2026-08-31 23:13:56
<script lang="ts">
import { hydratable } from 'svelte';
import { Database } from 'bun:sqlite';
import { files } from './files.ts';
import FactCard from './FactCard.svelte';
import FactCardProps from './FactCardProps.svelte';
const sources = await loadSources(files);
// With hydratable, the result is serialized into <head>; the matching call inside the hydrated
// island below reads it back from window.__svelte.h instead of re-running this function on the client.
const fact = await hydratable('mochi-demo:fact', () => {
console.log('[server] computing fact via bun:sqlite (should print once per request)');
const db = new Database(':memory:');
const row = db.query("SELECT datetime('now') as now, sqlite_version() as version").get() as { now: string; version: string };
db.close();
return {
sqliteVersion: row.version,
computedAt: row.now,
};
});
</script>
<h3>Page (SSR-only)</h3>
<p class="hint">Runs in the page's top-level script and is inlined into the rendered HTML.</p>
<p class="row">SQLite <strong>{fact.sqliteVersion}</strong>, server time <code>{fact.computedAt}</code></p>
<h3>Island using hydratable()</h3>
<p class="hint">Reads the SSR value out of window.__svelte.h on the client without re-running the work.</p>
<FactCard mochi:hydrate />
<h3>Island using a prop</h3>
<p class="hint">Receives the value as a prop; Mochi serialises it into the island's HTML.</p>
<FactCardProps {fact} mochi:hydrate />
Styles
<style>
h3 {
margin: 1rem 0 0.25rem;
font-size: 1rem;
font-weight: 600;
}
.hint {
color: var(--text-muted);
font-size: 0.85em;
margin: 0 0 0.5rem;
}
.row {
margin: 0 0 0.5rem;
}
code {
font-size: 0.9em;
}
</style>
More demos
Image: Component How the <Image> component works — named sizes, ThumbHash blur-up placeholders, and encrypted deferred URLs whose transforms run lazily on the endpoint. View Transitions How view transitions work — drop <ViewTransitions /> into a layout to animate full-page navigations with zero JavaScript. Cancelling form submissions How cancelling form submissions works — cancel() stops the fetch before it fires; controller.abort() stops one mid-flight.