Form Errors
The action throws a plain Error. With the enhance attachment, the error message is shown inline; without it the server renders the Mochi error page.
The action throws a plain Error. With {@attach enhance(...)} the error message is shown inline. Without it, the server renders the Mochi error page.
With {@attach enhance(...)}
The enhance attachment catches the thrown error and shows it inline
Plain HTML
Plain POST, server throws, Mochi renders the error page (press back to return)
<script lang="ts">
import ErrorDemo from './ErrorDemo.svelte';
</script>
<p>
The action throws a plain <code>Error</code>. With <code>{'{@attach enhance(...)}'}</code> the error message is shown inline. Without it, the server renders the Mochi error page.
</p>
<h3>With <code>{'{@attach enhance(...)}'}</code></h3>
<ErrorDemo label="The enhance attachment catches the thrown error and shows it inline" mochi:hydrate />
<h3>Plain HTML</h3>
<ErrorDemo label="Plain POST, server throws, Mochi renders the error page (press back to return)" />
Styles
<style>
h3 {
margin: 1.5rem 0 0.25rem;
font-size: 0.95rem;
font-weight: 600;
color: var(--text-muted);
}
p {
margin: 0 0 0.5rem;
font-size: 0.9rem;
color: var(--text-muted);
}
code {
background: var(--code-bg);
color: var(--code-accent);
padding: 0.05rem 0.35rem;
border-radius: var(--radius-sm);
font-family: var(--font-mono);
font-size: 0.85rem;
}
</style>
More demos
Server Island Component that renders on-demand after the page is delivered. Using form return data An action returns a value via success({...}); {@attach enhance(...)} updates the UI in place, plain HTML re-renders the page. Cancelling cancel() skips the fetch entirely; controller.abort() stops a request mid-flight.