For decades, web developers have accepted a fundamental constraint: if you want to know how tall a block of text will be, you have to ask the browser. Render it to the DOM, call getBoundingClientRect(), and wait for the answer. This dance between JavaScript and the rendering engine has shaped everything from how we build virtualized lists to why certain UI patterns remain perpetually janky.
Cheng Lou thinks that era is over. His new library, Pretext, performs multiline text measurement and layout entirely in userland JavaScript. No DOM reads. No reflows. No architectural compromises that cascade through your component tree.
The Problem Pretext Solves
Text layout has been the final boss of web performance work. Every time you need to calculate heights for variable-content items, you're forced into expensive DOM operations that block the main thread. Developers have built elaborate workarounds: batching reads and writes, using ResizeObservers, caching measurements, or simply giving up and using fixed heights. None of these solutions are clean, and all of them leak complexity into application architecture.
Lou's background makes him unusually qualified to tackle this. He was an early React team member, worked on Messenger, created ReasonML and ReScript, and spent time at Midjourney. He describes the development process as "crawling through depths of hell," iterating against real browser measurements using Claude and CodeX over weeks to achieve pixel-perfect cross-browser fidelity.
The result is a library that measures text using the browser's Canvas font engine as ground truth, then performs all subsequent layout calculations as pure arithmetic. The hot path becomes a single linear traversal of cached data. According to Lou's benchmarks, this approach is up to 500 times faster than traditional DOM measurement, though he's quick to note that comparison is somewhat unfair since Pretext eliminates the read/write interleaving problem entirely.
What This Enables
The demos are striking. A masonry layout with 100,000+ variable-height text cards scrolling at 120fps. Shrinkwrapped chat bubbles that hug their content perfectly. Magazine-style multi-column layouts that flow around obstacles. These are UI patterns that have historically required either significant engineering investment or uncomfortable compromises.
The implications extend beyond performance. When text measurement moves to userland, AI-assisted code generation becomes dramatically simpler. An LLM can reason about layout without understanding the timing complexities of DOM operations. The API is minimal: prepare() does one-time setup, layout() returns heights, and more advanced methods let you route text manually around arbitrary shapes.
Language support is comprehensive. Full Unicode, CJK, RTL scripts, mixed content, emojis, and browser-specific quirks across Chrome, Firefox, and Safari. The library weighs a few kilobytes and works with DOM, Canvas, SVG, or WebGL rendering targets.
The Broader Shift
Pretext arrives at a moment when traditional application architectures are being reconsidered. The web platform's reliance on CSS for layout has always been a pragmatic bargain: developers accept the browser's opinionated system in exchange for accessibility, internationalization, and cross-platform consistency.
But that bargain was struck in an era before AI-generated interfaces, before 120Hz displays became standard, before apps routinely needed to render tens of thousands of dynamic elements. The question Pretext raises is whether CSS's monopoly on layout still makes sense, or whether we've been paying a hidden tax for conveniences that increasingly sophisticated tooling can provide in userland.
Reception from the web development community has been enthusiastic. Vercel CEO Guillermo Rauch called it "so good." Ryan Florence of Remix confirmed Canvas compatibility. The consensus seems to be that Lou has solved something long considered unsolvable.
Whether Pretext represents CSS's death or merely a new option in the toolkit depends on how quickly the patterns it enables become expected. History suggests that once developers taste 120fps with zero architectural compromise, they rarely go back.


