🍡 mochi

Cancelling

Two cancellation paths: cancel() short-circuits before the fetch; controller.abort() stops an in-flight request. Both leave the form in a clean idle state.

The action sleeps 3 seconds to simulate a slow lookup. With {@attach enhance(...)}, submitting the same query twice calls cancel() — the fetch never fires. The visible "Cancel" button calls controller.abort() to stop the in-flight request. Without enhancement, it is a plain POST that waits for the server.

With {@attach enhance(...)}

Search, then search the same query again (cancel) or click Cancel while searching (abort)

Plain HTML

Plain POST — waits the full 3 s, page re-renders with the result

<script lang="ts">
  import LookupDemo from './LookupDemo.svelte';
</script>

<p>
  The action sleeps 3 seconds to simulate a slow lookup. With <code>{'{@attach enhance(...)}'}</code>, submitting the same query twice calls <code>cancel()</code> — the fetch
  never fires. The visible "Cancel" button calls <code>controller.abort()</code> to stop the in-flight request. Without enhancement, it is a plain POST that waits for the server.
</p>
<h3>With <code>{'{@attach enhance(...)}'}</code></h3>
<LookupDemo label="Search, then search the same query again (cancel) or click Cancel while searching (abort)" mochi:hydrate />
<h3>Plain HTML</h3>
<LookupDemo label="Plain POST — waits the full 3 s, page re-renders with the result" />
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>