How the engine behind every loader turns a pattern into lit dots, from a JSON scene to a baked track, and the four ways it draws them.
Engine · 4 min read
Every loader on this site runs on one engine: the dot-matrix item. It is a React component. Install it once. Then each loader is one <DotMatrix> with a few props.
npx shadcn@latest add https://dotsengine.dev/r/dot-matrix.jsonimport { DotMatrix } from "@/components/ui/dot-matrix/dot-matrix";
export function Saving() {
return <DotMatrix pattern="radar" lattice="circle" size={24} aria-label="Saving" />;
}The item installs into one dot-matrix/ folder in the ui folder that components.json names: components/ui/ in Next.js, src/components/ui/ in Vite and TanStack Start. It needs @ui-sdk/core and @ui-sdk/react, and the CLI installs them for you.
What you choose
You decide what the dots draw, where they sit, how they look and move, and what state they show. Each choice has its own page.
| You choose | Props | Read |
|---|---|---|
| What the dots draw | pattern | Built-in patterns |
| Where the dots sit | lattice, look.dot, look.grid | Layouts and dots |
| The color | color, look.colors, look.glow | Colors |
| The movement | value, look.speed, look.morph | Motion |
| The state | state, active, enter | Loading states |
Every prop, with its type and default, is in the DotMatrix API.
The same engine draws all of these. Only the props change:
From a pattern to dots
A pattern is plain JSON. We call it a scene. The engine turns a scene into dots in four steps:
- Compile. Each node of the scene becomes a small function. It gives the light of one dot at one time.
- Bake. The engine samples every dot 30 times a second, for one loop. It keeps the result as bytes, one byte for each dot in each frame. We call this a track.
- Draw. A renderer reads the track and draws the frame for the current time. It never runs the scene again.
- Morph. When the pattern, the lattice or the color changes, each dot moves from the old track to the new one. Nothing cross-fades.
A worker thread does the bake, so your page stays free. The loop starts when the bake is done. All loops follow the page clock, so two loaders with the same pattern move in step.
Server rendering
The component file starts with "use client", so it works in the Next.js App Router and in TanStack Start.
- First frame on the server. The server renders the first frame as plain dots. The loader shows before any script runs.
- No layout shift. The root box gets its width and height from
sizeand the lattice. Nothing moves when the script takes over. - Same frame in both places. Random parts of a pattern use a fixed hash. The server and the browser compute the same first frame, so hydration matches.
- Hand over. In the browser, the renderer mounts a layer over the first frame, then removes the server dots.
Pass only data from a server component: a pattern name, a scene, a lattice, colors. A renderer is a set of functions. Set it inside a client component.
Four ways to draw
A renderer only reads tracks. So you can change the renderer and keep the same pattern.
| Renderer | Item | Use it for |
|---|---|---|
| Canvas (default) | dot-matrix | Most loaders. One canvas each, drawn from shared sprites. |
| DOM | dot-matrix-dom | Small loaders that must move while the main thread is busy. The compositor runs their Web Animations. |
| SVG | dot-matrix-svg | One SVG per loader, with gradient halos and no filters. It installs dot-matrix-dom too. |
| WebGL | dot-matrix-webgl | Large fields and pages with many loaders. All of them share one WebGL2 context. |
npx shadcn@latest add https://dotsengine.dev/r/dot-matrix-webgl.jsonimport { webglRenderer } from "@/components/ui/dot-matrix-webgl/dot-matrix-webgl";
import { DotMatrix } from "@/components/ui/dot-matrix/dot-matrix";
<DotMatrix pattern="plasma" size={240} renderer={webglRenderer} />;The other renderers are domRenderer from dot-matrix-dom/dot-matrix-dom, svgRenderer from dot-matrix-svg/dot-matrix-svg, and canvasRenderer from dot-matrix/dot-matrix-canvas.
Screen readers
The loader is an <output>. Its name says what the pattern means:
| Pattern | Name |
|---|---|
| A loop | "Loading" |
check, or a scene with outcome: "success" | "Done" |
cross, or a scene with outcome: "failure" | "Something went wrong" |
- Pass
aria-labelto say what loads, such as "Uploading photo". - Pass
aria-hiddenwhen text next to it already says it. - Pass
messagesto change the three names, for example in another language. - When
patternchanges to one with an outcome, a screen reader hears the outcome once.
The loop runs only while the loader is on screen and the tab is visible.