---
title: "Boing"
description: "Toasts that spring and morph in place instead of stacking"
canonical: "https://aayushbharti.in/projects/boing"
last-updated: "2026-11-16"
---

# Boing

> Toasts that spring and morph in place instead of stacking

A React toast library where one toast springs, squashes and morphs in place on real spring physics, instead of a pile stacking up in the corner.

- Type: Library
- Role: Library Author & Designer
- Tech: react, typescript, web-audio-api, nextjs, tailwindcss, vitest, tsup, playwright, pnpm
- Published: 2026-11-16
- Live: https://boing.aayushbharti.in
- Repo: https://github.com/aayushbharti/boing
- URL: https://aayushbharti.in/projects/boing

**TL;DR:** Boing (react-boing on npm) is a toast notification library for React with zero runtime dependencies. One toast morphs in place as the app changes state, driven by a mass-spring-damper solved every frame, with the same springs baked into CSS linear() easings for the stack. It is written in TypeScript with a framework-free core, tested with Node's test runner and Vitest, and documented on a Next.js site with a playground.

## Highlights

- One toast that morphs in place instead of stacking
- Spring physics with squash and stretch
- A late async result can't overwrite a newer toast
- On npm, with docs, 11 guides and a playground

---
## A loading toast and its result should be the same toast

Every app I've built fires a toast for a save, then another one when the save finishes. Most libraries show that as two toasts: a spinner, then a success stacked on top of it or swapped in with a fade. The thing on screen changed state, so I wanted the toast on screen to change shape with it.

So Boing keeps one toast and morphs it. It arrives as a 44px circle, opens sideways into a pill with the message, and when the next call comes in, width, height, icon and text move to the new content together. The film above runs through every type on the live site; the Try it row on [boing.aayushbharti.in](https://boing.aayushbharti.in) is the fastest way to feel it.

---

![Boing's home page: the headline Toasts that feel alive, an npm install command, Read the docs, and a Try it row with Success, Error, Promise, Undo and Progress](/projects/boing/home-e9aca27d.webp)

---

```mermaid
flowchart LR
    subgraph App["Your app"]
        CALL["toast.success()<br/>toast.promise()"]:::cyan
        T["&lt;Toaster /&gt;<br/>react/Toaster.tsx"]:::cyan
    end
    subgraph Core["packages/react-boing/src/core"]
        STORE["store.ts<br/>phases, owners, held modes"]:::blue
        BIND["bind.ts<br/>pill morph, text roll, drag"]:::violet
        MOTION["motion.ts<br/>frame-loop springs"]:::violet
        SPRING["spring.ts<br/>springEasing → linear()"]:::amber
        STYLES["styles.ts<br/>one injected style tag"]:::amber
        SOUND["sound.ts<br/>Web Audio chime"]:::green
    end
    DOCS["apps/docs<br/>Next.js 16, imports src"]:::green
    CALL --> STORE
    T -- "useSyncExternalStore" --> STORE
    T --> BIND --> MOTION
    STYLES --> SPRING
    STORE --> SOUND
    DOCS --> T
```

`store.ts` is the only source of truth: the `toast` API, a subscribe/getState pair, and the lifecycle each toast walks through (`enter`, `open`, `closing`, `exit`, at 450ms, 340ms and 220ms). It knows nothing about React or the DOM, so the core tests run on Node's built-in runner with no browser at all.

`<Toaster />` subscribes through `useSyncExternalStore` and renders one slot per toast. Everything that moves lives in `bind.ts`, which owns the pill's DOM once React has rendered it. React decides what's on screen; it never sees a single animation frame.

Styles are one `<style>` tag the package injects at runtime, with a `nonce` prop for strict CSPs. That's why there's no stylesheet to import, and it lets the stack's easing be generated from the same spring numbers as the JavaScript motion.

**Server components and the docs site**

The package never touches `window` or `document` at import time, and `ssr.test.ts` imports it under plain Node to keep it that way. The build adds a `"use client"` banner, so `<Toaster />` can sit in a server component layout in Next.js.

The docs site at boing.aayushbharti.in maps `react-boing` to the package's TypeScript source through `tsconfig` paths, so a library edit shows up on the site without a rebuild. Every docs and guide page is a typed record that generates the HTML page, its JSON-LD, a Markdown twin and its `llms.txt` entry.

---

## Springs that keep their momentum

A CSS transition interrupted halfway starts again from where it is, at zero velocity. For a toast that's about to change shape again, that reads as a hiccup. So the pill's width, height and position are real springs: a mass, a stiffness and a damping, stepped with semi-implicit Euler in 1/240-second sub-steps on one shared `requestAnimationFrame` loop. A new target changes where the spring pulls, and the velocity it already had carries into the new shape.

The velocity also does the squash and stretch. Vertical speed divided by 6,000 stretches the pill along its path, capped at 18%, and width speed over 20,000 squashes it, capped at 5%. Those divisors came from trying values until a fast entrance looked like a rubber ball and a slow one didn't wobble.

The stacked slots behind the newest toast move with plain CSS instead, because there can be several and they only ever slide. `springEasing()` solves the same spring in closed form, finds when it settles within 0.001 of its target, and samples it 60 times per second of motion into a CSS `linear()` easing. The default spring (stiffness 170, damping 18) becomes 49 stops over 800ms. It's exported, so your own transitions can move on Boing's springs. This is the same function, ported line for line:

**Text that rolls, errors that shake**

When a toast's copy changes, the old text is cloned into a ghost element that rolls out over 280ms while the new text rolls in, with at least 450ms between two rolls so a burst of updates doesn't strobe. When loading turns into success, the new icon starts at the angle the spinner had reached and finishes the turn over 650ms, so the spin never jumps back to zero.

Each type has a reaction after it opens: an error gets a sideways kick of 380px/s into a stiff spring (stiffness 520, damping 13), and a warning hops 200px/s. Under `prefers-reduced-motion` every spring snaps to its end state and toasts fade instead.

---

Morphing one toast has a failure mode that stacking doesn't. Start a slow save, then a fast one. The fast save takes the toast and shows success. Then the slow one resolves, and a naive update would flip the toast back to "Draft A saved", which is now a lie about the most recent action.

The store keeps an `owners` map from each toast to the caller that last took it. Every `show` call gets a caller id, and `update(callerId, patch)` returns early unless that caller still owns the toast. `toast.promise` goes through `update`, so the slow promise still resolves for your code but leaves the toast alone.

```ts
const id = callers.get(callerId) ?? callerId;
if (owners.get(id) !== callerId) {
  return; // someone newer took this toast
}
applyPatch(id, patch);
```

**Repeats, held toasts and queues**

Calling the same toast twice adds a counter (×2) to the live one instead of a second toast, unless the call carries something that makes it distinct, such as an id, a button or an image.

Errors, loading toasts and toasts with a button stay until dismissed, which raises the question of what a quick "Saved" should do while an error is waiting. `held` answers it with three modes: `replace` (the default) morphs the held toast like any other, `list` keeps it and shows quick toasts beside it, and `queue` holds new calls until it's gone. `update` works on queued calls too, so a promise that settles while it's waiting shows its result when its turn comes.

---

![Boing playground: a preview stage with a Changes saved toast and an Undo button above an account settings card, and a settings panel for toast type, title, description and buttons](/projects/boing/playground-a002d7c5.webp)

---

## What I chose, and what it cost

| Chose | Over | Why | Cost |
|---|---|---|---|
| One toast that morphs | A stack of toasts, like Sonner | A state change reads as one thing changing, and nothing piles up in the corner. | Needed the owners map so stale results can't overwrite newer ones, and the held modes for errors. |
| Frame-loop springs for the pill | CSS transitions with a spring-shaped easing | Interrupting keeps velocity, and velocity drives the squash and stretch. | The pill writes `width` and `height` every frame, which means layout work while it moves. |
| CSS `linear()` for the stacked slots | Running them on the frame loop too | Several slots that only translate and scale; the browser can run them without JavaScript. | Two motion systems that have to agree, so both read the same spring numbers. |
| Styles injected from JavaScript | A CSS file to import | One install step, and the stack easing is generated from the spring config. | A runtime `<style>` tag, which strict CSPs need a `nonce` for. |
| Tones synthesized with Web Audio | Shipping audio files | No assets to host or load. Success rises (G4 to C5), error falls, warning taps twice. | Sound is off by default, and the first tone has to follow a click or key press (thanks, autoplay policies). |
| Zero dependencies | Motion or react-spring | Nothing extra in the bundle or the lockfile, and `spring.ts` plus `motion.ts` come to under 200 lines. | I own the integrator, its rest threshold and its edge cases. |

---

## What shipped, and what I'd change

What shipped: `react-boing` 0.1.0 on npm, 15 days after the first commit, as ESM and CJS with type declarations. Five toast types, `toast.promise`, in-place updates, undo actions that return a patch, progress bars, repeat counters, three held modes, six positions, light, dark and system themes, optional sound, and 131 tests across the core and the DOM. The docs site has the API reference, 11 guides, a playground that writes the code for the toast you build, and Markdown twins of every page for assistants.

The `width` and `height` writes are what I'd look at first. They're the honest cost of letting the text reflow naturally while the pill grows, and I haven't profiled them on a slow phone yet. If they show up there, the fix is to animate a clip and a scale and measure the text once, at the cost of the copy stretching mid-morph.

The store is a module-level singleton, so two `<Toaster />` instances in one app render the same toasts. That's right for most apps and wrong for a micro-frontend that wants separate regions. `createToaster()` already exists inside the core; exporting it with a store prop on `<Toaster />` is the next API change.

---

## Frequently asked questions

### What is Boing?

Boing is a toast notification library for React, published on npm as react-boing. A toast arrives as a small circle, opens sideways into a pill with its message and shrinks back before it leaves. A new call reshapes the toast already on screen instead of stacking another one, and all of it moves on spring physics. It has zero runtime dependencies and the gzipped build is about 15KB.

### How does Boing animate toasts with spring physics?

Boing runs a mass-spring-damper for the pill's width, height and position, integrated with semi-implicit Euler in 1/240-second sub-steps on one shared requestAnimationFrame loop. Because each spring keeps its velocity, interrupting a toast mid-motion carries its momentum into the new shape. The vertical and horizontal velocity also drive squash and stretch, capped at 18% and 5%.

### What does springEasing() in Boing do?

springEasing({ stiffness, damping, mass }) solves a damped spring in closed form, finds when it settles within 0.001 of its target, and samples it 60 times per second of motion into a CSS linear() easing. It returns that easing with a duration in milliseconds, so CSS transitions and the Web Animations API can move on the same spring as Boing. The default spring (stiffness 170, damping 18) gives 49 stops over 800ms.

### How is Boing different from Sonner or react-hot-toast?

Boing shows one toast by default and morphs it, so loading turns into success and an action turns into its confirmation in the same element, instead of a stack of separate toasts. The motion comes from a spring solver rather than fixed-duration curves. Identical repeat calls fold into a counter (×2), and three held modes (replace, list, queue) decide how errors and toasts with buttons share the screen.

### Does Boing work with the Next.js App Router?

Yes. The react-boing build ships a "use client" banner, so <Toaster /> can sit in a server component layout, and the package never touches window or document at import time, which a test checks. toast() and toast.configure() are called from client components.

### Is Boing accessible?

Boing announces toasts through two live regions that stay on the page, assertive for errors and polite for everything else. Escape dismisses, Alt+T moves focus into the toast and pauses its timer, and under prefers-reduced-motion the springs snap to their end state and toasts fade instead of moving. Layout mirrors on right-to-left pages.
