Mladich Sigil
Posts

Pretext library by Cheng Lou

03/04/2026
Typescript
Cool stuff
Problem solvers

When?

Cheng Lou just dropped Pretext, and it's one of those "why didn't I think of that" libraries that actually solves a real pain point.

If you've ever built virtual lists, masonry grids, or anything with dynamic text sizing, you know the DOM measurement trap: create an element, style it, measure it, throw it away. Repeat 100x and your frame budget is gone. Pretext says nah — it does pixel-perfect multiline text measurement and layout in pure JS/TS, zero DOM, ~15KB gzipped, no deps.

How?

Here's the flow: prepare('your text', '16px Inter') once upfront via Canvas to get glyph metrics and segments. Then layout(prepared, width, lineHeight) spits out height and line info in microseconds using straight math. Supports i18n, bidi, the works. Demos like shrink-wrap chat bubbles or masonry cards show it flexing on real UIs where DOM thrashing kills perf.

Cheng Lou (ex-React core, React Motion legend, now Midjourney) calls out the irony: browsers force reflow for something as basic as "how tall is this paragraph?" Pretext rejects that premise entirely — prep offline, layout anywhere (even SSR or workers). Viral for a reason: 16k stars in days, HN buzzing.

So?

gasg

The real magic is what it unlocks. Variable-height virtualization without jank, obstacle-aware text routing, editorial engines that feel native but run buttery. It's not hype; it's the kind of constraint-breaking tool that sticks around because it fills a gap nobody else touched.

If you're doing anything text-heavy in the browser, drop it in. Your hot paths will thank you.

Pretext library by Cheng Lou | A real problem solver | Alex Mladich