Mochi

I built a toast library. The world probably didn’t need another one, but I had a specific idea for what a toast could feel like, and nothing else matched it.

Mochi is a gooey toast library for React. Each toast is a blob that morphs, breathes, and pulses. It’s built on Base UI’s Toast primitive, which handles accessibility, focus management, and swipe to dismiss. Everything on top of that, like the gooeyness and animations, is Mochi.

The demos on this page rebuild each behavior from scratch without Base UI, so you can try one decision at a time.

Gooey

The core idea is that a toast should feel alive.

Each toast is an inline SVG with two shapes: a pill (the header) and a body (the expandable description). An SVG gooey filter combines them into one organic shape. When the toast expands, the shapes overlap and the filter morphs them into a continuous blob - something you can't pull off with CSS border-radius.

The filter works in three steps. A Gaussian blur softens both shapes into a blobby mass (tied to corner radius, so rounder toasts get softer edges). Then a color matrix cranks the alpha contrast with values 0 0 0 20 -10, snapping soft edges back to hard and creating that metaball look. Finally a composite step draws the sharp original shapes back on top, so only the joins melt. The text and icons sit in HTML above the SVG and never go through the filter, so they stay crisp.

The filter also acts as a kind of co-designer. Where the pill meets the body, it pulls in a curve I never drew. Hover or tap the demo below to open both toasts: the same two shapes, with and without the filter.

Both shapes animate with transforms instead of width and height: scaleY for the body, scaleX for the middle of the pill. Transforms are the most reliable thing to animate on SVG elements; not every browser will transition width or x on a <rect>. The filter doesn't get skipped, though. Transforms on shapes inside the filtered group are applied before the filter, so the blob is melted again on every frame. That's the point: it's what keeps the pill and body fused while they move. There's still no JavaScript animation loop. React sets the target transform, a CSS transition animates it, and the filter just re-renders.

Expanding

Toasts with a description expand when you hover them with a mouse and collapse when you leave. On a touchscreen there's no hover, so a tap toggles them, and on a keyboard Enter or Space does. Loading toasts are the exception - they never expand, to avoid visual noise while something's still in progress. The first demo ignores you until it says "Saved".

Hover works here because expanding doesn't change any state. It just shows more info. Instant feedback, no commitment. A mouse click does nothing, since hovering already did the work.

Under the hood, React computes every transform from the open/closed state and sets it inline, and CSS transitions with spring easing animate between them. React owns the state, CSS owns the motion. Collapsing is faster (250ms) than expanding (600ms).

One tricky bit: the body's height has to stay stable throughout the collapse. If it changed mid-transition, the scaleY target would shift and the toast would visually jump. Mochi used to freeze the expanded height into a ref while open. Now the description stays rendered while collapsed, just invisible, so its height never changes and there's nothing to freeze.

Position

From a single position prop (like "top-left"), three behaviors cascade:

Pill alignment. The pill aligns to the screen edge: right-aligned for right-edge positions, left-aligned for left, centered for center. A bottom-right toast's pill sits close to the screen edge, feeling like a natural extension of the UI chrome.

Expand direction. Bottom toasts expand upward. Top toasts expand downward. The pill stays anchored to the screen edge. The body scales from its edge-side end, so expansion always pushes away from the edge.

Text alignment. The description text follows the pill's alignment: right-aligned for right-edge positions, centered for center. Left-aligned description text under a centered pill looks off-balance, so the text follows the same spatial anchor.

Try moving the dot grid below - the pill alignment, expand direction, and text alignment all shift together.

Moving between positions needs one rule: collapse before travel. If the toast moved while open, the body would flip direction and alignment mid-flight. So it collapses first, switches position while the body is tucked inside the pill, travels, and expands when it arrives. The jumps happen where you can't see them. After each move it peeks open for a moment, then settles back to a pill.

Spring

All animations use a single CSS spring easing curve: a linear() function with 33 stops that approximates a spring. It settles at about 85% of its duration, so I pair it with 600ms.

--ease-spring: linear(
  0, 0.002 0.6%, 0.007 1.2%, ...
  1.028 46.3%, 1.026 51.9%,
  1.01 66.1%, 1.003 74.9%, 1 85.2%, 1
);

JavaScript would have worked too: Framer Motion has real springs, and the Web Animations API accepts linear(). I chose CSS transitions because they're naturally interruptible: hover and unhover quickly, and the animation just reverses from wherever it is. And React only sets target values, so there's no animation loop and no coordination code. The trade-off is that a linear() spring has a fixed duration and doesn't carry its velocity when interrupted, the way a physics spring does.

For users who prefer reduced motion, all animation durations drop to near-zero via a prefers-reduced-motion: reduce media query. In the position demo the toast doesn't travel at all: it fades in at its new spot.

Crossfade

When a promise toast goes from loading to success, the header crossfades. The old text blurs out while the new text blurs in.

Two layers: when the title changes, the current content becomes the "previous" layer with a blur-out animation (150ms). The new content enters with a blur-in (600ms, spring easing).

I use blur instead of a plain opacity fade because with opacity you can read both labels during the overlap, which looks like a bug. Blur makes the old text unreadable immediately, so the overlap feels intentional - like one label morphing into the other. Press replay on the first demo and watch the header - it starts as a loading spinner, then crossfades into the success state.

The pill morphs to the new width at the same time. It's built from two round caps and a straight middle that scales sideways, so even the width change is a transform.

Dedup

This one was important to get right.

Without dedup, every toast.success({ title: "Saved" }) creates a new toast. Mochi shows one toast at a time, so each new one pushes the old one out: an exit and an entrance for a message that didn't change. Click Save a few times.

Without dedup
0 toasts created
With dedup
0 toasts created

With dedup, a repeat updates the toast that's already showing. The dismiss timer restarts and the toast pulses instead of being replaced.

When I wrote Mochi, Base UI had no way to do this, so Mochi did it itself. It built a fingerprint from type:title and kept a map of the toasts on screen. If a matching toast was showing, it reset the timer and played the pulse.

The fingerprint uses type and title because both are always strings. Description is a ReactNode which can contain JSX and can't be reliably compared, so it's excluded.

The hardest part was cleanup: with one-toast mode, old toasts are visually dead before their removal callbacks fire. During that window, dedup logic would try to update a ghost toast. The fix was to eagerly clear all dedup state before creating any new toast, with onRemove as a safety net for other dismiss paths like swipe and timeout.

Base UI 1.4 made most of that unnecessary. If you add a toast with an id that already exists, Base UI updates that toast in place and restarts its timer. If the toast is already on its way out, it's replaced with a fresh one, which is exactly the ghost case. The fingerprint becomes the id, and the map and the cleanup code can go:

toastManager.add({ id: `${type}:${title}`, type, title, description });

Pulse

When a repeat lands on a toast that's already showing, the toast scales to 1.03 and back over 400ms. Small, but noticeable. It's the breathe you saw in the dedup demo.

One problem: CSS animations don't restart when you set the same attribute again. The browser sees no change. My fix was to force a reflow with void el.offsetWidth between removing and re-adding the animation attribute, so the removal was committed before the re-add.

Base UI now gives every toast an updateKey that goes up each time the toast is updated. Two animation names with the same frames, picked by whether the key is odd or even, give the browser a new animation every time. No reflow needed:

// New toasts start at 0, so the first add plays the entrance, not the pulse.
const pulse = toast.updateKey % 2 === 0 ? "animate-toast-pulse-a" : "animate-toast-pulse-b";

Credit

I want to be clear about what I didn't build. Base UI's Toast primitive handles all the accessibility (ARIA live regions, screen reader announcements, F6 landmark navigation), swipe-to-dismiss, lifecycle management, and the base components. It's well-documented and battle-tested. I use it directly.

Everything else I described - the gooey SVG rendering, the pill-and-body shapes, position-aware alignment, the crossfade, pulsate - that's what Mochi adds on top. Dedup used to be on that list. Base UI does it now, and Mochi gets to be smaller.

Why

The toast space is crowded. Sonner exists and it's great. Beautiful animations, millions of downloads. The right choice for most projects.

Mochi exists because I wanted to explore a different visual direction. The SVG gooey filter is the entire premise. Every decision - the pill-and-body shapes, transforms over width and height, collapse before travel, the blur crossfade - flows from that one visual idea.

Sometimes the best reason to build something is that you can see it clearly in your head and it doesn't exist yet.