## Demo: hydration ### Hydration.svelte ```svelte

No directive

Pure SSR — no client JavaScript is shipped for this component. It renders on the server and is inert in the browser. Best for content that never needs interactivity.

mochi:hydrate

Eager hydration — the island ships and boots immediately when the page loads. Use for above-the-fold UI that needs to be interactive right away.

mochi:hydrate:visible

Lazy hydration — the bundle and CSS are only fetched once the island scrolls into view (via an IntersectionObserver). The card below stays inert until you scroll it into the viewport.

↓ Scroll down ↓

mochi:hydrate:visible

You can pass IntersectionObserver options — here rootMargin: '200px' starts hydration a bit before the island is actually in view.

`} />

mochi:defer

Server island — the component is not in the initial page. A placeholder ships, then the browser fetches the rendered HTML on demand. Pair with hydrated child components to also hydrate parts of the island after it loads.

Loading from server…
``` ### HydrationTarget.svelte ```svelte
{label} {isBrowser ? 'hydrated' : 'server-rendered only'}
rendered at {renderedAt}
{#if !isBrowser}

This button won't work since the component is not hydrated!

{/if} {@render children?.()}
``` ### routes.ts ```ts import { Mochi } from 'mochi-framework'; import type { MochiRouteValue } from 'mochi-framework'; export const routes: Record = { '/demos/hydration': Mochi.page('./src/demos/hydration/Hydration.svelte'), }; ``` ### index.ts ```ts import { Mochi, logger } from 'mochi-framework'; await Mochi.serve({ port: 3333, development: process.env.MODE === 'development', routes: { '/': Mochi.page('./src/Home.svelte'), }, }); logger.info('Server running at http://localhost:3333'); ```