Real-time Chat
An example of building a simple in-memory chat using a hydrated island and the built-in WebSocket support in Bun. The server stores a bounded message history and replays it to new connections; ws.publish() broadcasts each message to all clients. Messages over 4 KB are rejected, frames over 8 KB are dropped by Bun before they are buffered, and a per-client window closes anyone sending more than 20 messages per 10 seconds. Open this page in two tabs to see them sync in real time.
Chat
<script>
import ChatWidget from './ChatWidget.svelte';
</script>
<ChatWidget mochi:hydrate />
More demos
Server Islands How server islands work — components marked mochi:defer render server-side on demand after the initial page is delivered. Form Errors How form action errors work — a thrown action error shows inline via {@attach enhance(...)}, or as the Mochi error page on a plain submit. Protection Mode How protection mode works — a Cloudflare-style browser check where an interstitial auto-solves the captcha proof-of-work and redeems it for a clearance cookie.